MCPcopy Index your code
hub / github.com/allegro/bigcache / Push

Method Push

queue/bytes_queue.go:88–106  ·  view source on GitHub ↗

Push copies entry at the end of queue and moves tail pointer. Allocates more space if needed. Returns index for pushed data or error if maximum size queue limit is reached.

(data []byte)

Source from the content-addressed store, hash-verified

86// Push copies entry at the end of queue and moves tail pointer. Allocates more space if needed.
87// Returns index for pushed data or error if maximum size queue limit is reached.
88func (q *BytesQueue) Push(data []byte) (int, error) {
89 neededSize := getNeededSize(len(data))
90
91 if !q.canInsertAfterTail(neededSize) {
92 if q.canInsertBeforeHead(neededSize) {
93 q.tail = leftMarginIndex
94 } else if q.capacity+neededSize >= q.maxCapacity && q.maxCapacity > 0 {
95 return -1, &queueError{"Full queue. Maximum size limit reached."}
96 } else {
97 q.allocateAdditionalMemory(neededSize)
98 }
99 }
100
101 index := q.tail
102
103 q.push(data, neededSize)
104
105 return index, nil
106}
107
108func (q *BytesQueue) allocateAdditionalMemory(minimum int) {
109 start := time.Now()

Calls 5

canInsertAfterTailMethod · 0.95
canInsertBeforeHeadMethod · 0.95
pushMethod · 0.95
getNeededSizeFunction · 0.85