From a2f47bf7088deea524750936103f5a683fd97b79 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 18 Jan 2018 17:26:20 -0800 Subject: [PATCH] more edits --- version2/src/C/NewKey.cc | 75 ++---- version2/src/C/NewKey.h | 80 +++--- version2/src/C/PendingTransaction.cc | 360 ++++++++++++--------------- version2/src/C/PendingTransaction.h | 262 ++++--------------- version2/src/C/SlotIndexer.cc | 35 ++- version2/src/C/SlotIndexer.h | 33 +-- version2/src/C/ThreeTuple.cc | 28 --- version2/src/C/ThreeTuple.h | 51 ++-- version2/src/C/TimingSingleton.cc | 32 --- version2/src/C/TimingSingleton.h | 66 ++--- version2/src/C/common.h | 3 +- 11 files changed, 351 insertions(+), 674 deletions(-) delete mode 100644 version2/src/C/ThreeTuple.cc delete mode 100644 version2/src/C/TimingSingleton.cc diff --git a/version2/src/C/NewKey.cc b/version2/src/C/NewKey.cc index 745f22d..85a5234 100644 --- a/version2/src/C/NewKey.cc +++ b/version2/src/C/NewKey.cc @@ -1,59 +1,22 @@ +#include "NewKey.h" +#include "ByteBuffer.h" + +Entry * decode(Slot * slot, ByteBuffer * bb) { + int keylength = bb->getInt(); + Array * key = new Array(keylength); + bb->get(key); + int64_t machineid = bb->getLong(); + + return new NewKey(slot, IoTString.shallow(key), machineid); +} +void NewKey::encode(ByteBuffer * bb) { + bb->put(TypeNewKey); + bb->putInt(key->length()); + bb->put(key->internalBytes()); + bb->putLong(machineid); +} -/** - * This Entry records the abort sent by a given machine. - * @author Ali Younis - * @version 1.0 - */ - - -class NewKey extends Entry { - IoTString key; - int64_t machineid; - - NewKey(Slot slot, IoTString _key, int64_t _machineid) { - super(slot); - key = _key; - machineid = _machineid; - } - - int64_t getMachineID() { - return machineid; - } - - IoTString getKey() { - return key; - } - - void setSlot(Slot s) { - parentslot = s; - } - - static Entry decode(Slot slot, ByteBuffer bb) { - int keylength = bb.getInt(); - char[] key = new char[keylength]; - bb.get(key); - int64_t machineid = bb.getLong(); - - return new NewKey(slot, IoTString.shallow(key), machineid); - } - - void encode(ByteBuffer bb) { - bb.put(Entry.TypeNewKey); - bb.putInt(key.length()); - bb.put(key.internalBytes()); - bb.putLong(machineid); - } - - int getSize() { - return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length(); - } - - char getType() { - return Entry.TypeNewKey; - } - - Entry getCopy(Slot s) { - return new NewKey(s, key, machineid); - } +int NewKey::getSize() { + return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length(); } diff --git a/version2/src/C/NewKey.h b/version2/src/C/NewKey.h index 73c6400..53a8f8c 100644 --- a/version2/src/C/NewKey.h +++ b/version2/src/C/NewKey.h @@ -1,4 +1,5 @@ - +#ifndef NEWKEY_H +#define NEWKEY_H /** * This Entry records the abort sent by a given machine. @@ -7,53 +8,30 @@ */ -class NewKey extends Entry { - private IoTString key; - private int64_t machineid; - - public NewKey(Slot slot, IoTString _key, int64_t _machineid) { - super(slot); - key = _key; - machineid = _machineid; - } - - public int64_t getMachineID() { - return machineid; - } - - public IoTString getKey() { - return key; - } - - public void setSlot(Slot s) { - parentslot = s; - } - - static Entry decode(Slot slot, ByteBuffer bb) { - int keylength = bb.getInt(); - char[] key = new char[keylength]; - bb.get(key); - int64_t machineid = bb.getLong(); - - return new NewKey(slot, IoTString.shallow(key), machineid); - } - - public void encode(ByteBuffer bb) { - bb.put(Entry.TypeNewKey); - bb.putInt(key.length()); - bb.put(key.internalBytes()); - bb.putLong(machineid); - } - - public int getSize() { - return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length(); - } - - public char getType() { - return Entry.TypeNewKey; - } - - public Entry getCopy(Slot s) { - return new NewKey(s, key, machineid); - } -} +class NewKey : public Entry { + private: + IoTString * key; + int64_t machineid; + + + public: + NewKey(Slot * slot, IoTString * _key, int64_t _machineid) : + Entry(slot), + key(_key), + machineid(_machineid) { + } + + int64_t getMachineID() { return machineid; } + IoTString * getKey() { return key; } + void setSlot(Slot * s) { parentslot = s; } + + + void encode(ByteBuffer * bb); + int getSize(); + char getType() { return TypeNewKey; } + + Entry * getCopy(Slot * s) { return new NewKey(s, key, machineid); } +}; + +Entry * NewKey_decode(Slot *slot, ByteBuffer *bb); + diff --git a/version2/src/C/PendingTransaction.cc b/version2/src/C/PendingTransaction.cc index 5495e35..0d45dc2 100644 --- a/version2/src/C/PendingTransaction.cc +++ b/version2/src/C/PendingTransaction.cc @@ -1,211 +1,167 @@ +#include "PendingTransaction.h" + +PendingTransaction::PendingTransaction(int64_t _machineId) : + keyValueUpdateSet(new Hashset()), + keyValueGuardSet(new HashSet()), + arbitrator(-1), + clientLocalSequenceNumber(-1), + machineId(_machineId), + currentDataSize(0) { +} +/** + * Add a new key value to the updates + * + */ +void PendingTransaction::addKV(KeyValue * newKV) { + + KeyValue rmKV = NULL; + + // Make sure there are no duplicates + for (KeyValue kv : keyValueUpdateSet) { + if (kv.getKey().equals(newKV.getKey())) { + + // Remove key if we are adding a newer version of the same key + rmKV = kv; + break; + } + } + + // Remove key if we are adding a newer version of the same key + if (rmKV != NULL) { + keyValueUpdateSet.remove(rmKV); + currentDataSize -= rmKV.getSize(); + } + + // Add the key to the hash set + keyValueUpdateSet.add(newKV); + currentDataSize += newKV.getSize(); +} +/** + * Add a new key value to the guard set + * + */ +void PendingTransaction::addKVGuard(KeyValue * newKV) { + // Add the key to the hash set + keyValueGuardSet.add(newKV); + currentDataSize += newKV.getSize(); +} +/** + * Checks if the arbitrator is the same + */ +bool PendingTransaction::checkArbitrator(int64_t arb) { + if (arbitrator == -1) { + arbitrator = arb; + return true; + } + + return arb == arbitrator; +} -class PendingTransaction { - - Set keyValueUpdateSet = NULL; - Set keyValueGuardSet = NULL; - int64_t arbitrator = -1; - int64_t clientLocalSequenceNumber = -1; - int64_t machineId = -1; - - int currentDataSize = 0; - - PendingTransaction(int64_t _machineId) { - machineId = _machineId; - keyValueUpdateSet = new HashSet(); - keyValueGuardSet = new HashSet(); - } - - /** - * Add a new key value to the updates - * - */ - void addKV(KeyValue newKV) { - - KeyValue rmKV = NULL; - - // Make sure there are no duplicates - for (KeyValue kv : keyValueUpdateSet) { - if (kv.getKey().equals(newKV.getKey())) { - - // Remove key if we are adding a newer version of the same key - rmKV = kv; - break; - } - } - - // Remove key if we are adding a newer version of the same key - if (rmKV != NULL) { - keyValueUpdateSet.remove(rmKV); - currentDataSize -= rmKV.getSize(); - } - - // Add the key to the hash set - keyValueUpdateSet.add(newKV); - currentDataSize += newKV.getSize(); - } - - /** - * Add a new key value to the guard set - * - */ - void addKVGuard(KeyValue newKV) { - // Add the key to the hash set - keyValueGuardSet.add(newKV); - currentDataSize += newKV.getSize(); - } - - /** - * Checks if the arbitrator is the same - */ - bool checkArbitrator(int64_t arb) { - if (arbitrator == -1) { - arbitrator = arb; - return true; - } - - return arb == arbitrator; - } - - /** - * Get the transaction arbitrator - */ - int64_t getArbitrator() { - return arbitrator; - } - - /** - * Get the key value update set - */ - Set getKVUpdates() { - return keyValueUpdateSet; - } - - /** - * Get the key value update set - */ - Set getKVGuard() { - return keyValueGuardSet; - } - - void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) { - clientLocalSequenceNumber = _clientLocalSequenceNumber; - } - - int64_t getClientLocalSequenceNumber() { - return clientLocalSequenceNumber; - } - - int64_t getMachineId() { - return machineId; - } - - bool evaluateGuard(Map keyValTableCommitted, Map keyValTableSpeculative, Map keyValTablePendingTransSpeculative) { - for (KeyValue kvGuard : keyValueGuardSet) { - - // First check if the key is in the speculative table, this is the value of the latest assumption - KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey()); - - - if (kv == NULL) { - // if it is not in the pending trans table then check the speculative table and use that - // value as our latest assumption - kv = keyValTableSpeculative.get(kvGuard.getKey()); - } - - - if (kv == NULL) { - // if it is not in the speculative table then check the committed table and use that - // value as our latest assumption - kv = keyValTableCommitted.get(kvGuard.getKey()); - } - - if (kvGuard.getValue() != NULL) { - if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) { - return false; - } - } else { - if (kv != NULL) { - return false; - } - } +bool PendingTransaction::evaluateGuard(Hashtable keyValTableCommitted, Hashtable keyValTableSpeculative, Hashtable keyValTablePendingTransSpeculative) { + for (KeyValue kvGuard : keyValueGuardSet) { + + // First check if the key is in the speculative table, this is the value of the latest assumption + KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey()); + + + if (kv == NULL) { + // if it is not in the pending trans table then check the speculative table and use that + // value as our latest assumption + kv = keyValTableSpeculative.get(kvGuard.getKey()); + } + + + if (kv == NULL) { + // if it is not in the speculative table then check the committed table and use that + // value as our latest assumption + kv = keyValTableCommitted.get(kvGuard.getKey()); + } + + if (kvGuard.getValue() != NULL) { + if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) { + return false; + } + } else { + if (kv != NULL) { + return false; + } + } } - return true; - } - - Transaction createTransaction() { - - Transaction newTransaction = new Transaction(); - int transactionPartCount = 0; - - // Convert all the data into a char array so we can start partitioning - char[] charData = convertDataToBytes(); - - int currentPosition = 0; - int remaining = charData.length; - - while (remaining > 0) { - - Boolean isLastPart = false; - // determine how much to copy - int copySize = TransactionPart.MAX_NON_HEADER_SIZE; - if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) { - copySize = remaining; - isLastPart = true; // last bit of data so last part - } - - // Copy to a smaller version - char[] partData = new char[copySize]; - System.arraycopy(charData, currentPosition, partData, 0, copySize); - - TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart); - newTransaction.addPartEncode(part); + return true; +} +Transaction * PendingTransaction::createTransaction() { + Transaction * newTransaction = new Transaction(); + int transactionPartCount = 0; + + // Convert all the data into a char array so we can start partitioning + Array * charData = convertDataToBytes(); + + int currentPosition = 0; + int remaining = charData.length; + + while (remaining > 0) { + + Boolean isLastPart = false; + // determine how much to copy + int copySize = TransactionPart.MAX_NON_HEADER_SIZE; + if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) { + copySize = remaining; + isLastPart = true; // last bit of data so last part + } + + // Copy to a smaller version + char[] partData = new char[copySize]; + System.arraycopy(charData, currentPosition, partData, 0, copySize); + + TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart); + newTransaction.addPartEncode(part); + // Update position, count and remaining - currentPosition += copySize; - transactionPartCount++; - remaining -= copySize; - } - - // Add the Guard Conditions - for (KeyValue kv : keyValueGuardSet) { - newTransaction.addGuardKV(kv); - } - - // Add the updates - for (KeyValue kv : keyValueUpdateSet) { - newTransaction.addUpdateKV(kv); - } - - return newTransaction; - } - - char[] convertDataToBytes() { - - // Calculate the size of the data - int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's - sizeOfData += currentDataSize; - - // Data handlers and storage - char[] dataArray = new char[sizeOfData]; - ByteBuffer bbEncode = ByteBuffer.wrap(dataArray); - - // Encode the size of the updates and guard sets - bbEncode.putInt(keyValueGuardSet.size()); - bbEncode.putInt(keyValueUpdateSet.size()); - - // Encode all the guard conditions - for (KeyValue kv : keyValueGuardSet) { - kv.encode(bbEncode); - } - - // Encode all the updates - for (KeyValue kv : keyValueUpdateSet) { - kv.encode(bbEncode); - } + currentPosition += copySize; + transactionPartCount++; + remaining -= copySize; + } + + // Add the Guard Conditions + for (KeyValue kv : keyValueGuardSet) { + newTransaction.addGuardKV(kv); + } + + // Add the updates + for (KeyValue kv : keyValueUpdateSet) { + newTransaction.addUpdateKV(kv); + } + + return newTransaction; +} - return bbEncode.array(); - } +Arrar * PendingTransaction::convertDataToBytes() { + // Calculate the size of the data + int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's + sizeOfData += currentDataSize; + + // Data handlers and storage + Array * dataArray = new Array(sizeOfData); + ByteBuffer * bbEncode = ByteBuffer_wrap(dataArray); + + // Encode the size of the updates and guard sets + bbEncode->putInt(keyValueGuardSet.size()); + bbEncode->putInt(keyValueUpdateSet.size()); + + // Encode all the guard conditions + for (KeyValue kv : keyValueGuardSet) { + kv->encode(bbEncode); + } + + // Encode all the updates + for (KeyValue kv : keyValueUpdateSet) { + kv->encode(bbEncode); + } + + return bbEncode->array(); } + diff --git a/version2/src/C/PendingTransaction.h b/version2/src/C/PendingTransaction.h index 0e4249b..7e60ce8 100644 --- a/version2/src/C/PendingTransaction.h +++ b/version2/src/C/PendingTransaction.h @@ -1,211 +1,57 @@ +#ifndef PENDINGTRANSACTION_H +#define PENDINGTRANSACTION_H - - +#include "common.h" class PendingTransaction { - - private Set keyValueUpdateSet = NULL; - private Set keyValueGuardSet = NULL; - private int64_t arbitrator = -1; - private int64_t clientLocalSequenceNumber = -1; - private int64_t machineId = -1; - - private int currentDataSize = 0; - - public PendingTransaction(int64_t _machineId) { - machineId = _machineId; - keyValueUpdateSet = new HashSet(); - keyValueGuardSet = new HashSet(); - } - - /** - * Add a new key value to the updates - * - */ - public void addKV(KeyValue newKV) { - - KeyValue rmKV = NULL; - - // Make sure there are no duplicates - for (KeyValue kv : keyValueUpdateSet) { - if (kv.getKey().equals(newKV.getKey())) { - - // Remove key if we are adding a newer version of the same key - rmKV = kv; - break; - } - } - - // Remove key if we are adding a newer version of the same key - if (rmKV != NULL) { - keyValueUpdateSet.remove(rmKV); - currentDataSize -= rmKV.getSize(); - } - - // Add the key to the hash set - keyValueUpdateSet.add(newKV); - currentDataSize += newKV.getSize(); - } - - /** - * Add a new key value to the guard set - * - */ - public void addKVGuard(KeyValue newKV) { - // Add the key to the hash set - keyValueGuardSet.add(newKV); - currentDataSize += newKV.getSize(); - } - - /** - * Checks if the arbitrator is the same - */ - public bool checkArbitrator(int64_t arb) { - if (arbitrator == -1) { - arbitrator = arb; - return true; - } - - return arb == arbitrator; - } - - /** - * Get the transaction arbitrator - */ - public int64_t getArbitrator() { - return arbitrator; - } - - /** - * Get the key value update set - */ - public Set getKVUpdates() { - return keyValueUpdateSet; - } - - /** - * Get the key value update set - */ - public Set getKVGuard() { - return keyValueGuardSet; - } - - public void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) { - clientLocalSequenceNumber = _clientLocalSequenceNumber; - } - - public int64_t getClientLocalSequenceNumber() { - return clientLocalSequenceNumber; - } - - public int64_t getMachineId() { - return machineId; - } - - public bool evaluateGuard(Map keyValTableCommitted, Map keyValTableSpeculative, Map keyValTablePendingTransSpeculative) { - for (KeyValue kvGuard : keyValueGuardSet) { - - // First check if the key is in the speculative table, this is the value of the latest assumption - KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey()); - - - if (kv == NULL) { - // if it is not in the pending trans table then check the speculative table and use that - // value as our latest assumption - kv = keyValTableSpeculative.get(kvGuard.getKey()); - } - - - if (kv == NULL) { - // if it is not in the speculative table then check the committed table and use that - // value as our latest assumption - kv = keyValTableCommitted.get(kvGuard.getKey()); - } - - if (kvGuard.getValue() != NULL) { - if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) { - return false; - } - } else { - if (kv != NULL) { - return false; - } - } - } - return true; - } - - public Transaction createTransaction() { - - Transaction newTransaction = new Transaction(); - int transactionPartCount = 0; - - // Convert all the data into a char array so we can start partitioning - char[] charData = convertDataToBytes(); - - int currentPosition = 0; - int remaining = charData.length; - - while (remaining > 0) { - - Boolean isLastPart = false; - // determine how much to copy - int copySize = TransactionPart.MAX_NON_HEADER_SIZE; - if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) { - copySize = remaining; - isLastPart = true; // last bit of data so last part - } - - // Copy to a smaller version - char[] partData = new char[copySize]; - System.arraycopy(charData, currentPosition, partData, 0, copySize); - - TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart); - newTransaction.addPartEncode(part); - - // Update position, count and remaining - currentPosition += copySize; - transactionPartCount++; - remaining -= copySize; - } - - // Add the Guard Conditions - for (KeyValue kv : keyValueGuardSet) { - newTransaction.addGuardKV(kv); - } - - // Add the updates - for (KeyValue kv : keyValueUpdateSet) { - newTransaction.addUpdateKV(kv); - } - - return newTransaction; - } - - private char[] convertDataToBytes() { - - // Calculate the size of the data - int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's - sizeOfData += currentDataSize; - - // Data handlers and storage - char[] dataArray = new char[sizeOfData]; - ByteBuffer bbEncode = ByteBuffer.wrap(dataArray); - - // Encode the size of the updates and guard sets - bbEncode.putInt(keyValueGuardSet.size()); - bbEncode.putInt(keyValueUpdateSet.size()); - - // Encode all the guard conditions - for (KeyValue kv : keyValueGuardSet) { - kv.encode(bbEncode); - } - - // Encode all the updates - for (KeyValue kv : keyValueUpdateSet) { - kv.encode(bbEncode); - } - - return bbEncode.array(); - } -} + private: + Hashset * keyValueUpdateSet = NULL; + Hashset * keyValueGuardSet = NULL; + int64_t arbitrator = -1; + int64_t clientLocalSequenceNumber = -1; + int64_t machineId = -1; + int32_T currentDataSize = 0; + + public: + PendingTransaction(int64_t _machineId); + /** + * Add a new key value to the updates + * + */ + void addKV(KeyValue newKV); + /** + * Add a new key value to the guard set + * + */ + void addKVGuard(KeyValue newKV); + /** + * Checks if the arbitrator is the same + */ + bool checkArbitrator(int64_t arb); + /** + * Get the transaction arbitrator + */ + int64_t getArbitrator(); + /** + * Get the key value update set + */ + Hashset * getKVUpdates() { return keyValueUpdateSet; } + + /** + * Get the key value update set + */ + public Hashset * getKVGuard() { return keyValueGuardSet; } + + void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) { clientLocalSequenceNumber = _clientLocalSequenceNumber; } + + int64_t getClientLocalSequenceNumber() { return clientLocalSequenceNumber; } + + int64_t getMachineId() { return machineId; } + + bool evaluateGuard(Hashtable keyValTableCommitted, Hashtable keyValTableSpeculative, Hashtable keyValTablePendingTransSpeculative); + + Transaction * createTransaction(); + + Array * convertDataToBytes(); +}; +#endif diff --git a/version2/src/C/SlotIndexer.cc b/version2/src/C/SlotIndexer.cc index f093c40..0fa6449 100644 --- a/version2/src/C/SlotIndexer.cc +++ b/version2/src/C/SlotIndexer.cc @@ -1,3 +1,4 @@ +#include "SlotIndexer.h" /** * Slot indexer allows slots in both the slot buffer and the new @@ -6,25 +7,19 @@ * @version 1.0 */ -class SlotIndexer { - Slot[] updates; - SlotBuffer buffer; - int64_t firstslotseqnum; - - SlotIndexer(Slot[] _updates, SlotBuffer _buffer) { - buffer = _buffer; - updates = _updates; - firstslotseqnum = updates[0].getSequenceNumber(); - } +SlotIndexer::SlotIndexer(Array * _updates, SlotBuffer * _buffer) : + buffer(_buffer), + updates(_updates), + firstslotseqnum(updates->get(0)->getSequenceNumber()) { +} - Slot getSlot(int64_t seqnum) { - if (seqnum >= firstslotseqnum) { - int offset = (int) (seqnum - firstslotseqnum); - if (offset >= updates.length) - throw new Error("Invalid Slot Sequence Number Reference"); - else - return updates[offset]; - } else - return buffer.getSlot(seqnum); - } +Slot * SlotIndexer::getSlot(int64_t seqnum) { + if (seqnum >= firstslotseqnum) { + int32_t offset = (int32_t) (seqnum - firstslotseqnum); + if (offset >= updates->length()) + throw new Error("Invalid Slot Sequence Number Reference"); + else + return updates->get(offset); + } else + return buffer->getSlot(seqnum); } diff --git a/version2/src/C/SlotIndexer.h b/version2/src/C/SlotIndexer.h index b69a8b8..c4f54eb 100644 --- a/version2/src/C/SlotIndexer.h +++ b/version2/src/C/SlotIndexer.h @@ -1,4 +1,6 @@ - +#ifndef SLOTINDEXER_H +#define SLOTINDEXER_H +#include "common.h" /** * Slot indexer allows slots in both the slot buffer and the new * server response to looked up in a consistent fashion. @@ -7,24 +9,13 @@ */ class SlotIndexer { - private Slot[] updates; - private SlotBuffer buffer; - private int64_t firstslotseqnum; - - SlotIndexer(Slot[] _updates, SlotBuffer _buffer) { - buffer = _buffer; - updates = _updates; - firstslotseqnum = updates[0].getSequenceNumber(); - } + private: + Array * updates; + SlotBuffer * buffer; + int64_t firstslotseqnum; - Slot getSlot(int64_t seqnum) { - if (seqnum >= firstslotseqnum) { - int offset = (int) (seqnum - firstslotseqnum); - if (offset >= updates.length) - throw new Error("Invalid Slot Sequence Number Reference"); - else - return updates[offset]; - } else - return buffer.getSlot(seqnum); - } -} + public: + SlotIndexer(Array * _updates, SlotBuffer * _buffer); + Slot* getSlot(int64_t seqnum); +}; +#endif; diff --git a/version2/src/C/ThreeTuple.cc b/version2/src/C/ThreeTuple.cc deleted file mode 100644 index eed94d0..0000000 --- a/version2/src/C/ThreeTuple.cc +++ /dev/null @@ -1,28 +0,0 @@ - -class ThreeTuple { - A a; - B b; - C c; - - ThreeTuple(A a, B b, C c) { - this.a = a; - this.b = b; - this.c = c; - } - - A getFirst() { - return a; - } - - B getSecond() { - return b; - } - - C getThird() { - return c; - } - - String toString() { - return "<" + a + "," + b + "," + c + ">"; - } -} diff --git a/version2/src/C/ThreeTuple.h b/version2/src/C/ThreeTuple.h index 5522121..ef5bcb5 100644 --- a/version2/src/C/ThreeTuple.h +++ b/version2/src/C/ThreeTuple.h @@ -1,28 +1,27 @@ +#ifndef THREETUPLE_H +#define THREETUPLE_H -class ThreeTuple { - private A a; - private B b; - private C c; +template + class ThreeTuple { + private: + A a; + B b; + C c; - ThreeTuple(A a, B b, C c) { - this.a = a; - this.b = b; - this.c = c; - } - - A getFirst() { - return a; - } - - B getSecond() { - return b; - } - - C getThird() { - return c; - } - - public String toString() { - return "<" + a + "," + b + "," + c + ">"; - } -} + public: + ThreeTuple(A _a, B _b, C _c) : + a(_a), + b(_b), + c(_c) { + } + A getFirst() { + return a; + } + B getSecond() { + return b; + } + C getThird() { + return c; + } +}; +#endif diff --git a/version2/src/C/TimingSingleton.cc b/version2/src/C/TimingSingleton.cc deleted file mode 100644 index 57e4f04..0000000 --- a/version2/src/C/TimingSingleton.cc +++ /dev/null @@ -1,32 +0,0 @@ - - -class TimingSingleton { - static TimingSingleton singleton = new TimingSingleton( ); - static int64_t startTime = 0; - - static int64_t totalTime = 0; - - TimingSingleton() { - - } - - static TimingSingleton getInstance( ) { - return singleton; - } - - - static void startTime( ) { - startTime = System.nanoTime(); - } - - static void endTime( ) { - totalTime += System.nanoTime() - startTime; - - } - - static int64_t getTime( ) { - return totalTime; - } - - -} diff --git a/version2/src/C/TimingSingleton.h b/version2/src/C/TimingSingleton.h index a6e1aac..4983f81 100644 --- a/version2/src/C/TimingSingleton.h +++ b/version2/src/C/TimingSingleton.h @@ -1,32 +1,40 @@ - +#ifndef TIMINGSINGLETON_H +#define TIMINGSINGLETON_H +#include class TimingSingleton { - private static TimingSingleton singleton = new TimingSingleton( ); - private static int64_t startTime = 0; - - private static int64_t totalTime = 0; - - private TimingSingleton() { - - } - - public static TimingSingleton getInstance( ) { - return singleton; - } - - - public static void startTime( ) { - startTime = System.nanoTime(); - } - - public static void endTime( ) { - totalTime += System.nanoTime() - startTime; - - } - - public static int64_t getTime( ) { - return totalTime; - } - - + private: + static TimingSingleton singleton = new TimingSingleton( ); + int64_t startTime = 0; + int64_t totalTime = 0; + + TimingSingleton() : startTime(0), + totalTime(0) { + } + + int64_t nanoTime() { + int64_t time; + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec*1000000000+tv.tv_usec*1000; + } + + public: + void startTime() { + startTime = nanoTime(); + } + + void endTime() { + totalTime += nanoTime() - startTime; + } + + int64_t getTime() { + return totalTime; + } +}; + +TimingSingleton t_singleton; +TimingSingleton * TimingSingleton_getInstance() { + return &t_singleton; } +#endif diff --git a/version2/src/C/common.h b/version2/src/C/common.h index 4803b60..764c2f2 100644 --- a/version2/src/C/common.h +++ b/version2/src/C/common.h @@ -10,7 +10,7 @@ typedef uint32_t uint; #include "array.h" - +class TimingSingleton; class Abort; class Entry; class Slot; @@ -22,5 +22,6 @@ class ArbitrationRound; class KeyValue; class IoTString; class RejectedMessage; +class PendingTransaction; #endif -- 2.34.1