Sha256: 4dc1a4e6f31a2f25d41fc7ee4ed2ae94563a090cdc77d7bbd972aa4098bd4f01

Contents?: true

Size: 479 Bytes

Versions: 36

Compression:

Stored size: 479 Bytes

Contents

//! This module provides a primitive hash function.

/// A primitive hash function for matching opcodes.
pub fn simple_hash(s: &str) -> usize {
    let mut h: u32 = 5381;
    for c in s.chars() {
        h = (h ^ c as u32).wrapping_add(h.rotate_right(6));
    }
    h as usize
}

#[cfg(test)]
mod tests {
    use super::simple_hash;

    #[test]
    fn basic() {
        assert_eq!(simple_hash("Hello"), 0x2fa70c01);
        assert_eq!(simple_hash("world"), 0x5b0c31d5);
    }
}

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
wasmtime-27.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.114.0/src/constant_hash.rs
wasmtime-26.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.113.0/src/constant_hash.rs
wasmtime-25.0.2 ./ext/cargo-vendor/cranelift-codegen-shared-0.112.2/src/constant_hash.rs
wasmtime-25.0.1 ./ext/cargo-vendor/cranelift-codegen-shared-0.112.1/src/constant_hash.rs
wasmtime-25.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.112.0/src/constant_hash.rs
wasmtime-24.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.111.0/src/constant_hash.rs
wasmtime-23.0.2 ./ext/cargo-vendor/cranelift-codegen-shared-0.110.2/src/constant_hash.rs
wasmtime-22.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.109.0/src/constant_hash.rs
wasmtime-21.0.1 ./ext/cargo-vendor/cranelift-codegen-shared-0.108.1/src/constant_hash.rs
wasmtime-20.0.2 ./ext/cargo-vendor/cranelift-codegen-shared-0.107.2/src/constant_hash.rs
wasmtime-20.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.107.2/src/constant_hash.rs
wasmtime-18.0.3 ./ext/cargo-vendor/cranelift-codegen-shared-0.105.3/src/constant_hash.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cranelift-codegen-shared-0.104.1/src/constant_hash.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.104.0/src/constant_hash.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.103.0/src/constant_hash.rs
wasmtime-15.0.1 ./ext/cargo-vendor/cranelift-codegen-shared-0.102.1/src/constant_hash.rs
wasmtime-15.0.0 ./ext/cargo-vendor/cranelift-codegen-shared-0.102.1/src/constant_hash.rs
wasmtime-14.0.4 ./ext/cargo-vendor/cranelift-codegen-shared-0.101.4/src/constant_hash.rs
wasmtime-14.0.3 ./ext/cargo-vendor/cranelift-codegen-shared-0.101.4/src/constant_hash.rs
wasmtime-14.0.1 ./ext/cargo-vendor/cranelift-codegen-shared-0.101.1/src/constant_hash.rs