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 SlotBuffer::~SlotBuffer() {
18 while (index != head) {
19 delete array->get(index);
21 if (index == (int32_t) array->length())
27 int SlotBuffer::size() {
30 return (array->length() + head) - tail;
33 int SlotBuffer::capacity() {
34 return array->length() - 1;
37 void SlotBuffer::resize(int newsize) {
38 if ((uint32_t)newsize == (array->length() - 1))
41 Array<Slot *> *newarray = new Array<Slot *>(newsize + 1);
42 int currsize = size();
44 for (int i = 0; i < currsize; i++) {
45 newarray->set(i, array->get(index));
46 if (((uint32_t)++ index) == array->length())
54 void SlotBuffer::incrementHead() {
56 if (((uint32_t)head) >= array->length())
60 void SlotBuffer::incrementTail() {
61 delete array->get(tail);
63 if (((uint32_t)tail) >= array->length())
67 void SlotBuffer::putSlot(Slot *s) {
68 int64_t checkNum = (getNewestSeqNum() + 1);
70 if (checkNum != s->getSequenceNumber()) {
72 while (index != head) {
73 delete array->get(index);
75 if (index == (int32_t) array->length())
78 oldestseqn = s->getSequenceNumber();
88 if (oldestseqn == 0) {
89 oldestseqn = s->getSequenceNumber();
98 Slot *SlotBuffer::getSlot(int64_t seqnum) {
99 int32_t diff = (int32_t) (seqnum - oldestseqn);
100 int32_t index = diff + tail;
106 if (((uint32_t)index) >= array->length()) {
110 index -= (int32_t) array->length();
113 if (((uint32_t)index) >= array->length()) {
117 if (head >= tail && index >= head) {
121 return array->get(index);