Skip to content

Commit 7b40f21

Browse files
committed
Added documentation to UniqueSourceFileQueue and fixed Pop method
1 parent 8fba85a commit 7b40f21

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
@@ -482,31 +482,42 @@ func (f *SourceFile) Equals(other *SourceFile) bool {
482482
f.RelativePath.EqualsTo(other.RelativePath)
483483
}
484484

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

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

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

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

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

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

0 commit comments

Comments
 (0)