Skip to content

Commit

Permalink
passing edges through an unordered map first to remove dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorySchwing committed Aug 12, 2021
1 parent f24cf9c commit acd4bdc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
42 changes: 27 additions & 15 deletions simpleParallel/COO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,35 @@ void COO::BuildCOOFromFile(std::string filename){
for(auto& row: CSVRange(file, sep))
{
//std::cout << "adding (" << std::stoi(row[0],&sz)
//<< ", " << std::stoi(row[1],&sz) << ")" << std::endl;
addEdgeSymmetric(std::stoi(row[0],&sz),
//<< ", " << std::stoi(row[1],&sz) << ")" << std::endl;
addEdgeToMap(std::stoi(row[0],&sz),
std::stoi(row[1],&sz), 1);
//coordinateFormat->addEdgeSimple(std::stoi(row[0],&sz),
// std::stoi(row[1],&sz), 1);
}

for (auto & edge : um)
addEdgeSymmetric(edge.first.first, edge.first.second, 1);

size = new_values.size();
// vlog(e)
sortMyself();
}

void COO::BuildTheExampleCOO(){
addEdgeSymmetric(0,1,1);
addEdgeSymmetric(0,4,1);
addEdgeSymmetric(1,4,1);
addEdgeSymmetric(1,5,1);
addEdgeSymmetric(1,6,1);
addEdgeSymmetric(2,4,1);
addEdgeSymmetric(2,6,1);
addEdgeSymmetric(3,5,1);
addEdgeSymmetric(3,6,1);
addEdgeSymmetric(4,7,1);
addEdgeSymmetric(4,8,1);
addEdgeSymmetric(5,8,1);
addEdgeSymmetric(6,9,1);
addEdgeToMap(0,1,1);
addEdgeToMap(0,4,1);
addEdgeToMap(1,4,1);
addEdgeToMap(1,5,1);
addEdgeToMap(1,6,1);
addEdgeToMap(2,4,1);
addEdgeToMap(2,6,1);
addEdgeToMap(3,5,1);
addEdgeToMap(3,6,1);
addEdgeToMap(4,7,1);
addEdgeToMap(4,8,1);
addEdgeToMap(5,8,1);
addEdgeToMap(6,9,1);

size = new_values.size();
// vlog(e)
Expand Down Expand Up @@ -151,6 +154,15 @@ void COO::addEdgeASymmetric(int u, int v, int weight){
}


/* Works but the amount of data is 2x */
void COO::addEdgeToMap(int u, int v, int weight){
std::pair<int, int> in(u, v);
std::pair<int, int> out(v, u);

um[in] = true;
um[out] = true;
}

/* Works but the amount of data is 2x */
void COO::addEdgeSymmetric(int u, int v, int weight){
new_row_indices.push_back(u);
Expand Down
14 changes: 14 additions & 0 deletions simpleParallel/COO.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
#include "../common/CSVRange.h"
#include <iterator>
#include <algorithm> /* rand */
#include <unordered_map>

// A hash function used to hash a pair of any kind
struct hash_pair {
template <class T1, class T2>
size_t operator()(const std::pair<T1, T2>& p) const
{
auto hash1 = std::hash<T1>{}(p.first);
auto hash2 = std::hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};

class COO final : public SparseMatrix
{
Expand All @@ -29,6 +41,7 @@ class COO final : public SparseMatrix
void addEdgeSimple(int u, int v, int weight);
void addEdgeASymmetric(int u, int v, int weight);
void addEdgeSymmetric(int u, int v, int weight);
void addEdgeToMap(int u, int v, int weight);
int GetNumberOfVertices();
int GetNumberOfEdges();
void BuildTheExampleCOO();
Expand All @@ -39,6 +52,7 @@ class COO final : public SparseMatrix
int vertexCount;

private:
std::unordered_map<std::pair<int, int>, bool, hash_pair> um;
bool isSorted;
};
#endif

0 comments on commit acd4bdc

Please sign in to comment.