Browse Source

Add convenience function for hashing strings

master
Macoy Madson 9 months ago
parent
commit
b248c5e9ab
  1. 19
      src/Hash.cake

19
src/Hash.cake

@ -27,3 +27,22 @@
(at i (type-cast data (addr uint8_t))))
s-crc32-table)
(bit-shift->> (deref crc-out) 8)))))
(defun hash-crc32-string-null-terminated
(str (addr (const char))
&return uint32_t)
(unless (at 0 s-crc32-table)
(assert (and (at 0 s-crc32-table) "Need to call hash-crc32-initialize first"))
(return 0))
(unless str
(return 0))
(var result uint32_t 0)
(while (deref str)
(set result
(bit-xor
(at (bit-xor (type-cast result uint8_t)
(deref (type-cast str (addr uint8_t))))
s-crc32-table)
(bit-shift->> result 8)))
(incr str))
(return result))

Loading…
Cancel
Save