Skip to content

stdlib/hashView source ↗

hash

11 items · generated by scribe fromstdlib/hash.fd· synced 2026-11-15

stdlib/hash11 items

Contents

hash_str

FNV-1a hash of a string. 32-bit (avoids i64 overflow). Fast, good distribution, widely used for hash tables.

Example: assert_eq(hash_str(""), 2166136261); assert_eq(hash_str(“a”), 3826002220); assert(hash_str(“abc”) != hash_str(“abd”));

pub fn hash_str(s: str) -> i64 {

Parameters:

  • s: str

Returns: i64

Defined at line 22


hash_bytes

FNV-1a hash of a Vec of bytes.

Example: var b: Vec= Vec::new(); b.push(97); assert_eq(hash_bytes(b), hash_str(“a”));

pub fn hash_bytes(bytes: Vec<i64>) -> i64 {

Parameters:

  • bytes: Vec<i64>

Returns: i64

Defined at line 41


hash_i64

FNV-1a hash of an i64.

Example: assert_eq(hash_i64(42), hash_i64(42)); assert(hash_i64(1) != hash_i64(2));

pub fn hash_i64(n: i64) -> i64 {

Parameters:

  • n: i64

Returns: i64

Defined at line 57


hash_combine

Combine two hash values (for hashing tuples/structs). Simple XOR-based combine to avoid overflow.

Example: var h = hash_combine(hash_str(“x”), hash_i64(7)); assert_eq(h, hash_combine(hash_str(“x”), hash_i64(7)));

pub fn hash_combine(a: i64, b: i64) -> i64 {

Parameters:

  • a: i64
  • b: i64

Returns: i64

Defined at line 76


hash_vec

Hash a Vec of i64 values by combining their hashes.

Example: var a: Vec= Vec::new(); a.push(1); a.push(2); var b: Vec= Vec::new(); b.push(1); b.push(2); assert_eq(hash_vec(a), hash_vec(b));

pub fn hash_vec(v: Vec<i64>) -> i64 {

Parameters:

  • v: Vec<i64>

Returns: i64

Defined at line 88


hash_djb2

DJB2 hash of a string. Simple, fast, good for small hash tables.

Example: assert_eq(hash_djb2(""), 5381); assert_eq(hash_djb2(“a”), 177670);

pub fn hash_djb2(s: str) -> i64 {

Parameters:

  • s: str

Returns: i64

Defined at line 105


hash_djb2_bytes

DJB2 hash of a Vec of bytes.

Example: var b: Vec= Vec::new(); b.push(97); assert_eq(hash_djb2_bytes(b), hash_djb2(“a”));

pub fn hash_djb2_bytes(bytes: Vec<i64>) -> i64 {

Parameters:

  • bytes: Vec<i64>

Returns: i64

Defined at line 121


hash_checksum

Simple sum checksum of a Vec of bytes. NOT a real checksum.

Example: var b: Vec= Vec::new(); b.push(1); b.push(2); b.push(3); assert_eq(hash_checksum(b), 6);

pub fn hash_checksum(bytes: Vec<i64>) -> i64 {

Parameters:

  • bytes: Vec<i64>

Returns: i64

Defined at line 139


hash_xor_checksum

XOR checksum of a Vec of bytes.

Example: var b: Vec= Vec::new(); b.push(15); b.push(3); assert_eq(hash_xor_checksum(b), 12);

pub fn hash_xor_checksum(bytes: Vec<i64>) -> i64 {

Parameters:

  • bytes: Vec<i64>

Returns: i64

Defined at line 155


hash_crc32

CRC32 checksum of a Vec of bytes. Uses the standard CRC-32 polynomial (0xEDB88320).

Example: var b: Vec= Vec::new(); b.push(97); assert_eq(hash_crc32(b), 3904355907);

pub fn hash_crc32(bytes: Vec<i64>) -> i64 {

Parameters:

  • bytes: Vec<i64>

Returns: i64

Defined at line 174


hash_crc32_str

CRC32 checksum of a string.

Example: var c = hash_crc32_str(“123456789”); println(int_to_str(c)); assert_eq(c, 3421780262);

pub fn hash_crc32_str(s: str) -> i64 {

Parameters:

  • s: str

Returns: i64

Defined at line 199


Generated by scribe, the Fides documentation generator