Module: Oselvar::Var::Core::Hash32
- Defined in:
- lib/oselvar/var/core/hash.rb
Overview
FNV-1a (32-bit) change-detector over UTF-16 code units. Not a security hash: tiny and byte-identical to the TS/Python/JVM ports so var.lock.json fingerprints match everywhere. The "fnv1a:" prefix namespaces the algorithm. Port of hash.ts.
Constant Summary collapse
- FNV_OFFSET =
0x811c9dc5- FNV_PRIME =
0x01000193- MASK =
0xffffffff
Class Method Summary collapse
Class Method Details
.hash_source(source) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/oselvar/var/core/hash.rb', line 17 def hash_source(source) h = FNV_OFFSET data = source.encode('UTF-16LE').bytes (0...data.length).step(2) do |i| unit = data[i] | (data[i + 1] << 8) h = ((h ^ unit) * FNV_PRIME) & MASK end format('fnv1a:%08x', h) end |