diff options
author | Antonio Jesus Navarro Perez <antonio@sourced.tech> | 2017-02-21 14:53:30 +0100 |
---|---|---|
committer | Antonio Jesus Navarro Perez <antonio@sourced.tech> | 2017-02-21 14:55:58 +0100 |
commit | 6e15f9cb0dbac68992eb242282e725784fe72b32 (patch) | |
tree | 04246d19a1c4814752599ff8d02da35c09f1dc20 /cache/queue.go | |
parent | 0b8b8da617d5a077f282e57d0300dc106a604236 (diff) | |
download | go-git-6e15f9cb0dbac68992eb242282e725784fe72b32.tar.gz |
cache: move package to plumbing
Because cache package is only intended to be used at internal level, we move it to the plumbing package.
Diffstat (limited to 'cache/queue.go')
-rw-r--r-- | cache/queue.go | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/cache/queue.go b/cache/queue.go deleted file mode 100644 index 8c6d7d3..0000000 --- a/cache/queue.go +++ /dev/null @@ -1,46 +0,0 @@ -package cache - -import "srcd.works/go-git.v4/plumbing" - -// queue is a basic FIFO queue based on a circular list that resize as needed. -type queue struct { - elements []plumbing.Hash - size int - head int - tail int - count int -} - -// newQueue returns a queue with the specified initial size -func newQueue(size int) *queue { - return &queue{ - elements: make([]plumbing.Hash, size), - size: size, - } -} - -// Push adds a node to the queue. -func (q *queue) Push(h plumbing.Hash) { - if q.head == q.tail && q.count > 0 { - elements := make([]plumbing.Hash, len(q.elements)+q.size) - copy(elements, q.elements[q.head:]) - copy(elements[len(q.elements)-q.head:], q.elements[:q.head]) - q.head = 0 - q.tail = len(q.elements) - q.elements = elements - } - q.elements[q.tail] = h - q.tail = (q.tail + 1) % len(q.elements) - q.count++ -} - -// Pop removes and returns a Hash from the queue in first to last order. -func (q *queue) Pop() plumbing.Hash { - if q.count == 0 { - return plumbing.ZeroHash - } - node := q.elements[q.head] - q.head = (q.head + 1) % len(q.elements) - q.count-- - return node -} |