From 55670da0c67520c7986b800cd5a33fdf20349663 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 18 Jan 2018 17:57:33 -0800 Subject: [PATCH] edits --- version2/src/C/LastMessage.cc | 56 ++++++---------------------- version2/src/C/LastMessage.h | 70 +++++++++++++---------------------- version2/src/C/hashset.h | 10 ++--- 3 files changed, 43 insertions(+), 93 deletions(-) diff --git a/version2/src/C/LastMessage.cc b/version2/src/C/LastMessage.cc index 036e247..55eec50 100644 --- a/version2/src/C/LastMessage.cc +++ b/version2/src/C/LastMessage.cc @@ -1,4 +1,6 @@ - +#include "LastMessage.h" +#include "Slot.h" +#include "ByteBuffer.h" /** * This Entry records the last message sent by a given machine. @@ -6,48 +8,14 @@ * @version 1.0 */ - -class LastMessage extends Entry { - int64_t machineid; - int64_t seqnum; - - LastMessage(Slot slot, int64_t _machineid, int64_t _seqnum) { - super(slot); - machineid=_machineid; - seqnum=_seqnum; - } - - int64_t getMachineID() { - return machineid; - } - - int64_t getSequenceNumber() { - return seqnum; - } - - static Entry decode(Slot slot, ByteBuffer bb) { - int64_t machineid=bb->getLong(); - int64_t seqnum=bb->getLong(); - return new LastMessage(slot, machineid, seqnum); - } - - void encode(ByteBuffer bb) { - bb->put(Entry.TypeLastMessage); - bb->putLong(machineid); - bb->putLong(seqnum); - } - - int getSize() { - return 2*sizeof(int64_t)+sizeof(char); - } - - char getType() { - return Entry.TypeLastMessage; - } - - Entry getCopy(Slot s) { - return new LastMessage(s, machineid, seqnum); - } +Entry * LastMessage_decode(Slot * slot, ByteBuffer * bb) { + int64_t machineid=bb->getLong(); + int64_t seqnum=bb->getLong(); + return new LastMessage(slot, machineid, seqnum); } - +void LastMessage::encode(ByteBuffer * bb) { + bb->put(TypeLastMessage); + bb->putLong(machineid); + bb->putLong(seqnum); +} diff --git a/version2/src/C/LastMessage.h b/version2/src/C/LastMessage.h index ef38af8..d4cddd0 100644 --- a/version2/src/C/LastMessage.h +++ b/version2/src/C/LastMessage.h @@ -1,4 +1,8 @@ +#ifndef LASTMESSAGE_H +#define LASTMESSAGE_H +#include"common.h" +#include"Entry.h" /** * This Entry records the last message sent by a given machine. @@ -7,47 +11,25 @@ */ -class LastMessage extends Entry { - private int64_t machineid; - private int64_t seqnum; - - public LastMessage(Slot slot, int64_t _machineid, int64_t _seqnum) { - super(slot); - machineid=_machineid; - seqnum=_seqnum; - } - - public int64_t getMachineID() { - return machineid; - } - - public int64_t getSequenceNumber() { - return seqnum; - } - - static Entry decode(Slot slot, ByteBuffer bb) { - int64_t machineid=bb->getLong(); - int64_t seqnum=bb->getLong(); - return new LastMessage(slot, machineid, seqnum); - } - - public void encode(ByteBuffer bb) { - bb->put(Entry.TypeLastMessage); - bb->putLong(machineid); - bb->putLong(seqnum); - } - - public int getSize() { - return 2*sizeof(int64_t)+sizeof(char); - } - - public char getType() { - return Entry.TypeLastMessage; - } - - public Entry getCopy(Slot s) { - return new LastMessage(s, machineid, seqnum); - } -} - - +class LastMessage : public Entry { + private: + int64_t machineid; + int64_t seqnum; + + public: + LastMessage(Slot * slot, int64_t _machineid, int64_t _seqnum) : + Entry(slot), + machineid(_machineid), + seqnum(_seqnum) { + } + + int64_t getMachineID() { return machineid; } + int64_t getSequenceNumber() { return seqnum; } + void encode(ByteBuffer * bb); + int getSize() { return 2*sizeof(int64_t)+sizeof(char); } + char getType() { return TypeLastMessage; } + Entry * getCopy(Slot * s) { return new LastMessage(s, machineid, seqnum); } +}; + +Entry * LastMessage_decode(Slot * slot, ByteBuffer * bb); +#endif diff --git a/version2/src/C/hashset.h b/version2/src/C/hashset.h index 2a94d96..7874e65 100644 --- a/version2/src/C/hashset.h +++ b/version2/src/C/hashset.h @@ -162,10 +162,10 @@ public: /** @brief Return random key from set. */ _Key getRandomElement() { - if (getSize() == 0) + if (size() == 0) return NULL; - else if (getSize() < 6) { - uint count = random() % getSize(); + else if (size() < 6) { + uint count = random() % size(); Linknode<_Key> *ptr = list; while (count > 0) { ptr = ptr->next; @@ -216,12 +216,12 @@ public: return true; } - unsigned int getSize() const { + unsigned int size() const { return table->getSize(); } bool isEmpty() const { - return getSize() == 0; + return size() == 0; } SetIterator<_Key, _KeyInt, _Shift, hash_function, equals> *iterator() { -- 2.34.1