NDEVR
API Documentation
HashMaker.h
1#pragma once
2#include <NDEVR/BaseValues.h>
3#include <NDEVR/String.h>
4namespace NDEVR
5{
10 {
11 public:
16 template<class t_type>
17 void hash(const t_type& value)
18 {
19 hashMemory(&value, sizeof(value));
20 }
21
25 void hash(const String& s)
26 {
27 hashMemory(s.begin(), s.size());
28 }
29
33 void hash(const StringView& value)
34 {
35 hashMemory(value.begin(), value.size());
36 }
37
41 void hash(const char* value)
42 {
43 hashMemory(value, String::str_len(value));
44 }
45
49 template<class t_type>
50 void hash(const Buffer<t_type>& value)
51 {
52 for(uint04 i = 0; i < value.size(); i++)
53 hash(value[i]);
54 }
55
59 uint08 hashValue() const { return m_hash_value; }
60 private:
66 void hashMemory(const void* data, std::size_t size)
67 {
68 const uint01* bytes = static_cast<const uint01*>(data);
69
70 // Use a simple combining hash (FNV-like)
71 for (std::size_t i = 0; i < size; ++i) {
72 m_hash_value ^= static_cast<uint08>(bytes[i]);
73 m_hash_value *= 0x100000001B3; // FNV prime
74 }
75 }
76 private:
77 uint08 m_hash_value = 0;
78 };
79}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Computes hash values from arbitrary data using an FNV-like combining algorithm.
Definition HashMaker.h:10
void hash(const StringView &value)
Hashes a StringView by hashing its character data.
Definition HashMaker.h:33
void hash(const String &s)
Hashes a String by hashing its character data.
Definition HashMaker.h:25
void hash(const char *value)
Hashes a null-terminated C string by hashing its character data.
Definition HashMaker.h:41
uint08 hashValue() const
Returns the current accumulated hash value.
Definition HashMaker.h:59
void hash(const Buffer< t_type > &value)
Hashes each element of a Buffer sequentially.
Definition HashMaker.h:50
void hash(const t_type &value)
Hashes an arbitrary value by hashing its raw memory representation.
Definition HashMaker.h:17
The core String View class for the NDEVR API.
Definition StringView.h:58
constexpr const char * begin() const
Returns a pointer to the beginning of the string data.
Definition StringView.h:640
constexpr uint04 size() const
Returns the byte size of this string view.
Definition StringView.h:435
The core String class for the NDEVR API.
Definition String.h:95
static constexpr uint04 str_len(const char *value)
constexpr method to get the length of a null-terminated string at compile time
Definition String.h:989
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...