File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -482,31 +482,42 @@ func (f *SourceFile) Equals(other *SourceFile) bool {
482
482
f .RelativePath .EqualsTo (other .RelativePath )
483
483
}
484
484
485
+ // UniqueSourceFileQueue is a queue of SourceFile. A SourceFile
486
+ // can be pushed in the queue only once.
485
487
type UniqueSourceFileQueue struct {
486
488
queue []* SourceFile
487
489
curr int
488
490
}
489
491
492
+ // Len returns the number of element waiting in the queue
490
493
func (q * UniqueSourceFileQueue ) Len () int {
491
494
return len (q .queue ) - q .curr
492
495
}
493
496
497
+ // Push insert a new element in the queue
494
498
func (q * UniqueSourceFileQueue ) Push (value * SourceFile ) {
495
499
if ! q .Contains (value ) {
496
500
q .queue = append (q .queue , value )
497
501
}
498
502
}
499
503
504
+ // Pop return the first element in the queue or nil if the queue is empty
500
505
func (q * UniqueSourceFileQueue ) Pop () * SourceFile {
506
+ if q .Empty () {
507
+ return nil
508
+ }
501
509
res := q .queue [q .curr ]
502
510
q .curr ++
503
511
return res
504
512
}
505
513
514
+ // Empty returns true if the queue is empty
506
515
func (q * UniqueSourceFileQueue ) Empty () bool {
507
516
return q .Len () == 0
508
517
}
509
518
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)
510
521
func (q * UniqueSourceFileQueue ) Contains (target * SourceFile ) bool {
511
522
for _ , elem := range q .queue {
512
523
if elem .Equals (target ) {
You can’t perform that action at this time.
0 commit comments