1 #include "SlotBuffer.h"
3 * Circular buffer that holds the live set of slots.
8 SlotBuffer::SlotBuffer() :
9 array(new Array<Slot *>(SlotBuffer_DEFAULT_SIZE + 1)),
15 int SlotBuffer::size() {
18 return (array->length() + head) - tail;
21 int SlotBuffer::capacity() {
22 return array->length() - 1;
25 void SlotBuffer::resize(int newsize) {
26 if (newsize == (array->length() - 1))
29 Array<Slot *> *newarray = new Array<Slot *>(newsize + 1);
30 int currsize = size();
32 for (int i = 0; i < currsize; i++) {
33 newarray->set(i, array->get(index));
34 if ((++index) == array->length())
42 void SlotBuffer::incrementHead() {
44 if (head >= array->length())
48 void SlotBuffer::incrementTail() {
50 if (tail >= array->length())
54 void SlotBuffer::putSlot(Slot *s) {
55 int64_t checkNum = (getNewestSeqNum() + 1);
57 if (checkNum != s->getSequenceNumber()) {
58 // We have a gap so expunge all our slots
59 oldestseqn = s->getSequenceNumber();
69 if (oldestseqn == 0) {
70 oldestseqn = s->getSequenceNumber();
79 Slot SlotBuffer::getSlot(int64_t seqnum) {
80 int32_t diff = (int32_t) (seqnum - oldestseqn);
81 int32_t index = diff + tail;
84 // Really old message so we dont have it anymore
88 if (index >= array->length()) {
92 index -= array->length();
95 if (index >= array->length) {
99 if (head >= tail && index >= head) {
103 return array->get(index);