Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
javadsaberlatibari authored Mar 15, 2024
1 parent 84b10ba commit 7fd863e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 106 deletions.
2 changes: 1 addition & 1 deletion wellcoordination/benchmark/pnset-benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) {
count < expected_nonconflicting_write_calls_per_node; count++) {
std::string callStr;
// registerStudent
std::string s_id = std::to_string(std::rand() % 1000000);
std::string s_id = std::to_string(std::rand() % 100000);
if(std::rand() %2==0)
callStr = "0 " + s_id;
else
Expand Down
85 changes: 17 additions & 68 deletions wellcoordination/benchmark/pnset-crdt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class PNSet : public ReplicatedObject
QUERY = 2
};
std::recursive_mutex m;
int pnsetsource[200001][2]={{0}};
int pnsetremote[200001][2]={{0}};
int arraysizesource=0;
int arraysizeremote=0;
int pnsetsource[200001]={0};
int pnsetremote[200001]={0};
//int arraysizesource=0;
//int arraysizeremote=0;
int setsizesource=0;
int setsizeremote=0;
/// -------------------------------------------------------------
Expand All @@ -51,8 +51,8 @@ class PNSet : public ReplicatedObject
//state
std::memcpy(pnsetsource, obj.pnsetsource, sizeof(pnsetsource));
std::memcpy(pnsetremote, obj.pnsetremote, sizeof(pnsetremote));
arraysizesource= obj.arraysizesource;
arraysizeremote= obj.arraysizeremote;
//arraysizesource= obj.arraysizesource;
//arraysizeremote= obj.arraysizeremote;
setsizesource=obj.setsizesource;
setsizeremote=obj.setsizeremote;
///------------------------------------------------------------------------
Expand All @@ -78,42 +78,17 @@ class PNSet : public ReplicatedObject
}
std::string addDownstream(std::string a, bool b)
{
bool find= false;
//bool find= false;
//std::scoped_lock lock(m);
if (b==false){
find=false;
for(int i=0; i<arraysizesource; i++){
if(pnsetsource[i][0]==std::stoi(a)){
pnsetsource[i][1]++;
setsizesource++;
find=true;
break;
}
}
if(!find){
pnsetsource[arraysizesource][0]= std::stoi(a);
pnsetsource[arraysizesource][1]++;
arraysizesource++;
setsizesource++;
}
pnsetsource[std::stoi(a)]++;
setsizesource++;
//find=false;
//---------------------------------------------------
}
else{
find=false;
for(int i=0; i<arraysizeremote; i++){
if(pnsetremote[i][0]==std::stoi(a)){
pnsetremote[i][1]++;
setsizeremote++;
find=true;
break;
}
}
if(!find){
pnsetremote[arraysizeremote][0]= std::stoi(a);
pnsetremote[arraysizeremote][1]++;
arraysizeremote++;
setsizeremote++;
}
pnsetremote[std::stoi(a)]++;
setsizeremote++;

//---------------------------------------------------
}
Expand All @@ -122,42 +97,16 @@ class PNSet : public ReplicatedObject
std::string removeDownstream(std::string a, bool b)
{
//std::scoped_lock lock(m);
bool find= false;
//bool find= false;
//std::scoped_lock lock(m);
if (b==false){
find=false;
for(int i=0; i<arraysizesource; i++){
if(pnsetsource[i][0]==std::stoi(a)){
pnsetsource[i][1]--;
setsizesource--;
find=true;
break;
}
}
if(!find){
pnsetsource[arraysizesource][0]= std::stoi(a);
pnsetsource[arraysizesource][1]--;
arraysizesource++;
setsizesource--;
}
pnsetsource[std::stoi(a)]--;
setsizesource--;
//---------------------------------------------------
}
else{
find=false;
for(int i=0; i<arraysizeremote; i++){
if(pnsetremote[i][0]==std::stoi(a)){
pnsetremote[i][1]--;
setsizeremote--;
find=true;
break;
}
}
if(!find){
pnsetremote[arraysizeremote][0]= std::stoi(a);
pnsetremote[arraysizeremote][1]--;
arraysizeremote++;
setsizeremote--;
}
pnsetremote[std::stoi(a)]--;
setsizeremote--;

//---------------------------------------------------
}
Expand Down
50 changes: 13 additions & 37 deletions wellcoordination/benchmark/pnset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class PNSet : public ReplicatedObject
QUERY = 2
};
std::atomic<bool> lock;
int pnset[200001][2]={{0}};
int arraysize=0;
int pnset[200001]={0};
//int arraysize=0;
//int arraysize=0;
//int setsizesource=0;
int setsize=0;
Expand All @@ -50,7 +50,7 @@ class PNSet : public ReplicatedObject
{
//state
std::memcpy(pnset, obj.pnset, sizeof(pnset));
arraysize = obj.arraysize;
//arraysize = obj.arraysize;
setsize= obj.setsize;
//removeset = obj.removeset;
}
Expand All @@ -64,47 +64,23 @@ class PNSet : public ReplicatedObject
// 0
void add(std::string a)
{
bool find=false;

//bool find=false;
while(lock.load());
lock.store(true);
find=false;
for(int i=0; i<arraysize; i++){
if(pnset[i][0]==std::stoi(a)){
pnset[i][1]++;
setsize++;
find=true;
break;
}
}
if(!find){
pnset[arraysize][0]= std::stoi(a);
pnset[arraysize][1]++;
arraysize++;
setsize++;
}
pnset[std::stoi(a)]++;
setsize++;
lock.store(false);
}
void remove(std::string a)
{
bool find=false;
//bool find=false;
while(lock.load());
lock.store(true);
find=false;
for(int i=0; i<arraysize; i++){
if(pnset[i][0]==std::stoi(a)){
pnset[i][1]--;
setsize--;
find=true;
break;
}
}
if(!find){
pnset[arraysize][0]= std::stoi(a);
pnset[arraysize][1]--;
arraysize++;
setsize--;
}
lock.store(false);
//find=false;
pnset[std::stoi(a)]--;
setsize--;
lock.store(false);
}
// 1
PNSet query() { return *this; }
Expand Down Expand Up @@ -136,4 +112,4 @@ class PNSet : public ReplicatedObject
{
return true;
}
};
};

0 comments on commit 7fd863e

Please sign in to comment.