Created
August 4, 2020 23:00
-
-
Save carrotIndustries/947c1e0e663859de5f03c277463a24e5 to your computer and use it in GitHub Desktop.
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
//compile using g++ -std=c++17 main.cpp uuid.cpp -luuid -o utest -O3 | |
#include "uuid.hpp" | |
#include <iostream> | |
using namespace horizon; | |
int main(void) { | |
UUID r; | |
std::cout << r.hash() << std::endl; | |
for(int i = 0; i< 1; i++) { | |
std::cout << r.hash() << std::endl; | |
} | |
return 0; | |
} |
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
#include "uuid.hpp" | |
#include <cstring> | |
namespace horizon { | |
UUID::UUID() | |
{ | |
memset(uu, 0, sizeof(uu)); | |
uu[15] = 0xff; | |
} | |
}; // namespace horizon |
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
#pragma once | |
#include <cstddef> | |
namespace horizon { | |
class UUID { | |
public: | |
UUID(); | |
size_t hash() const | |
{ | |
size_t r = 0; | |
for (size_t i = 0; i < 16; i++) { | |
r ^= uu[i] << ((i % sizeof(size_t)) * 8); | |
} | |
return r; | |
} | |
private: | |
unsigned char uu[16]; | |
}; | |
} // namespace horizon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment