Skip to content

Commit 8e9d957

Browse files
committed
Added documentation to UniqueSourceFileQueue and fixed Pop method
1 parent 0f88170 commit 8e9d957

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

legacy/builder/container_find_includes.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,31 +483,42 @@ func (f *SourceFile) Equals(other *SourceFile) bool {
483483
f.RelativePath.EqualsTo(other.RelativePath)
484484
}
485485

486+
// UniqueSourceFileQueue is a queue of SourceFile. A SourceFile
487+
// can be pushed in the queue only once.
486488
type UniqueSourceFileQueue struct {
487489
queue []*SourceFile
488490
curr int
489491
}
490492

493+
// Len returns the number of element waiting in the queue
491494
func (q *UniqueSourceFileQueue) Len() int {
492495
return len(q.queue) - q.curr
493496
}
494497

498+
// Push insert a new element in the queue
495499
func (q *UniqueSourceFileQueue) Push(value *SourceFile) {
496500
if !q.Contains(value) {
497501
q.queue = append(q.queue, value)
498502
}
499503
}
500504

505+
// Pop return the first element in the queue or nil if the queue is empty
501506
func (q *UniqueSourceFileQueue) Pop() *SourceFile {
507+
if q.Empty() {
508+
return nil
509+
}
502510
res := q.queue[q.curr]
503511
q.curr++
504512
return res
505513
}
506514

515+
// Empty returns true if the queue is empty
507516
func (q *UniqueSourceFileQueue) Empty() bool {
508517
return q.Len() == 0
509518
}
510519

520+
// Contains return true if the target elemen has been already added
521+
// in the queue (even if the element has been alread popped out)
511522
func (q *UniqueSourceFileQueue) Contains(target *SourceFile) bool {
512523
for _, elem := range q.queue {
513524
if elem.Equals(target) {

0 commit comments

Comments
 (0)