Edits
authorbdemsky <bdemsky@uci.edu>
Mon, 12 Feb 2018 19:37:26 +0000 (11:37 -0800)
committerbdemsky <bdemsky@uci.edu>
Mon, 12 Feb 2018 19:37:26 +0000 (11:37 -0800)
15 files changed:
version2/src/C/CloudComm.cc
version2/src/C/Commit.cc
version2/src/C/Entry.h
version2/src/C/IoTString.h
version2/src/C/KeyValue.h
version2/src/C/Liveness.h
version2/src/C/Pair.h
version2/src/C/Slot.cc
version2/src/C/Slot.h
version2/src/C/Table.cc
version2/src/C/Table.h
version2/src/C/Transaction.cc
version2/src/C/URL.h
version2/src/C/hashset.h
version2/src/C/hashtable.h

index edc0706..c6c0e75 100644 (file)
@@ -101,10 +101,10 @@ void CloudComm::initCrypt() {
  */
 URL *CloudComm::buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries) {
        const char *reqstring = isput ? "req=putslot" : "req=getslot";
-       char * buffer = (char *) malloc(baseurl->length() + 200);
+       char *buffer = (char *) malloc(baseurl->length() + 200);
        memcpy(buffer, baseurl->internalBytes(), baseurl->length());
        int offset = baseurl->length();
-  offset+=sprintf(&buffer[offset], "?%s&seq=%" PRId64, reqstring, sequencenumber);
+       offset += sprintf(&buffer[offset], "?%s&seq=%" PRId64, reqstring, sequencenumber);
        if (maxentries != 0)
                sprintf(&buffer[offset], "&max=%" PRId64, maxentries);
        IoTString *urlstr = new IoTString(buffer);
@@ -117,23 +117,23 @@ void CloudComm::setSalt() {
                // Salt already sent to server so don't set it again
                return;
        }
-       
+
        try {
                Array<char> *saltTmp = new Array<char>(CloudComm_SALT_SIZE);
                random->nextBytes(saltTmp);
 
-               char * buffer = (char *) malloc(baseurl->length() + 100);
+               char *buffer = (char *) malloc(baseurl->length() + 100);
                memcpy(buffer, baseurl->internalBytes(), baseurl->length());
                int offset = baseurl->length();
-               offset+=sprintf(&buffer[offset], "?req=setsalt");
+               offset += sprintf(&buffer[offset], "?req=setsalt");
                IoTString *urlstr = new IoTString(buffer);
                free(buffer);
-               
+
                URL *url = new URL(urlstr);
                timer->startTime();
                URLConnection *con = url->openConnection();
                HttpURLConnection *http = (HttpURLConnection *) con;
-               
+
                http->setRequestMethod("POST");
                http->setFixedLengthStreamingMode(saltTmp->length());
                http->setDoOutput(true);
@@ -163,10 +163,10 @@ bool CloudComm::getSalt() {
        HttpURLConnection *http = NULL;
 
        try {
-               char * buffer = (char *) malloc(baseurl->length() + 100);
+               char *buffer = (char *) malloc(baseurl->length() + 100);
                memcpy(buffer, baseurl->internalBytes(), baseurl->length());
                int offset = baseurl->length();
-               offset+=sprintf(&buffer[offset], "?req=getsalt");
+               offset += sprintf(&buffer[offset], "?req=getsalt");
                IoTString *urlstr = new IoTString(buffer);
                free(buffer);
 
index fb09a94..ec4b39a 100644 (file)
@@ -39,9 +39,9 @@ void Commit::addPartDecode(CommitPart *newPart) {
        }
 
        CommitPart *previouslySeenPart = parts->setExpand(newPart->getPartNumber(), newPart);
-       if(previouslySeenPart == NULL)
+       if (previouslySeenPart == NULL)
                partCount++;
-       
+
        if (previouslySeenPart != NULL) {
                // Set dead the old one since the new one is a rescued version of this part
                previouslySeenPart->setDead();
@@ -115,9 +115,9 @@ void Commit::setDead() {
        if (!isDead) {
                isDead = true;
                // Make all the parts of this transaction dead
-               for (int32_t partNumber = 0; partNumber < parts->size(); partNumber ++) {
+               for (int32_t partNumber = 0; partNumber < parts->size(); partNumber++) {
                        CommitPart *part = parts->get(partNumber);
-                       if (parts!=NULL)
+                       if (parts != NULL)
                                part->setDead();
                }
        }
@@ -150,7 +150,7 @@ void Commit::createCommitParts() {
                Array<char> *partData = new Array<char>(copySize);
                System_arraycopy(charData, currentPosition, partData, 0, copySize);
 
-               CommitPartpart = new CommitPart(NULL, machineId, sequenceNumber, transactionSequenceNumber, commitPartCount, partData, isLastPart);
+               CommitPart *part = new CommitPart(NULL, machineId, sequenceNumber, transactionSequenceNumber, commitPartCount, partData, isLastPart);
                parts->setExpand(part->getPartNumber(), part);
 
                // Update position, count and remaining
@@ -165,7 +165,7 @@ void Commit::decodeCommitData() {
        int dataSize = 0;
        for (int i = 0; i < parts->size(); i++) {
                CommitPart *tp = parts->get(i);
-               if (tp!=NULL)
+               if (tp != NULL)
                        dataSize += tp->getDataSize();
        }
 
@@ -175,7 +175,7 @@ void Commit::decodeCommitData() {
        // Stitch all the data sections together
        for (int i = 0; i < parts->size(); i++) {
                CommitPart *tp = parts->get(i);
-               if (tp!=NULL) {
+               if (tp != NULL) {
                        System_arraycopy(tp->getData(), 0, combinedData, currentPosition, tp->getDataSize());
                        currentPosition += tp->getDataSize();
                }
@@ -198,13 +198,13 @@ void Commit::decodeCommitData() {
 Array<char> *Commit::convertDataToBytes() {
        // Calculate the size of the data
        int sizeOfData = sizeof(int32_t);       // Number of Update KV's
-       SetIterator<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> * kvit = keyValueUpdateSet->iterator();
-       while(kvit->hasNext()) {
-               KeyValue * kv = kvit->next();
+       SetIterator<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = keyValueUpdateSet->iterator();
+       while (kvit->hasNext()) {
+               KeyValue *kv = kvit->next();
                sizeOfData += kv->getSize();
        }
        delete kvit;
-       
+
        // Data handlers and storage
        Array<char> *dataArray = new Array<char>(sizeOfData);
        ByteBuffer *bbEncode = ByteBuffer_wrap(dataArray);
@@ -214,12 +214,12 @@ Array<char> *Commit::convertDataToBytes() {
 
        // Encode all the updates
        kvit = keyValueUpdateSet->iterator();
-       while(kvit->hasNext()) {
-               KeyValue * kv = kvit->next();
+       while (kvit->hasNext()) {
+               KeyValue *kv = kvit->next();
                kv->encode(bbEncode);
        }
        delete kvit;
-       
+
        return bbEncode->array();
 }
 
@@ -227,8 +227,8 @@ void Commit::setKVsMap(Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKey
        keyValueUpdateSet->clear();
        keyValueUpdateSet->addAll(newKVs);
        liveKeys->clear();
-       SetIterator<KeyValue*, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = newKVs->iterator();
-       while(kvit->hasNext()) {
+       SetIterator<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = newKVs->iterator();
+       while (kvit->hasNext()) {
                liveKeys->add(kvit->next()->getKey());
        }
        delete kvit;
@@ -242,18 +242,18 @@ Commit *Commit_merge(Commit *newer, Commit *older, int64_t newSequenceNumber) {
        }
        Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvSet = new Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue>();
        SetIterator<KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = older->getKeyValueUpdateSet()->iterator();
-       while(kvit->hasNext()) {
-               KeyValue* kv=kvit->next();
+       while (kvit->hasNext()) {
+               KeyValue *kv = kvit->next();
                kvSet->add(kv);
        }
        delete kvit;
        kvit = newer->getKeyValueUpdateSet()->iterator();
-       while(kvit->hasNext()) {
-               KeyValue* kv=kvit->next();
+       while (kvit->hasNext()) {
+               KeyValue *kv = kvit->next();
                kvSet->add(kv);
        }
        delete kvit;
-       
+
        int64_t transactionSequenceNumber = newer->getTransactionSequenceNumber();
        if (transactionSequenceNumber == -1) {
                transactionSequenceNumber = older->getTransactionSequenceNumber();
index e006b4a..acdd04a 100644 (file)
 #define TypeLastMessage 5
 #define TypeRejectedMessage 6
 #define TypeTableStatus 7
+#define TypeSlot 8
 
 class Entry : public Liveness {
        /* Records whether the information is still live or has been
           superceded by a newer update.  */
 private:
        bool islive;
- protected:
+protected:
        Slot *parentslot;
 
 public:
@@ -52,12 +53,6 @@ public:
        virtual int getSize() = 0;
 
 
-       /**
-        * Returns a char encoding the type of the entry object.
-        */
-       virtual char getType() = 0;
-
-
        /**
         * Returns a copy of the Entry that can be added to a different slot.
         */
index f72dfa8..bd838bb 100644 (file)
@@ -9,10 +9,10 @@
  * @version 1.0
  */
 
-inline int hashCharArray(Array<char> * array) {
+inline int hashCharArray(Array<char> *array) {
        uint len = array->length();
-       int hash=0;
-       for(uint i=0; i <len; i++) {
+       int hash = 0;
+       for (uint i = 0; i < len; i++) {
                hash = 31 * hash + array->get(i);
        }
        return hash;
@@ -29,8 +29,8 @@ private:
         */
 
 public:
- IoTString(Array<char> *_array) :
-       array(new Array<char>(_array)),
      IoTString(Array<char> *_array) :
+               array(new Array<char>(_array)),
                hashvalue(hashCharArray(array)) {
        }
 
@@ -38,11 +38,11 @@ public:
                int32_t len = strlen(_array);
                array = new Array<char>(len);
                strcpy(array->internalArray(), _array);
-               hashvalue=hashCharArray(array);
+               hashvalue = hashCharArray(array);
        }
 
- IoTString(IoTString *string) :
-       array(new Array<char>(string->array)),
      IoTString(IoTString *string) :
+               array(new Array<char>(string->array)),
                hashvalue(hashCharArray(array)) {
        }
 
index 2493bb2..9234b2d 100644 (file)
@@ -8,7 +8,7 @@
  * @version 1.0
  */
 
-class KeyValue { /*extends Entry */
+class KeyValue {/*extends Entry */
 private:
        IoTString *key;
        IoTString *value;
@@ -30,4 +30,4 @@ public:
 KeyValue *KeyValue_decode(ByteBuffer *bb);
 unsigned int hashKeyValue(KeyValue *kv);
 bool equalsKeyValue(KeyValue *a, KeyValue *b);
-#endif 
+#endif
index ad56cb9..1f92b99 100644 (file)
@@ -2,6 +2,10 @@
 #define LIVENESS_H
 
 class Liveness {
+       /**
+        * Returns a char encoding the type of the entry object.
+        */
+       virtual char getType() = 0;
 };
 
 #endif
index 4da3bf7..5506eae 100644 (file)
@@ -23,13 +23,13 @@ public:
 };
 
 template<typename A, typename B>
-inline unsigned int pairHashFunction(Pair<A, B> p) {
-       return (p.getFirst() << 1) ^ p.getSecond();
+inline unsigned int pairHashFunction(Pair<A, B> p) {
+       return (p->getFirst() << 1) ^ p->getSecond();
 }
 
 template<typename A, typename B>
-inline bool pairEquals(Pair<A, B> a, Pair<A, B> b) {
-       return ( a.getFirst() == b.getFirst() ) && (a.getSecond() == b.getSecond());
+inline bool pairEquals(Pair<A, B> *a, Pair<A, B> *b) {
+       return (a->getFirst() == b->getFirst() ) && (a->getSecond() == b->getSecond());
 }
 
 inline unsigned int pairHashFunction(Pair<int64_t, int64_t> p) {
@@ -37,6 +37,6 @@ inline unsigned int pairHashFunction(Pair<int64_t, int64_t> p) {
 }
 
 inline bool pairEquals(Pair<int64_t, int64_t> a, Pair<int64_t, int64_t> b) {
-       return ( a.getFirst() == b.getFirst() ) && (a.getSecond() == b.getSecond());
+       return (a.getFirst() == b.getFirst() ) && (a.getSecond() == b.getSecond());
 }
 #endif
index f4247e4..10c92de 100644 (file)
@@ -97,6 +97,10 @@ Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac) {
        return slot;
 }
 
+char Slot::getType() {
+       return TypeSlot;
+}
+
 Array<char> *Slot::encode(Mac *mac) {
        Array<char> *array = new Array<char>(SLOT_SIZE);
        ByteBuffer *bb = ByteBuffer_wrap(array);
index c91aac1..d6e7575 100644 (file)
@@ -52,6 +52,7 @@ public:
        bool isLive() { return livecount > 0; }
        Array<char> *getSlotCryptIV();
        friend Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
+       char getType();
 };
 
 Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
index 5f93fe8..ee3b8bb 100644 (file)
 #include "ByteBuffer.h"
 #include "Abort.h"
 #include "CommitPart.h"
-
+#include "ArbitrationRound.h"
+#include "TransactionPart.h"
+#include "Commit.h"
+#include "RejectedMessage.h"
+#include "SlotIndexer.h"
 
 Table::Table(IoTString *baseurl, IoTString *password, int64_t _localMachineId, int listeningPort) :
        buffer(NULL),
@@ -153,15 +157,15 @@ void Table::init() {
        speculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
        pendingTransactionSpeculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
        liveNewKeyTable = new Hashtable<IoTString *, NewKey *>();
-       lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> >();
+       lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> >();
        rejectedMessageWatchVectorTable = new Hashtable<int64_t, Hashset<RejectedMessage *> * >();
        arbitratorTable = new Hashtable<IoTString *, int64_t>();
-       liveAbortTable = new Hashtable<Pair<int64_t, int64_t>, Abort *, uintptr_t, 0, pairHashFunction, pairEquals>();
-       newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
-       newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
+       liveAbortTable = new Hashtable<Pair<int64_t, int64_t> *, Abort *, uintptr_t, 0, pairHashFunction, pairEquals>();
+       newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
+       newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
        lastArbitratedTransactionNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
        liveTransactionBySequenceNumberTable = new Hashtable<int64_t, Transaction *>();
-       liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t>, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals>();
+       liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t> *, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals>();
        liveCommitsTable = new Hashtable<int64_t, Hashtable<int64_t, Commit *> >();
        liveCommitsByKeyTable = new Hashtable<IoTString *, Commit *>();
        lastCommitSeenSequenceNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
@@ -171,8 +175,8 @@ void Table::init() {
        transactionPartsSent = new Hashtable<Transaction *, Vector<int32_t> *>();
        outstandingTransactionStatus = new Hashtable<int64_t, TransactionStatus *>();
        liveAbortsGeneratedByLocal = new Hashtable<int64_t, Abort *>();
-       offlineTransactionsCommittedAndAtServer = new Hashset<Pair<int64_t, int64_t>, uintptr_t, 0, pairHashFunction, pairEquals>();
-       localCommunicationTable = new Hashtable<int64_t, Pair<IoTString *, int32_t> >();
+       offlineTransactionsCommittedAndAtServer = new Hashset<Pair<int64_t, int64_t> *, uintptr_t, 0, pairHashFunction, pairEquals>();
+       localCommunicationTable = new Hashtable<int64_t, Pair<IoTString *, int32_t> *>();
        lastTransactionSeenFromMachineFromServer = new Hashtable<int64_t, int64_t>();
        pendingSendArbitrationRounds = new Vector<ArbitrationRound *>();
        lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = new Hashtable<int64_t, int64_t>();
@@ -222,7 +226,7 @@ void Table::rebuild() {
 }
 
 void Table::addLocalCommunication(int64_t arbitrator, IoTString *hostName, int portNumber) {
-       localCommunicationTable->put(arbitrator, Pair<IoTString *, int32_t>(hostName, portNumber));
+       localCommunicationTable->put(arbitrator, new Pair<IoTString *, int32_t>(hostName, portNumber));
 }
 
 int64_t Table::getArbitrator(IoTString *key) {
@@ -321,8 +325,8 @@ bool Table::update()  {
                updateLiveTransactionsAndStatus();
                return true;
        } catch (Exception *e) {
-               SetIterator<int64_t> * kit = getKeyIterator(localCommunicationTable);
-               while(kit->hasNext()) {
+               SetIterator<int64_t> *kit = getKeyIterator(localCommunicationTable);
+               while (kit->hasNext()) {
                        int64_t m = kit->next();
                        updateFromLocal(m);
                }
@@ -404,10 +408,10 @@ TransactionStatus *Table::commitTransaction() {
                Hashset<int64_t> *arbitratorTriedAndFailed = new Hashset<int64_t>();
                uint size = pendingTransactionQueue->size();
                uint oldindex = 0;
-               for(int iter = 0; iter < size; iter++) {
+               for (int iter = 0; iter < size; iter++) {
                        Transaction *transaction = pendingTransactionQueue->get(iter);
                        pendingTransactionQueue->set(oldindex++, pendingTransactionQueue->get(iter));
-                       
+
                        if (arbitratorTriedAndFailed->contains(transaction->getArbitrator())) {
                                // Already contacted this client so ignore all attempts to contact this client
                                // to preserve ordering for arbitrator
@@ -430,7 +434,7 @@ TransactionStatus *Table::commitTransaction() {
                }
                pendingTransactionQueue->setSize(oldindex);
        }
-       
+
        updateLiveStateFromLocal();
 
        return transactionStatus;
@@ -464,8 +468,8 @@ bool Table::sendToServer(NewKey *newKey) {
                                                }
                                        }
 
-                                       SetIterator<Transaction *> * trit = getKeyIterator(lastTransactionPartsSent);
-                                       while(trit->hasNext()) {
+                                       SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                       while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
                                                // Update which transactions parts still need to be sent
@@ -502,9 +506,9 @@ bool Table::sendToServer(NewKey *newKey) {
                                                }
 
                                                // Process each entry in the slot
-                                               Vector<Entry *> * ventries=s->getEntries();
+                                               Vector<Entry *> *ventries = s->getEntries();
                                                uint vesize = ventries->size();
-                                               for(uint vei = 0; vei < vesize; vei++) {
+                                               for (uint vei = 0; vei < vesize; vei++) {
                                                        Entry *entry = ventries->get(vei);
                                                        if (entry->getType() == TypeLastMessage) {
                                                                LastMessage *lastMessage = (LastMessage *)entry;
@@ -523,7 +527,9 @@ bool Table::sendToServer(NewKey *newKey) {
                                                        }
                                                }
 
-                                               for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+                                               SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                               while (trit->hasNext()) {
+                                                       Transaction *transaction = trit->next();
                                                        transaction->resetServerFailure();
 
                                                        // Update which transactions parts still need to be sent
@@ -547,16 +553,20 @@ bool Table::sendToServer(NewKey *newKey) {
                                                                }
                                                        }
                                                }
+                                               delete trit;
                                        }
                                }
 
-                               for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+                               SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                               while (trit->hasNext()) {
+                                       Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
                                        // Set the transaction sequence number back to nothing
                                        if (!transaction->didSendAPartToServer()) {
                                                transaction->setSequenceNumber(-1);
                                        }
                                }
+                               delete trit;
 
                                if (sendSlotsReturn.getThird()->length() != 0) {
                                        // insert into the local block chain
@@ -580,8 +590,11 @@ bool Table::sendToServer(NewKey *newKey) {
                                        }
 
                                        // Process each entry in the slot
-                                       for (Entry *entry : s->getEntries()) {
-
+                                       Vector<Entry *> *entries = s->getEntries();
+                                       uint eSize = entries->size();
+                                       for(uint ei=0; ei < eSize; ei++) {
+                                               Entry * entry = entries->get(ei);
+                                               
                                                if (entry->getType() == TypeLastMessage) {
                                                        LastMessage *lastMessage = (LastMessage *)entry;
                                                        if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {
@@ -599,7 +612,9 @@ bool Table::sendToServer(NewKey *newKey) {
                                                }
                                        }
 
-                                       for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+                                       SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                       while (trit->hasNext()) {
+                                               Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
 
                                                // Update which transactions parts still need to be sent
@@ -623,14 +638,18 @@ bool Table::sendToServer(NewKey *newKey) {
                                                        }
                                                }
                                        }
+                                       delete trit;
                                } else {
-                                       for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+                                       SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                       while (trit->hasNext()) {
+                                               Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
                                                // Set the transaction sequence number back to nothing
                                                if (!transaction->didSendAPartToServer()) {
                                                        transaction->setSequenceNumber(-1);
                                                }
                                        }
+                                       delete trit;
                                }
 
                                // insert into the local block chain
@@ -672,7 +691,9 @@ bool Table::sendToServer(NewKey *newKey) {
 
                        if (needsResize) {
                                // Reset which transaction to send
-                               for (Transaction *transaction : transactionPartsSent->keySet()) {
+                               SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                               while (trit->hasNext()) {
+                                       Transaction *transaction = trit->next();
                                        transaction->resetNextPartToSend();
 
                                        // Set the transaction sequence number back to nothing
@@ -680,6 +701,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                                transaction->setSequenceNumber(-1);
                                        }
                                }
+                               delete trit;
 
                                // Clear the sent data since we are trying again
                                pendingSendArbitrationEntriesToDelete->clear();
@@ -694,10 +716,9 @@ bool Table::sendToServer(NewKey *newKey) {
                        lastInsertedNewKey = insertedNewKey;
                        lastNewSize = newSize;
                        lastNewKey = newKey;
-                       lastTransactionPartsSent = new Hashtable<Transaction *, Vector<int32_t> * >(transactionPartsSent);
+                       lastTransactionPartsSent = transactionPartsSent->clone();
                        lastPendingSendArbitrationEntriesToDelete = new Vector<Entry *>(pendingSendArbitrationEntriesToDelete);
 
-
                        ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsReturn = sendSlotsToServer(slot, newSize, newKey != NULL);
 
                        if (sendSlotsReturn.getFirst()) {
@@ -714,19 +735,21 @@ bool Table::sendToServer(NewKey *newKey) {
                                // Remove the aborts and commit parts that were sent from the pending to send queue
                                uint size = pendingSendArbitrationRounds->size();
                                uint oldcount = 0;
-                               for (uint i=0; i < size; i++)
-                                       ArbitrationRound *round = pendingSendArbitrartionRounds->get(i);
+                               for (uint i = 0; i < size; i++) {
+                                       ArbitrationRound *round = pendingSendArbitrationRounds->get(i);
                                        round->removeParts(pendingSendArbitrationEntriesToDelete);
 
                                        if (!round->isDoneSending()) {
                                                // Sent all the parts
-                                               pendingSendArbitrartionRounds->set(oldcount++,
-                                                                                                                                                                                        pendingSendArbitrartionRounds->get(i));
+                                               pendingSendArbitrationRounds->set(oldcount++,
+                                                                                                                                                                                       pendingSendArbitrationRounds->get(i));
                                        }
                                }
-                       pendingSendArbitrationRounds->setSize(oldcount);
+                               pendingSendArbitrationRounds->setSize(oldcount);
 
-                               for (Transaction *transaction : transactionPartsSent->keySet()) {
+                               SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                               while (trit->hasNext()) {
+                                       Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
 
                                        // Update which transactions parts still need to be sent
@@ -744,9 +767,12 @@ bool Table::sendToServer(NewKey *newKey) {
                                                pendingTransactionQueue->remove(transaction);
                                        }
                                }
+                               delete trit;
                        } else {
                                // Reset which transaction to send
-                               for (Transaction *transaction : transactionPartsSent->keySet()) {
+                               SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                               while (trit->hasNext()) {
+                                       Transaction *transaction = trit->next();
                                        transaction->resetNextPartToSend();
 
                                        // Set the transaction sequence number back to nothing
@@ -754,6 +780,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                                transaction->setSequenceNumber(-1);
                                        }
                                }
+                               delete trit;
                        }
 
                        // Clear the sent data in preparation for next send
@@ -767,10 +794,11 @@ bool Table::sendToServer(NewKey *newKey) {
                }
 
        } catch (ServerException *e) {
-
                if (e->getType() != ServerException->TypeInputTimeout) {
                        // Nothing was able to be sent to the server so just clear these data structures
-                       for (Transaction *transaction : transactionPartsSent->keySet()) {
+                       SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                       while (trit->hasNext()) {
+                               Transaction *transaction = trit->next();
                                transaction->resetNextPartToSend();
 
                                // Set the transaction sequence number back to nothing
@@ -778,15 +806,19 @@ bool Table::sendToServer(NewKey *newKey) {
                                        transaction->setSequenceNumber(-1);
                                }
                        }
+                       delete trit;
                } else {
                        // There was a partial send to the server
                        hadPartialSendToServer = true;
 
                        // Nothing was able to be sent to the server so just clear these data structures
-                       for (Transaction *transaction : transactionPartsSent->keySet()) {
+                       SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                       while (trit->hasNext()) {
+                               Transaction *transaction = trit->next();
                                transaction->resetNextPartToSend();
                                transaction->setServerFailure();
                        }
+                       delete trit;
                }
 
                pendingSendArbitrationEntriesToDelete->clear();
@@ -799,11 +831,10 @@ bool Table::sendToServer(NewKey *newKey) {
 }
 
 bool Table::updateFromLocal(int64_t machineId) {
-       Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(machineId);
-       if (localCommunicationInformation == NULL) {
-               // Cant talk to that device locally so do nothing
+       if (!localCommunicationTable->contains(machineId))
                return false;
-       }
+
+       Pair<IoTString *, int32_t> * localCommunicationInformation = localCommunicationTable->get(machineId);
 
        // Get the size of the send data
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
@@ -836,10 +867,10 @@ bool Table::updateFromLocal(int64_t machineId) {
        for (int i = 0; i < numberOfEntries; i++) {
                char type = bbDecode->get();
                if (type == TypeAbort) {
-                       Abort *abort = (Abort*)Abort_decode(NULL, bbDecode);
+                       Abort *abort = (Abort *)Abort_decode(NULL, bbDecode);
                        processEntry(abort);
                } else if (type == TypeCommitPart) {
-                       CommitPart *commitPart = (CommitPart*)CommitPart_decode(NULL, bbDecode);
+                       CommitPart *commitPart = (CommitPart *)CommitPart_decode(NULL, bbDecode);
                        processEntry(commitPart);
                }
        }
@@ -852,12 +883,10 @@ bool Table::updateFromLocal(int64_t machineId) {
 Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
        // Get the devices local communications
-       Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
-
-       if (localCommunicationInformation == NULL) {
-               // Cant talk to that device locally so do nothing
+       if (!localCommunicationTable->contains(machineId))
                return Pair<bool, bool>(true, false);
-       }
+       
+       Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
 
        // Get the size of the send data
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
@@ -872,7 +901,7 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
        // Make the send data size
        Array<char> *sendData = new Array<char>(sendDataSize);
-       ByteBuffer *bbEncode = ByteBuffer.wrap(sendData);
+       ByteBuffer *bbEncode = ByteBuffer_wrap(sendData);
 
        // Encode the data
        bbEncode->putLong(lastArbitrationDataLocalSequenceNumber);
@@ -901,7 +930,7 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
        for (int i = 0; i < numberOfEntries; i++) {
                char type = bbDecode->get();
                if (type == TypeAbort) {
-                       Abort *abort = (Abort*)Abort_decode(NULL, bbDecode);
+                       Abort *abort = (Abort *)Abort_decode(NULL, bbDecode);
 
                        if ((abort->getTransactionMachineId() == localMachineId) && (abort->getTransactionClientLocalSequenceNumber() == transaction->getClientLocalSequenceNumber())) {
                                foundAbort = true;
@@ -909,7 +938,7 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
                        processEntry(abort);
                } else if (type == TypeCommitPart) {
-                       CommitPart *commitPart = (CommitPart*)CommitPart_decode(NULL, bbDecode);
+                       CommitPart *commitPart = (CommitPart *)CommitPart_decode(NULL, bbDecode);
                        processEntry(commitPart);
                }
        }
@@ -917,14 +946,14 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
        updateLiveStateFromLocal();
 
        if (couldArbitrate) {
-               TransactionStatus status =  transaction->getTransactionStatus();
+               TransactionStatus status =  transaction->getTransactionStatus();
                if (didCommit) {
                        status->setStatus(TransactionStatus_StatusCommitted);
                } else {
                        status->setStatus(TransactionStatus_StatusAborted);
                }
        } else {
-               TransactionStatus status =  transaction->getTransactionStatus();
+               TransactionStatus status =  transaction->getTransactionStatus();
                if (foundAbort) {
                        status->setStatus(TransactionStatus_StatusAborted);
                } else {
@@ -952,7 +981,7 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
                Transaction *transaction = new Transaction();
                for (int i = 0; i < numberOfParts; i++) {
                        bbDecode->get();
-                       TransactionPart *newPart = (TransactionPart)TransactionPart.decode(NULL, bbDecode);
+                       TransactionPart *newPart = (TransactionPart *)TransactionPart_decode(NULL, bbDecode);
                        transaction->addPartDecode(newPart);
                }
 
@@ -976,11 +1005,13 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
        // Get the aborts to send back
        Vector<int64_t> *abortLocalSequenceNumbers = new Vector<int64_t>(liveAbortsGeneratedByLocal->keySet());
        Collections->sort(abortLocalSequenceNumbers);
-       for (int64_t localSequenceNumber : abortLocalSequenceNumbers) {
+       uint asize = abortLocalSequenceNumbers->size();
+       for(uint i=0; i<asize; i++) {
+               int64_t localSequenceNumber = abortLocalSequenceNumbers->get(i);
                if (localSequenceNumber <= lastArbitratedSequenceNumberSeen) {
                        continue;
                }
-
+               
                Abort *abort = liveAbortsGeneratedByLocal->get(localSequenceNumber);
                unseenArbitrations->add(abort);
                returnDataSize += abort->getSize();
@@ -992,7 +1023,9 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
                Vector<int64_t> *commitLocalSequenceNumbers = new Vector<int64_t>(commitForClientTable->keySet());
                Collections->sort(commitLocalSequenceNumbers);
 
-               for (int64_t localSequenceNumber : commitLocalSequenceNumbers) {
+               uint clsSize = commitLocalSequenceNumbers->size();
+               for(uint clsi = 0; clsi < clsSize; clsi++) {
+                       int64_t localSequenceNumber = commitLocalSequenceNumbers->get(clsi);
                        Commit *commit = commitForClientTable->get(localSequenceNumber);
 
                        if (localSequenceNumber <= lastArbitratedSequenceNumberSeen) {
@@ -1034,8 +1067,8 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
 
        bbEncode->putInt(unseenArbitrations->size());
        uint size = unseenArbitrations->size();
-       for(uint i = 0; i< size; i++) {
-               Entry * entry = unseenArbitrations->get(i);
+       for (uint i = 0; i < size; i++) {
+               Entry *entry = unseenArbitrations->get(i);
                entry->encode(bbEncode);
        }
 
@@ -1065,8 +1098,8 @@ ThreeTuple<bool, bool, Array<Slot *> *> Table::sendSlotsToServer(Slot *slot, int
                if (hadPartialSendToServer) {
 
                        bool isInserted = false;
-                       uint size = array->size();
-                       for(uint i=0; i < size; i++) {
+                       uint size = array->length();
+                       for (uint i = 0; i < size; i++) {
                                Slot *s = array->get(i);
                                if ((s->getSequenceNumber() == slot->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
                                        isInserted = true;
@@ -1074,14 +1107,17 @@ ThreeTuple<bool, bool, Array<Slot *> *> Table::sendSlotsToServer(Slot *slot, int
                                }
                        }
 
-                       for(uint i=0; i < size; i++) {
+                       for (uint i = 0; i < size; i++) {
                                Slot *s = array->get(i);
                                if (isInserted) {
                                        break;
                                }
 
                                // Process each entry in the slot
-                               for (Entry *entry : s->getEntries()) {
+                               Vector<Entry *> *entries = s->getEntries();
+                               uint eSize = entries->size();
+                               for(uint ei=0; ei < eSize; ei++) {
+                                       Entry * entry = entries->get(ei);
 
                                        if (entry->getType() == TypeLastMessage) {
                                                LastMessage *lastMessage = (LastMessage *)entry;
@@ -1115,7 +1151,7 @@ ThreeTuple<bool, bool, Array<Slot *> *> Table::sendSlotsToServer(Slot *slot, int
 ThreeTuple<bool, int32_t, bool> Table::fillSlot(Slot *slot, bool resize, NewKey *newKeyEntry) {
        int newSize = 0;
        if (liveSlotCount > bufferResizeThreshold) {
-               resize = true;  //Resize is forced
+               resize = true;//Resize is forced
        }
 
        if (resize) {
@@ -1153,17 +1189,17 @@ ThreeTuple<bool, int32_t, bool> Table::fillSlot(Slot *slot, bool resize, NewKey
        transactionPartsSent->clear();
        pendingSendArbitrationEntriesToDelete->clear();
        uint size = pendingSendArbitrationRounds->size();
-       for (uint i=0; i<size; i++)
-               ArbitrartionRound *round = pendingSendArbitrationRounds->get(i);
+       for (uint i = 0; i < size; i++) {
+               ArbitrationRound *round = pendingSendArbitrationRounds->get(i);
                bool isFull = false;
                round->generateParts();
                Vector<Entry *> *parts = round->getParts();
 
                // Insert pending arbitration data
                uint vsize = parts->size();
-               for (uint vi=0; vi<vsize; vi++) {
+               for (uint vi = 0; vi < vsize; vi++) {
                        Entry *arbitrationData = parts->get(vi);
-                       
+
                        // If it is an abort then we need to set some information
                        if (arbitrationData->getType() == TypeAbort) {
                                ((Abort *)arbitrationData)->setSequenceNumber(slot->getSequenceNumber());
@@ -1274,7 +1310,7 @@ ThreeTuple<bool, bool, int64_t> Table::doMandatoryResuce(Slot *slot, bool resize
 
        // Mandatory Rescue
        for (; currentSequenceNumber < threshold; currentSequenceNumber++) {
-               Slot previousSlot = buffer->getSlot(currentSequenceNumber);
+               Slot previousSlot = buffer->getSlot(currentSequenceNumber);
                // Push slot number forward
                if (!seenLiveSlot) {
                        oldestLiveSlotSequenceNumver = currentSequenceNumber;
@@ -1329,10 +1365,12 @@ search:
                        else {
                                skipcount++;
                                if (skipcount > Table_SKIP_THRESHOLD)
-                                       break search;
+                                       goto donesearch;
                        }
                }
        }
+ donesearch:
+       ;
 }
 
 /**
@@ -1512,7 +1550,7 @@ void Table::processNewTransactionParts() {
        // Iterate through all the machine Ids that we received new parts
        // for
        for (int64_t machineId : newTransactionParts->keySet()) {
-               Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
+               Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
 
                // Iterate through all the parts for that machine Id
                for (Pair<int64_t, int32_t> partId : parts->keySet()) {
@@ -1559,7 +1597,7 @@ void Table::arbitrateFromServer() {
        Collections->sort(transactionSequenceNumbers);
 
        // Collection of key value pairs that are
-       Hashtable<IoTString *, KeyValue *> speculativeTableTmp = new Hashtable<IoTString *, KeyValue *>();
+       Hashtable<IoTString *, KeyValue *> speculativeTableTmp = new Hashtable<IoTString *, KeyValue *>();
 
        // The last transaction arbitrated on
        int64_t lastTransactionCommitted = -1;
@@ -1607,10 +1645,13 @@ void Table::arbitrateFromServer() {
                        // Guard evaluated as true
 
                        // Update the local changes so we can make the commit
-                       for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+                       SetIterator<KeyValue *> *kvit = getKeyIterator(transaction->getKeyValueUpdateSet());
+                       while (kvit->hasNext()) {
+                               KeyValue *kv = kvit->next();
                                speculativeTableTmp->put(kv->getKey(), kv);
                        }
-
+                       delete kvit;
+                       
                        // Update what the last transaction committed was for use in batch commit
                        lastTransactionCommitted = transactionSequenceNumber;
                } else {
@@ -1702,10 +1743,13 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                localArbitrationSequenceNumber++;
 
                // Update the local changes so we can make the commit
-               for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+               SetIterator<KeyValue *> *kvit = getKeyIterator(transaction->getKeyValueUpdateSet());
+               while (kvit->hasNext()) {
+                       KeyValue *kv = kvit->next();
                        newCommit->addKV(kv);
                }
-
+               delete kvit;
+               
                // create the commit parts
                newCommit->createCommitParts();
 
@@ -1739,7 +1783,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                if (transaction->getMachineId() == localMachineId) {
                        // For locally created messages update the status
                        // Guard evaluated was false so create abort
-                       TransactionStatus status = transaction->getTransactionStatus();
+                       TransactionStatus status = transaction->getTransactionStatus();
                        if (status != NULL) {
                                status->setStatus(TransactionStatus_StatusAborted);
                        }
@@ -1786,7 +1830,7 @@ bool Table::compactArbitrationData() {
        }
 
        ArbitrationRound *lastRound = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - 1);
-       if (lastRound->didSendPart()) {
+       if (lastRound->getDidSendPart()) {
                return false;
        }
 
@@ -1797,7 +1841,7 @@ bool Table::compactArbitrationData() {
        while (numberToDelete < pendingSendArbitrationRounds->size()) {
                ArbitrationRound *xs round = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - numberToDelete - 1);
 
-               if (round->isFull() || round->didSendPart()) {
+               if (round->isFull() || round->getDidSendPart()) {
                        // Stop since there is a part that cannot be compacted and we
                        // need to compact in order
                        break;
@@ -1874,7 +1918,7 @@ bool Table::updateCommittedTable() {
 
        // Iterate through all the machine Ids that we received new parts for
        for (int64_t machineId : newCommitParts->keySet()) {
-               Hashtable<Pair<int64_t, int32_t>, CommitPart *> *parts = newCommitParts->get(machineId);
+               Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *parts = newCommitParts->get(machineId);
 
                // Iterate through all the parts for that machine Id
                for (Pair<int64_t, int32_t> partId : parts->keySet()) {
@@ -1960,8 +2004,7 @@ bool Table::updateCommittedTable() {
                        }
 
                        // Update the last arbitration data that we have seen so far
-                       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(commit->getMachineId()) != NULL) {
-
+                       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->contains(commit->getMachineId())) {
                                int64_t lastArbitrationSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(commit->getMachineId());
                                if (commit->getSequenceNumber() > lastArbitrationSequenceNumber) {
                                        // Is larger
@@ -1994,9 +2037,12 @@ bool Table::updateCommittedTable() {
                        // Get what commits should be edited, these are the commits that
                        // have live values for their keys
                        Hashset<Commit *> *commitsToEdit = new Hashset<Commit *>();
-                       for (KeyValue *kv : commit->getKeyValueUpdateSet()) {
+                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+                       while (kvit->hasNext()) {
+                               KeyValue *kv = kvit->next();
                                commitsToEdit->add(liveCommitsByKeyTable->get(kv->getKey()));
                        }
+                       delete kvit;
                        commitsToEdit->remove(NULL);            // remove NULL since it could be in this set
 
                        // Update each previous commit that needs to be updated
@@ -2006,10 +2052,13 @@ bool Table::updateCommittedTable() {
                                if (previousCommit->isLive()) {
 
                                        // Update which keys in the old commits are still live
-                                       for (KeyValue *kv : commit->getKeyValueUpdateSet()) {
+                                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+                                       while (kvit->hasNext()) {
+                                               KeyValue *kv = kvit->next();
                                                previousCommit->invalidateKey(kv->getKey());
                                        }
-
+                                       delete kvit;
+                                       
                                        // if the commit is now dead then remove it
                                        if (!previousCommit->isLive()) {
                                                commitForClientTable->remove(previousCommit);
@@ -2030,10 +2079,13 @@ bool Table::updateCommittedTable() {
                        didProcessANewCommit = true;
 
                        // Update the committed table of keys and which commit is using which key
-                       for (KeyValue *kv : commit->getKeyValueUpdateSet()) {
+                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+                       while (kvit->hasNext()) {
+                               KeyValue *kv = kvit->next();
                                committedKeyValueTable->put(kv->getKey(), kv);
                                liveCommitsByKeyTable->put(kv->getKey(), commit);
                        }
+                       delete kvit;
                }
        }
 
@@ -2106,9 +2158,12 @@ bool Table::updateSpeculativeTable(bool didProcessNewCommits) {
 
                if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, NULL)) {
                        // Guard evaluated to true so update the speculative table
-                       for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+                       while (kvit->hasNext()) {
+                               KeyValue *kv = kvit->next();
                                speculatedKeyValueTable->put(kv->getKey(), kv);
                        }
+                       delete kvit;
                }
        }
 
@@ -2154,9 +2209,12 @@ void Table::updatePendingTransactionSpeculativeTable(bool didProcessNewCommitsOr
 
                if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, pendingTransactionSpeculatedKeyValueTable)) {
                        // Guard evaluated to true so update the speculative table
-                       for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+                       while (kvit->hasNext()) {
+                               KeyValue *kv = kvit->next();
                                pendingTransactionSpeculatedKeyValueTable->put(kv->getKey(), kv);
                        }
+                       delete kvit;
                }
        }
 }
@@ -2210,7 +2268,10 @@ void Table::processSlot(SlotIndexer *indexer, Slot *slot, bool acceptUpdatesToLo
        updateLastMessage(slot->getMachineID(), slot->getSequenceNumber(), slot, acceptUpdatesToLocal, machineSet);
 
        // Process each entry in the slot
-       for (Entry *entry : slot->getEntries()) {
+       Vector<Entry *> *entries = slot->getEntries();
+       uint eSize = entries->size();
+       for(uint ei=0; ei < eSize; ei++) {
+               Entry * entry = entries->get(ei);
                switch (entry->getType()) {
                case TypeCommitPart:
                        processEntry((CommitPart *)entry);
@@ -2362,7 +2423,7 @@ void Table::processEntry(Abort *entry) {
        // keep track of it
        Abort *previouslySeenAbort = liveAbortTable->put(entry->getAbortId(), entry);
        if (previouslySeenAbort != NULL) {
-               previouslySeenAbort->setDead(); // Delete old version of the abort since we got a rescued newer version
+               previouslySeenAbort->setDead();         // Delete old version of the abort since we got a rescued newer version
        }
 
        if (entry->getTransactionArbitrator() == localMachineId) {
@@ -2424,11 +2485,11 @@ void Table::processEntry(TransactionPart *entry) {
        }
 
        // This part is still alive
-       Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *transactionPart = newTransactionParts->get(entry->getMachineId());
+       Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *transactionPart = newTransactionParts->get(entry->getMachineId());
 
        if (transactionPart == NULL) {
                // Dont have a table for this machine Id yet so make one
-               transactionPart = new Hashtable<Pair<int64_t, int32_t>, TransactionPart *>();
+               transactionPart = new Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals>();
                newTransactionParts->put(entry->getMachineId(), transactionPart);
        }
 
@@ -2454,10 +2515,10 @@ void Table::processEntry(CommitPart *entry) {
                }
        }
 
-       Hashtable<Pair<int64_t, int32_t>, CommitPart *> *commitPart = newCommitParts->get(entry->getMachineId());
+       Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *commitPart = newCommitParts->get(entry->getMachineId());
        if (commitPart == NULL) {
                // Don't have a table for this machine Id yet so make one
-               commitPart = new Hashtable<Pair<int64_t, int32_t>, CommitPart *>();
+               commitPart = new Hashtable<Pair<int64_t, int32_t> *, CommitPart *>();
                newCommitParts->put(entry->getMachineId(), commitPart);
        }
        // Update the part and set dead ones we have already seen (got a
index 7cc98ab..eb9faca 100644 (file)
@@ -62,15 +62,15 @@ private:
        Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable;    // Table of speculated key value pairs, if there is a speculative value
        Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable;  // Table of speculated key value pairs, if there is a speculative value from the pending transactions
        Hashtable<IoTString *, NewKey *> *liveNewKeyTable;      // Table of live new keys
-       Hashtable<int64_t, Pair<int64_t, Liveness *> > *lastMessageTable;       // Last message sent by a client machine id -> (Seq Num, Slot or LastMessage);
+       Hashtable<int64_t, Pair<int64_t, Liveness *> *> *lastMessageTable;      // Last message sent by a client machine id -> (Seq Num, Slot or LastMessage);
        Hashtable<int64_t, Hashset<RejectedMessage *> *> *rejectedMessageWatchVectorTable;      // Table of machine Ids and the set of rejected messages they have not seen yet
        Hashtable<IoTString *, int64_t> *arbitratorTable;// Table of keys and their arbitrators
-       Hashtable<Pair<int64_t, int64_t>, Abort *, uintptr_t, 0, pairHashFunction, pairEquals> *liveAbortTable;// Table live abort messages
-       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newTransactionParts;    // transaction parts that are seen in this latest round of slots from the server
-       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newCommitParts;      // commit parts that are seen in this latest round of slots from the server
+       Hashtable<Pair<int64_t, int64_t> *, Abort *, uintptr_t, 0, pairHashFunction, pairEquals> *liveAbortTable;// Table live abort messages
+       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newTransactionParts;  // transaction parts that are seen in this latest round of slots from the server
+       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newCommitParts;    // commit parts that are seen in this latest round of slots from the server
        Hashtable<int64_t, int64_t> *lastArbitratedTransactionNumberByArbitratorTable;  // Last transaction sequence number that an arbitrator arbitrated on
        Hashtable<int64_t, Transaction *> *liveTransactionBySequenceNumberTable;        // live transaction grouped by the sequence number
-       Hashtable<Pair<int64_t, int64_t>, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals> *liveTransactionByTransactionIdTable;      // live transaction grouped by the transaction ID
+       Hashtable<Pair<int64_t, int64_t> *, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals> *liveTransactionByTransactionIdTable;    // live transaction grouped by the transaction ID
        Hashtable<int64_t, Hashtable<int64_t, Commit *> > *liveCommitsTable;
        Hashtable<IoTString *, Commit *> *liveCommitsByKeyTable;
        Hashtable<int64_t, int64_t> *lastCommitSeenSequenceNumberByArbitratorTable;
@@ -81,8 +81,8 @@ private:
        Hashtable<Transaction *, Vector<int32_t> *> *transactionPartsSent;
        Hashtable<int64_t, TransactionStatus *> *outstandingTransactionStatus;
        Hashtable<int64_t, Abort *> *liveAbortsGeneratedByLocal;
-       Hashset<Pair<int64_t, int64_t>, uintptr_t, 0, pairHashFunction, pairEquals> *offlineTransactionsCommittedAndAtServer;
-       Hashtable<int64_t, Pair<IoTString *, int32_t> > *localCommunicationTable;
+       Hashset<Pair<int64_t, int64_t> *, uintptr_t, 0, pairHashFunction, pairEquals> *offlineTransactionsCommittedAndAtServer;
+       Hashtable<int64_t, Pair<IoTString *, int32_t> *> *localCommunicationTable;
        Hashtable<int64_t, int64_t> *lastTransactionSeenFromMachineFromServer;
        Hashtable<int64_t, int64_t> *lastArbitrationDataLocalSequenceNumberSeenFromArbitrator;
        bool lastInsertedNewKey;
index 51fcbf6..77c3590 100644 (file)
@@ -24,7 +24,7 @@ Transaction::Transaction() :
 }
 
 void Transaction::addPartEncode(TransactionPart *newPart) {
-       TransactionPart * old=parts->setExpand(newPart->getPartNumber(), newPart);
+       TransactionPart *old = parts->setExpand(newPart->getPartNumber(), newPart);
        if (old == NULL)
                partCount++;
        partsPendingSend->add(newPart->getPartNumber());
@@ -54,7 +54,7 @@ void Transaction::addPartDecode(TransactionPart *newPart) {
        TransactionPart *previouslySeenPart = parts->setExpand(newPart->getPartNumber(), newPart);
        if (previouslySeenPart == NULL)
                partCount++;
-       
+
        if (previouslySeenPart != NULL) {
                // Set dead the old one since the new one is a rescued version of this part
                previouslySeenPart->setDead();
@@ -101,10 +101,10 @@ int64_t Transaction::getSequenceNumber() {
 
 void Transaction::setSequenceNumber(int64_t _sequenceNumber) {
        sequenceNumber = _sequenceNumber;
-       
+
        for (int32_t i = 0; i < parts->size(); i++) {
-               TransactionPart * tp = parts->get(i);
-               if (tp !=NULL)
+               TransactionPart *tp = parts->get(i);
+               if (tp != NULL)
                        tp->setSequenceNumber(sequenceNumber);
        }
 }
@@ -161,9 +161,9 @@ void Transaction::removeSentParts(Vector<int32_t> *sentParts) {
        nextPartToSend = 0;
        bool changed = false;
        uint lastusedindex = 0;
-       for(uint i=0; i < partsPendingSend->size(); i++) {
+       for (uint i = 0; i < partsPendingSend->size(); i++) {
                int32_t parti = partsPendingSend->get(i);
-               for(uint j=0; j < sentParts->size(); j++) {
+               for (uint j = 0; j < sentParts->size(); j++) {
                        int32_t partj = sentParts->get(j);
                        if (parti == partj) {
                                changed = true;
@@ -171,7 +171,7 @@ void Transaction::removeSentParts(Vector<int32_t> *sentParts) {
                        }
                }
                partsPendingSend->set(lastusedindex++, parti);
-       NextElement:
+NextElement:
                ;
        }
        if (changed) {
@@ -214,7 +214,7 @@ void Transaction::setDead() {
                // Set dead
                isDead = true;
                // Make all the parts of this transaction dead
-               for (int32_t partNumber = 0; partNumber < parts->size(); partNumber ++) {
+               for (int32_t partNumber = 0; partNumber < parts->size(); partNumber++) {
                        TransactionPart *part = parts->get(partNumber);
                        if (part != NULL)
                                part->setDead();
@@ -265,8 +265,8 @@ void Transaction::decodeTransactionData() {
 }
 
 bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKeyValueTable, Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable, Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable) {
-       SetIterator<KeyValue *>* kvit=keyValueGuardSet->iterator();
-       while(kvit->hasNext()) {
+       SetIterator<KeyValue *> *kvit = keyValueGuardSet->iterator();
+       while (kvit->hasNext()) {
                KeyValue *kvGuard = kvit->next();
                // First check if the key is in the speculative table, this is the value of the latest assumption
                KeyValue *kv = NULL;
index 72139c3..0b20bc2 100644 (file)
@@ -2,7 +2,7 @@
 #define URL_H
 #include "common.h"
 class URL {
- public:
+public:
        URL(IoTString *string);
 };
 #endif
index d0b01f6..55ae1fb 100644 (file)
@@ -17,9 +17,9 @@ class Hashset;
 template<typename _Key, typename _KeyInt = uintptr_t, int _Shift = 0, unsigned int (*hash_function)(_Key) = defaultHashFunction<_Key, _Shift, _KeyInt>, bool (*equals)(_Key, _Key) = defaultEquals<_Key> >
 class SetIterator {
 public:
- SetIterator(Hashlistnode<_Key, _Key> *_curr, Hashtable <_Key, _Key, _KeyInt, _Shift, hash_function, equals> *_table) :
-curr(_curr),
-table(_table)
      SetIterator(Hashlistnode<_Key, _Key> *_curr, Hashtable <_Key, _Key, _KeyInt, _Shift, hash_function, equals> *_table) :
+               curr(_curr),
+               table(_table)
        {
        }
 
@@ -64,16 +64,16 @@ table(_table)
        }
 
 private:
-Hashlistnode<_Key,_Key> *curr;
-Hashlistnode<_Key, _Key> *last;
-Hashtable <_Key, _Key, _KeyInt, _Shift, hash_function, equals> *table;
+       Hashlistnode<_Key,_Key> *curr;
+       Hashlistnode<_Key, _Key> *last;
+       Hashtable <_Key, _Key, _KeyInt, _Shift, hash_function, equals> *table;
 };
 
 template<typename _Key, typename _KeyInt = uintptr_t, int _Shift = 0, unsigned int (*hash_function)(_Key) = defaultHashFunction<_Key, _Shift, _KeyInt>, bool (*equals)(_Key, _Key) = defaultEquals<_Key> >
 class Hashset {
 public:
        Hashset(unsigned int initialcapacity = 16, double factor = 0.5) :
-table(new Hashtable<_Key, _Key, _KeyInt, _Shift, hash_function, equals>(initialcapacity, factor))
+               table(new Hashtable<_Key, _Key, _KeyInt, _Shift, hash_function, equals>(initialcapacity, factor))
        {
        }
 
@@ -174,7 +174,7 @@ private:
 };
 
 template<typename _Key, typename _Val, typename _KeyInt, int _Shift, unsigned int (*hash_function)(_Key), bool (*equals)(_Key, _Key)>
-       SetIterator<_Key, _KeyInt, _Shift, hash_function, equals> * getKeyIterator(Hashtable<_Key,_Val,_KeyInt,_Shift,hash_function,equals> *table) {
+SetIterator<_Key, _KeyInt, _Shift, hash_function, equals> *getKeyIterator(Hashtable<_Key,_Val,_KeyInt,_Shift,hash_function,equals> *table) {
        return new SetIterator<_Key, _KeyInt, _Shift, hash_function, equals>(table->list, table);
 }
 #endif
index 3ded5b5..aca3361 100644 (file)
@@ -31,8 +31,8 @@ struct Hashlistnode {
        _Key key;
        _Val val;
        uint hashcode;
-       struct Hashlistnode<_Key, _Val> * next;
-       struct Hashlistnode<_Key, _Val> * prev;
+       struct Hashlistnode<_Key, _Val> *next;
+       struct Hashlistnode<_Key, _Val> *prev;
 };
 
 template<typename _Key, int _Shift, typename _KeyInt>
@@ -59,6 +59,7 @@ inline bool defaultEquals(_Key key1, _Key key2) {
  *                 manipulation and storage.
  * @tparam _Shift  Logical shift to apply to all keys. Default 0.
  */
+
 template<typename _Key, typename _Val, typename _KeyInt = uintptr_t, int _Shift = 0, unsigned int (*hash_function)(_Key) = defaultHashFunction<_Key, _Shift, _KeyInt>, bool (*equals)(_Key, _Key) = defaultEquals<_Key> >
 class Hashtable {
 public:
@@ -82,6 +83,17 @@ public:
                tail = list = NULL;
        }
 
+Hashtable<_Key, _Val, _KeyInt, _Shift, hash_function, equals> * clone() {
+       Hashtable<_Key, _Val, _KeyInt, _Shift, hash_function, equals> * ctable = new Hashtable<_Key, _Val, _KeyInt, _Shift, hash_function, equals> (capacity, loadfactor);
+       struct Hashlistnode<_Key, _Val> * ptr = list;
+       while (ptr != NULL) {
+               ctable->put(ptr->key, ptr->val);
+               ptr = ptr->next;
+       }
+       return ctable;
+}
+
+
        /** @brief Hash table destructor */
        ~Hashtable() {
                ourfree(table);
@@ -302,16 +314,16 @@ public:
                                return (_Val)0;
                        } else {
                                _Val v = zero->val;
-                               if (zero -> next != NULL)
-                                       zero -> next -> prev = zero ->prev;
+                               if (zero->next != NULL)
+                                       zero->next->prev = zero->prev;
                                else
-                                       tail = zero -> prev;
+                                       tail = zero->prev;
 
-                               if (zero -> prev != NULL)
-                                       zero -> prev -> next = zero -> next;
+                               if (zero->prev != NULL)
+                                       zero->prev->next = zero->next;
                                else
                                        list = zero->next;
-                                       
+
                                ourfree(zero);
                                zero = NULL;
                                Size--;
@@ -335,17 +347,17 @@ public:
                                        //empty out this bin
                                        search->val = (_Val) 1;
                                        search->key = 0;
-                                       
-                                       if (search -> next != NULL)
-                                               search -> next -> prev = search ->prev;
+
+                                       if (search->next != NULL)
+                                               search->next->prev = search->prev;
                                        else
-                                               tail = search -> prev;
-                                       
-                                       if (search -> prev != NULL)
-                                               search -> prev -> next = search -> next;
+                                               tail = search->prev;
+
+                                       if (search->prev != NULL)
+                                               search->prev->next = search->next;
                                        else
                                                list = search->next;
-                                       
+
                                        Size--;
                                        return v;
                                }
@@ -428,9 +440,9 @@ public:
 
                        if (tail == NULL)
                                tail = search;
-                       search -> next = list;
+                       search->next = list;
                        if (list != NULL)
-                               list -> prev = search;
+                               list->prev = search;
                        list = search;
                        search->hashcode = hashcode;
                        search->key = key;
@@ -443,9 +455,9 @@ public:
        unsigned int getCapacity() {return capacity;}
        struct Hashlistnode<_Key, _Val> *table;
        struct Hashlistnode<_Key, _Val> *zero;
-  struct Hashlistnode<_Key, _Val> * list;
-  struct Hashlistnode<_Key, _Val> * tail;
-  unsigned int capacity;
+       struct Hashlistnode<_Key, _Val> *list;
+       struct Hashlistnode<_Key, _Val> *tail;
+       unsigned int capacity;
        unsigned int Size;
 private:
        unsigned int capacitymask;