Skip to content

Commit b3b262b

Browse files
committed
Added documentation to UniqueSourceFileQueue and fixed Pop method
1 parent c388af5 commit b3b262b

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
@@ -501,31 +501,42 @@ func (f *SourceFile) Equals(other *SourceFile) bool {
501501
f.RelativePath.EqualsTo(other.RelativePath)
502502
}
503503

504+
// UniqueSourceFileQueue is a queue of SourceFile. A SourceFile
505+
// can be pushed in the queue only once.
504506
type UniqueSourceFileQueue struct {
505507
queue []*SourceFile
506508
curr int
507509
}
508510

511+
// Len returns the number of element waiting in the queue
509512
func (q *UniqueSourceFileQueue) Len() int {
510513
return len(q.queue) - q.curr
511514
}
512515

516+
// Push insert a new element in the queue
513517
func (q *UniqueSourceFileQueue) Push(value *SourceFile) {
514518
if !q.Contains(value) {
515519
q.queue = append(q.queue, value)
516520
}
517521
}
518522

523+
// Pop return the first element in the queue or nil if the queue is empty
519524
func (q *UniqueSourceFileQueue) Pop() *SourceFile {
525+
if q.Empty() {
526+
return nil
527+
}
520528
res := q.queue[q.curr]
521529
q.curr++
522530
return res
523531
}
524532

533+
// Empty returns true if the queue is empty
525534
func (q *UniqueSourceFileQueue) Empty() bool {
526535
return q.Len() == 0
527536
}
528537

538+
// Contains return true if the target elemen has been already added
539+
// in the queue (even if the element has been alread popped out)
529540
func (q *UniqueSourceFileQueue) Contains(target *SourceFile) bool {
530541
for _, elem := range q.queue {
531542
if elem.Equals(target) {

0 commit comments

Comments
 (0)