In C++, hashing is exposed as methods — view.hash(seed = 0), view.bytesum(), and view.hash_multiseed(seeds, hashes) — and as the function object sz::hash{} together with sz::equal_to{}, which are convenient as template arguments for std::unordered_map/std::unordered_set. sz::fill_random(slice, nonce) fills a mutable span with reproducible noise.
#include <stringzilla/stringzilla.hpp>#include <unordered_map>#include <unordered_set>#include <cassert>namespace sz = ashvardanian::stringzilla;int main() { // Drop the SIMD hash and equality into the STL containers as template arguments. std::unordered_map<std::string, int, sz::hash, sz::equal_to> counts; for (char const *word : {"apple", "banana", "apple"}) counts[word] += 1; assert(counts["apple"] == 2); assert(counts.size() == 2); // `sz::string_t` keys also work in the plain containers, via the bundled `std::hash` specialization. std::unordered_set<sz::string_t> uniq = {"apple", "banana"}; assert(uniq.count("apple") == 1); sz::string_t noise(16, '\0'); sz::fill_random(noise.span(), /*nonce*/ 7); // reproducible noise assert(noise.size() == 16); return 0;}
API
Types
hashHelper function-like object to hash string-view convertible objects with StringZilla.
Similar to std::hash<std::string_view>, but doesn't require including the heavy <functional> header. Can be used to combine STL classes with StringZilla logic, like: std::unordered_map<std::string, int, sz::hash, sz::equal_to>.