-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathqueue.go
50 lines (43 loc) · 858 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
// Copyright 2020-2021 InfluxData, Inc. All rights reserved.
// Use of this source code is governed by MIT
// license that can be found in the LICENSE file.
package write
import (
"container/list"
)
type queue struct {
list *list.List
limit int
}
func newQueue(limit int) *queue {
return &queue{list: list.New(), limit: limit}
}
func (q *queue) push(batch *Batch) bool {
overWrite := false
if q.list.Len() == q.limit {
q.pop()
overWrite = true
}
q.list.PushBack(batch)
return overWrite
}
func (q *queue) pop() *Batch {
el := q.list.Front()
if el != nil {
q.list.Remove(el)
batch := el.Value.(*Batch)
batch.Evicted = true
return batch
}
return nil
}
func (q *queue) first() *Batch {
el := q.list.Front()
if el != nil {
return el.Value.(*Batch)
}
return nil
}
func (q *queue) isEmpty() bool {
return q.list.Len() == 0
}