-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #155 Signed-off-by: GitHub <[email protected]>
- Loading branch information
Showing
34 changed files
with
239 additions
and
238 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,9 +47,9 @@ If you are interested, please contact us at [email protected] or contribute to | |
| :heavy_check_mark: | Add Benchmark for all algorithms | Oct 5, 2022 | | ||
| :heavy_check_mark: | Code Optimization | Oct 5, 2022 | | ||
| :heavy_check_mark: | Release 0.4.0 | Oct 7, 2022 | | ||
| :memo: | "Const" Code Review [#155](https://github.com/ZigRazor/CXXGraph/issues/155) | TBD | | ||
| :heavy_check_mark: | "Const" Code Review [#155](https://github.com/ZigRazor/CXXGraph/issues/155) | Mar 23, 2023 | | ||
| :memo: | Release 0.5.0 | TBD | | ||
| :memo: | Test on Partition Algorithm [#264](https://github.com/ZigRazor/CXXGraph/issues/264) | TBD | | ||
| :grey_exclamation: | Test on Partition Algorithm [#264](https://github.com/ZigRazor/CXXGraph/issues/264) | Mar 21, 2023 | | ||
| :heavy_check_mark: | Bug Resolution [#263](https://github.com/ZigRazor/CXXGraph/issues/263) | Mar 21, 2023 | | ||
| :memo: | General Performance Optimization [#262](https://github.com/ZigRazor/CXXGraph/issues/262) [#265](https://github.com/ZigRazor/CXXGraph/issues/265) | TBD | | ||
| :memo: | Reduction of Code Issue of Static Analysis | TBD | | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,128 +9,114 @@ | |
/*** Header-Only C++ Library for Graph ***/ | ||
/*** Representation and Algorithms ***/ | ||
/***********************************************************/ | ||
/*** Author: ZigRazor ***/ | ||
/*** Author: ZigRazor ***/ | ||
/*** E-Mail: [email protected] ***/ | ||
/***********************************************************/ | ||
/*** Collaboration: ----------- ***/ | ||
/***********************************************************/ | ||
/*** License: AGPL v3.0 ***/ | ||
/*** License: AGPL v3.0 ***/ | ||
/***********************************************************/ | ||
|
||
|
||
#ifndef __CXXGRAPH_NODE_H__ | ||
#define __CXXGRAPH_NODE_H__ | ||
|
||
#pragma once | ||
#include <iostream> | ||
#include <openssl/sha.h> | ||
#include <iomanip> | ||
|
||
|
||
namespace CXXGRAPH | ||
{ | ||
template <typename T> | ||
class Node; | ||
template <typename T> | ||
std::ostream &operator<<(std::ostream &os, const Node<T> &node); | ||
template <typename T> | ||
class Node | ||
{ | ||
private: | ||
std::size_t id = 0; | ||
std::string userId = ""; | ||
T data; | ||
void setId(std::string_view); | ||
|
||
public: | ||
Node(std::string_view, const T &data); | ||
~Node() = default; | ||
const std::size_t &getId() const; | ||
const std::string &getUserId() const; | ||
const T &getData() const; | ||
//operator | ||
bool operator==(const Node<T> &b) const; | ||
bool operator<(const Node<T> &b) const; | ||
friend std::ostream &operator<<<>(std::ostream &os, const Node<T> &node); | ||
}; | ||
|
||
template <typename T> | ||
Node<T>::Node(std::string_view id, const T &data) | ||
{ | ||
this->userId = id; | ||
// the userid is set as sha512 hash of the user provided id | ||
setId(id); | ||
this->data = data; | ||
} | ||
#include <iomanip> | ||
#include <iostream> | ||
|
||
template <typename T> | ||
void Node<T>::setId(std::string_view inpId) | ||
{ | ||
//const unsigned char* userId = reinterpret_cast<const unsigned char *>((*inpId).c_str() ); | ||
//unsigned char obuf[64]; | ||
//unsigned long long obuf[8]; | ||
//SHA512(userId, (*inpId).length(), reinterpret_cast<unsigned char*>(obuf)); | ||
/** | ||
// Transform byte-array to string | ||
std::stringstream shastr; | ||
shastr << std::hex << std::setfill('0'); | ||
int i = 0; | ||
//unsigned long can only store 8 bytes so we truncate the hash to 8 bytes | ||
for (const auto &byte: obuf) | ||
{ | ||
shastr << std::setw(2) << static_cast<int>(byte); | ||
i++; | ||
if (i==8) break; | ||
} | ||
auto idStr = shastr.str(); | ||
// convert hex string to unsigned long long | ||
std::istringstream iss(idStr); | ||
iss >> std::hex >> this->id; | ||
**/ | ||
this->id = std::hash<std::string_view>{}(inpId); | ||
|
||
} | ||
namespace CXXGRAPH { | ||
template <typename T> | ||
class Node; | ||
template <typename T> | ||
std::ostream &operator<<(std::ostream &os, const Node<T> &node); | ||
template <typename T> | ||
class Node { | ||
private: | ||
std::size_t id = 0; | ||
std::string userId = ""; | ||
T data; | ||
void setId(const std::string &); | ||
|
||
public: | ||
Node(const std::string &, const T &data); | ||
~Node() = default; | ||
const std::size_t &getId() const; | ||
const std::string &getUserId() const; | ||
const T &getData() const; | ||
// operator | ||
bool operator==(const Node<T> &b) const; | ||
bool operator<(const Node<T> &b) const; | ||
friend std::ostream &operator<< <>(std::ostream &os, const Node<T> &node); | ||
}; | ||
|
||
template <typename T> | ||
Node<T>::Node(const std::string &id, const T &data) { | ||
this->userId = id; | ||
// the userid is set as sha512 hash of the user provided id | ||
setId(id); | ||
this->data = data; | ||
} | ||
|
||
template <typename T> | ||
const std::size_t &Node<T>::getId() const | ||
{ | ||
return id; | ||
} | ||
template <typename T> | ||
void Node<T>::setId(const std::string &inpId) { | ||
// const unsigned char* userId = reinterpret_cast<const unsigned char | ||
// *>((*inpId).c_str() ); unsigned char obuf[64]; unsigned long long obuf[8]; | ||
// SHA512(userId, (*inpId).length(), reinterpret_cast<unsigned char*>(obuf)); | ||
/** | ||
// Transform byte-array to string | ||
std::stringstream shastr; | ||
shastr << std::hex << std::setfill('0'); | ||
int i = 0; | ||
//unsigned long can only store 8 bytes so we truncate the hash to 8 bytes | ||
for (const auto &byte: obuf) | ||
{ | ||
shastr << std::setw(2) << static_cast<int>(byte); | ||
i++; | ||
if (i==8) break; | ||
} | ||
auto idStr = shastr.str(); | ||
// convert hex string to unsigned long long | ||
std::istringstream iss(idStr); | ||
iss >> std::hex >> this->id; | ||
**/ | ||
this->id = std::hash<std::string>{}(inpId); | ||
} | ||
|
||
template <typename T> | ||
const std::string &Node<T>::getUserId() const | ||
{ | ||
return userId; | ||
} | ||
template <typename T> | ||
const std::size_t &Node<T>::getId() const { | ||
return id; | ||
} | ||
|
||
template <typename T> | ||
const T &Node<T>::getData() const | ||
{ | ||
return data; | ||
} | ||
template <typename T> | ||
const std::string &Node<T>::getUserId() const { | ||
return userId; | ||
} | ||
|
||
template <typename T> | ||
bool Node<T>::operator==(const Node<T> &b) const | ||
{ | ||
return (this->id == b.id && this->data == b.data); | ||
} | ||
template <typename T> | ||
const T &Node<T>::getData() const { | ||
return data; | ||
} | ||
|
||
template <typename T> | ||
bool Node<T>::operator<(const Node<T> &b) const | ||
{ | ||
return (this->id < b.id); | ||
} | ||
template <typename T> | ||
bool Node<T>::operator==(const Node<T> &b) const { | ||
return (this->id == b.id && this->data == b.data); | ||
} | ||
|
||
template <typename T> | ||
bool Node<T>::operator<(const Node<T> &b) const { | ||
return (this->id < b.id); | ||
} | ||
|
||
//ostream overload | ||
template <typename T> | ||
std::ostream &operator<<(std::ostream &os, const Node<T> &node) | ||
{ | ||
os << "Node: {\n" | ||
<< " Id:\t" << node.userId << "\n Data:\t" << node.data << "\n}"; | ||
return os; | ||
} | ||
// ostream overload | ||
template <typename T> | ||
std::ostream &operator<<(std::ostream &os, const Node<T> &node) { | ||
os << "Node: {\n" | ||
<< " Id:\t" << node.userId << "\n Data:\t" << node.data << "\n}"; | ||
return os; | ||
} | ||
} // namespace CXXGRAPH | ||
|
||
#endif // __CXXGRAPH_NODE_H__ | ||
#endif // __CXXGRAPH_NODE_H__ |
Oops, something went wrong.