hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit fc502aa4aca5017d18609a2ccb44427c31922d0e
parent 66dab152148fa5536ba8b21af644c065f9dd7d94
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 19 Nov 2021 18:00:41 +0100

hash::fnv: add string32, string64

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mhash/fnv/fnv.ha | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/hash/fnv/fnv.ha b/hash/fnv/fnv.ha @@ -18,6 +18,20 @@ export type state64 = struct { v: u64, }; +// Hashes a string, returning a 32-bit key. +export fn string32(s: str) u32 = { + let hash = fnv32a(); + hash::write(&hash, strings::toutf8(s)); + return sum32(&hash); +}; + +// Hashes a string, returning a 64-bit key. +export fn string64(s: str) u64 = { + let hash = fnv64a(); + hash::write(&hash, strings::toutf8(s)); + return sum64(&hash); +}; + // Creates a [[hash::hash]] which computes the FNV-1 32-bit hash function. This // hash does not allocate any state, so you do not need to call [[hash::close]] // when you're done with it.