aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/allegro/bigcache/queue
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-02-18 16:15:55 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-02-19 17:00:31 +0800
commit992a7bbad531b9f44e84dfe5a779e7a6146d194d (patch)
tree1991cfaf21b724c4060985980d45822c57c2c2dd /vendor/github.com/allegro/bigcache/queue
parenta458153098d6f66ee0c6f990f31b3646ad171bbb (diff)
downloaddexon-992a7bbad531b9f44e84dfe5a779e7a6146d194d.tar.gz
dexon-992a7bbad531b9f44e84dfe5a779e7a6146d194d.tar.zst
dexon-992a7bbad531b9f44e84dfe5a779e7a6146d194d.zip
vendor: update bigcache
(cherry picked from commit 37e5a908e7368d84beef14a3ee8c534f34aa636f)
Diffstat (limited to 'vendor/github.com/allegro/bigcache/queue')
-rw-r--r--vendor/github.com/allegro/bigcache/queue/bytes_queue.go34
1 files changed, 31 insertions, 3 deletions
diff --git a/vendor/github.com/allegro/bigcache/queue/bytes_queue.go b/vendor/github.com/allegro/bigcache/queue/bytes_queue.go
index 0285c72cd..bda737403 100644
--- a/vendor/github.com/allegro/bigcache/queue/bytes_queue.go
+++ b/vendor/github.com/allegro/bigcache/queue/bytes_queue.go
@@ -16,6 +16,12 @@ const (
minimumEmptyBlobSize = 32 + headerEntrySize
)
+var (
+ errEmptyQueue = &queueError{"Empty queue"}
+ errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."}
+ errIndexOutOfBounds = &queueError{"Index out of range"}
+)
+
// BytesQueue is a non-thread safe queue type of fifo based on bytes array.
// For every push operation index of entry is returned. It can be used to read the entry later
type BytesQueue struct {
@@ -162,6 +168,11 @@ func (q *BytesQueue) Get(index int) ([]byte, error) {
return data, err
}
+// CheckGet checks if an entry can be read from index
+func (q *BytesQueue) CheckGet(index int) error {
+ return q.peekCheckErr(index)
+}
+
// Capacity returns number of allocated bytes for queue
func (q *BytesQueue) Capacity() int {
return q.capacity
@@ -177,18 +188,35 @@ func (e *queueError) Error() string {
return e.message
}
+// peekCheckErr is identical to peek, but does not actually return any data
+func (q *BytesQueue) peekCheckErr(index int) error {
+
+ if q.count == 0 {
+ return errEmptyQueue
+ }
+
+ if index <= 0 {
+ return errInvalidIndex
+ }
+
+ if index+headerEntrySize >= len(q.array) {
+ return errIndexOutOfBounds
+ }
+ return nil
+}
+
func (q *BytesQueue) peek(index int) ([]byte, int, error) {
if q.count == 0 {
- return nil, 0, &queueError{"Empty queue"}
+ return nil, 0, errEmptyQueue
}
if index <= 0 {
- return nil, 0, &queueError{"Index must be grater than zero. Invalid index."}
+ return nil, 0, errInvalidIndex
}
if index+headerEntrySize >= len(q.array) {
- return nil, 0, &queueError{"Index out of range"}
+ return nil, 0, errIndexOutOfBounds
}
blockSize := int(binary.LittleEndian.Uint32(q.array[index : index+headerEntrySize]))