forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.go
52 lines (41 loc) · 801 Bytes
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ids
import (
"container/list"
)
// QueueSet is a set of IDs stored in fifo order
type QueueSet struct {
idList *list.List
}
func (qs *QueueSet) init() {
if qs.idList == nil {
qs.idList = list.New()
}
}
// SetHead ...
func (qs *QueueSet) SetHead(id ID) {
qs.init()
for qs.idList.Len() > 0 {
element := qs.idList.Front()
head := element.Value.(ID)
if head.Equals(id) {
return
}
qs.idList.Remove(element)
}
qs.idList.PushFront(id)
}
// Append ...
func (qs *QueueSet) Append(id ID) {
qs.init()
qs.idList.PushBack(id)
}
// GetTail ...
func (qs *QueueSet) GetTail() ID {
qs.init()
if qs.idList.Len() == 0 {
return ID{}
}
return qs.idList.Back().Value.(ID)
}