1 #include "SlotBuffer.h"
4 * Circular buffer that holds the live set of slots.
9 SlotBuffer::SlotBuffer() :
10 array(new Array<Slot *>(SlotBuffer_DEFAULT_SIZE + 1)),
16 int SlotBuffer::size() {
19 return (array->length() + head) - tail;
22 int SlotBuffer::capacity() {
23 return array->length() - 1;
26 void SlotBuffer::resize(int newsize) {
27 if (newsize == (array->length() - 1))
30 Array<Slot *> *newarray = new Array<Slot *>(newsize + 1);
31 int currsize = size();
33 for (int i = 0; i < currsize; i++) {
34 newarray->set(i, array->get(index));
35 if ((++index) == array->length())
43 void SlotBuffer::incrementHead() {
45 if (head >= array->length())
49 void SlotBuffer::incrementTail() {
51 if (tail >= array->length())
55 void SlotBuffer::putSlot(Slot *s) {
56 int64_t checkNum = (getNewestSeqNum() + 1);
58 if (checkNum != s->getSequenceNumber()) {
59 // We have a gap so expunge all our slots
60 oldestseqn = s->getSequenceNumber();
70 if (oldestseqn == 0) {
71 oldestseqn = s->getSequenceNumber();
80 Slot *SlotBuffer::getSlot(int64_t seqnum) {
81 int32_t diff = (int32_t) (seqnum - oldestseqn);
82 int32_t index = diff + tail;
85 // Really old message so we dont have it anymore
89 if (index >= array->length()) {
93 index -= array->length();
96 if (index >= array->length()) {
100 if (head >= tail && index >= head) {
104 return array->get(index);