Skip to content

Commit

Permalink
Changing incoming attribute storage from vector to map
Browse files Browse the repository at this point in the history
  • Loading branch information
grf14003 committed May 7, 2020
1 parent 273a7fd commit 725a42a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 12 additions & 1 deletion bfs/include/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,31 @@ class Attribute
size_t length;
void* value;
public:
Attribute()
{
key = "";
length = 0;
value = NULL;
}
Attribute(BinaryAttributeStructure bin, void* value) {
key = "";
for (int i = 0; i < ATTRIB_KEY_SIZE; i++)
key += bin.key[i];
length = bin.length;
this->value = value;
}

Attribute(string key, size_t length, void* value)
{
this->key = key;
this->length = length;
this->value = value;
}
Attribute(const Attribute& toCopy)
{
this->key = string(toCopy.key);
this->length = toCopy.length;
this->value = toCopy.value;
}

~Attribute() {

Expand Down
5 changes: 3 additions & 2 deletions bfs/include/DataSyncThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <iostream>
#include <ctime>

Expand Down Expand Up @@ -45,10 +46,10 @@ class DataSyncThread
// if this one is still running
bool threadRunning = false;

vector<Attribute> incomingAttributes;
map<string, Attribute> incomingAttributes;
HANDLE attribMutex;
public:
DataSyncThread(SOCKET s)
DataSyncThread(SOCKET s)
{
sock = s;
attribMutex = CreateMutex(NULL, false, NULL);
Expand Down
8 changes: 4 additions & 4 deletions bfs/src/comms/DataSyncThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void DataSyncThread::addIncomingAttribute(Attribute attrib)
{
DWORD result = WaitForSingleObject(attribMutex, INFINITE);
if (result == WAIT_OBJECT_0) {
incomingAttributes.push_back(attrib);
incomingAttributes[string(attrib.getKey())] = attrib;
ReleaseMutex(attribMutex);
}
else {
Expand Down Expand Up @@ -253,17 +253,17 @@ int DataSyncThread::connectToAlgorithm(char* serverName)
}
}

vector<Attribute> DataSyncThread::getIncomingAttributes()
vector<Attribute> DataSyncThread :: getIncomingAttributes()
{
vector<Attribute> newAttribVector;
if (! areIncomingAttributesAvailable())
return newAttribVector;

DWORD result = WaitForSingleObject(attribMutex, INFINITE);
if (result == WAIT_OBJECT_0) {
for (Attribute attrib : incomingAttributes)
for (auto attrib : incomingAttributes)
{
newAttribVector.push_back(attrib);
newAttribVector.push_back(attrib.second);
}
incomingAttributes.clear();
ReleaseMutex(attribMutex);
Expand Down

0 comments on commit 725a42a

Please sign in to comment.