Bug fixes + tabbing
[iotcloud.git] / version2 / src / C / SlotBuffer.cc
index ad78b3eeedf638a011828b1832cf326832cf33ae..aa217ac17dda116f1ca2c48c3d498a93d182ae9d 100644 (file)
@@ -13,6 +13,10 @@ SlotBuffer::SlotBuffer() :
        oldestseqn(0) {
 }
 
+SlotBuffer::~SlotBuffer() {
+       delete array;
+}
+
 int SlotBuffer::size() {
        if (head >= tail)
                return head - tail;
@@ -24,7 +28,7 @@ int SlotBuffer::capacity() {
 }
 
 void SlotBuffer::resize(int newsize) {
-       if (newsize == (array->length() - 1))
+       if ((uint32_t)newsize == (array->length() - 1))
                return;
 
        Array<Slot *> *newarray = new Array<Slot *>(newsize + 1);
@@ -32,7 +36,7 @@ void SlotBuffer::resize(int newsize) {
        int index = tail;
        for (int i = 0; i < currsize; i++) {
                newarray->set(i, array->get(index));
-               if ((++index) == array->length())
+               if (((uint32_t)++ index) == array->length())
                        index = 0;
        }
        array = newarray;
@@ -42,13 +46,13 @@ void SlotBuffer::resize(int newsize) {
 
 void SlotBuffer::incrementHead() {
        head++;
-       if (head >= array->length())
+       if (((uint32_t)head) >= array->length())
                head = 0;
 }
 
 void SlotBuffer::incrementTail() {
        tail++;
-       if (tail >= array->length())
+       if (((uint32_t)tail) >= array->length())
                tail = 0;
 }
 
@@ -56,7 +60,6 @@ void SlotBuffer::putSlot(Slot *s) {
        int64_t checkNum = (getNewestSeqNum() + 1);
 
        if (checkNum != s->getSequenceNumber()) {
-               // We have a gap so expunge all our slots
                oldestseqn = s->getSequenceNumber();
                tail = 0;
                head = 1;
@@ -77,26 +80,25 @@ void SlotBuffer::putSlot(Slot *s) {
        }
 }
 
-Slot * SlotBuffer::getSlot(int64_t seqnum) {
+Slot *SlotBuffer::getSlot(int64_t seqnum) {
        int32_t diff = (int32_t) (seqnum - oldestseqn);
        int32_t index = diff + tail;
 
        if (index < 0) {
-               // Really old message so we dont have it anymore
                return NULL;
        }
 
-       if (index >= array->length()) {
+       if (((uint32_t)index) >= array->length()) {
                if (head >= tail) {
                        return NULL;
                }
-               index -= array->length();
+               index -= (int32_t) array->length();
        }
 
-       if (index >= array->length()) {
-
+       if (((uint32_t)index) >= array->length()) {
                return NULL;
        }
+
        if (head >= tail && index >= head) {
                return NULL;
        }