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() {
20 int SlotBuffer::size() {
23 return (array->length() + head) - tail;
26 int SlotBuffer::capacity() {
27 return array->length() - 1;
30 void SlotBuffer::resize(int newsize) {
31 if (newsize == (array->length() - 1))
34 Array<Slot *> *newarray = new Array<Slot *>(newsize + 1);
35 int currsize = size();
37 for (int i = 0; i < currsize; i++) {
38 newarray->set(i, array->get(index));
39 if ((++index) == array->length())
47 void SlotBuffer::incrementHead() {
49 if (head >= array->length())
53 void SlotBuffer::incrementTail() {
55 if (tail >= array->length())
59 void SlotBuffer::putSlot(Slot *s) {
60 int64_t checkNum = (getNewestSeqNum() + 1);
62 if (checkNum != s->getSequenceNumber()) {
63 oldestseqn = s->getSequenceNumber();
73 if (oldestseqn == 0) {
74 oldestseqn = s->getSequenceNumber();
83 Slot *SlotBuffer::getSlot(int64_t seqnum) {
84 int32_t diff = (int32_t) (seqnum - oldestseqn);
85 int32_t index = diff + tail;
91 if (index >= array->length()) {
95 index -= array->length();
98 if (index >= array->length()) {
102 if (head >= tail && index >= head) {
106 return array->get(index);