canInsertAfterTail returns true if it's possible to insert an entry of size of need after the tail of the queue
(need int)
| 244 | |
| 245 | // canInsertAfterTail returns true if it's possible to insert an entry of size of need after the tail of the queue |
| 246 | func (q *BytesQueue) canInsertAfterTail(need int) bool { |
| 247 | if q.full { |
| 248 | return false |
| 249 | } |
| 250 | if q.tail >= q.head { |
| 251 | return q.capacity-q.tail >= need |
| 252 | } |
| 253 | // 1. there is exactly need bytes between head and tail, so we do not need |
| 254 | // to reserve extra space for a potential empty entry when realloc this queue |
| 255 | // 2. still have unused space between tail and head, then we must reserve |
| 256 | // at least headerEntrySize bytes so we can put an empty entry |
| 257 | return q.head-q.tail == need || q.head-q.tail >= need+minimumHeaderSize |
| 258 | } |
| 259 | |
| 260 | // canInsertBeforeHead returns true if it's possible to insert an entry of size of need before the head of the queue |
| 261 | func (q *BytesQueue) canInsertBeforeHead(need int) bool { |