Skip to content

Instantly share code, notes, and snippets.

@carrotIndustries
Created August 4, 2020 23:00
Show Gist options
  • Save carrotIndustries/947c1e0e663859de5f03c277463a24e5 to your computer and use it in GitHub Desktop.
Save carrotIndustries/947c1e0e663859de5f03c277463a24e5 to your computer and use it in GitHub Desktop.
//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;
}
#include "uuid.hpp"
#include <cstring>
namespace horizon {
UUID::UUID()
{
memset(uu, 0, sizeof(uu));
uu[15] = 0xff;
}
}; // namespace horizon
#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