docs

core::hash

이 페이지의 내용

API 참조는 영어로만 있습니다. 표준 라이브러리 소스의 영어 문서 주석에서 만듭니다.

what a Hash impl writes to: Hasher, BuildHasher, the process-keyed RandomState that Dict and Set default to with its SipHash-1-3 DefaultHasher, and the caller-keyed SipHasher13 / SipHasher24, whose output is stable.

Structs

RandomStateSource

pub struct RandomState

The process's hash key, what Dict and Set use by default: drawn at random once per process, so where a key lands changes between runs (but not what a dict prints: that follows insertion order). Every RandomState::new() in a process holds the same key.

  • pub const fn new() -> RandomState§

    Source

    The process's keys: every RandomState of the process hashes alike.

Trait implementations 7

DefaultHasherSource

pub struct DefaultHasher

RandomState's hasher. The algorithm (SipHash-1-3 today) and so its output are unspecified and may change in any release: never persist it. SipHasher13 is the stable form.

Trait implementations 3
  • impl Hasher for DefaultHasher
  • impl Clone for DefaultHasher
  • impl Debug for DefaultHasher

SipHasher13Source

pub struct SipHasher13

SipHash-1-3 under a caller's key. Its output for the bytes written is the reference SipHash and stable across releases; write_<int> writes the integer's little-endian bytes (write_usize 8). The writes a Hash impl makes are not stable, so a persisted hash feeds bytes and integers directly, never x.hash(ref h).

  • pub const fn with_keys(k0: u64, k1: u64) -> SipHasher13§

    Source

    A hasher under the 128-bit key k0, k1.

Trait implementations 3

SipHasher24Source

pub struct SipHasher24

SipHash-2-4 under a caller's key: as SipHasher13, with the original paper's rounds.

  • pub const fn with_keys(k0: u64, k1: u64) -> SipHasher24§

    Source

    A hasher under the 128-bit key k0, k1.

Trait implementations 3

BuildHasherDefaultSource

pub struct BuildHasherDefault<H>

Builds H::default(): for a Dict / Set with a fixed hasher of the caller's (Dict<K, V, BuildHasherDefault<MyHasher>>). Use one only when keys cannot come from an attacker.

  • pub const fn new() -> BuildHasherDefault<H>§

    Source

    The builder; it holds nothing.

Trait implementations 5

Traits

HasherSource

pub trait Hasher

A running hash: Hash impls feed it bytes and integers, finish reads the result. Equal values must make the same sequence of writes; a variable-length run of values starts with write_length_prefix, so that ("ab", "c") and ("a", "bc") differ.

  • fn write<B: AsBytes>(ref self, bytes: B)§

    Source

    Raw bytes; adds no length or terminator.

  • fn finish(self) -> u64§

    Source

    The hash of everything written so far; the state is not reset.

  • const fn write_u8(ref self, x: u8)§

    Source

    x as one byte.

  • const fn write_u16(ref self, x: u16)§

    Source

    x as 2 little-endian bytes.

  • const fn write_u32(ref self, x: u32)§

    Source

    x as 4 little-endian bytes.

  • const fn write_u64(ref self, x: u64)§

    Source

    x as 8 little-endian bytes.

  • const fn write_usize(ref self, x: usize)§

    Source

    8 bytes on every target, so a hash does not depend on the width.

  • const fn write_i8(ref self, x: i8)§

    Source

    x as write_u8 of its bits.

  • const fn write_i16(ref self, x: i16)§

    Source

    x as write_u16 of its bits.

  • const fn write_i32(ref self, x: i32)§

    Source

    x as write_u32 of its bits.

  • const fn write_i64(ref self, x: i64)§

    Source

    x as write_u64 of its bits.

  • const fn write_isize(ref self, x: isize)§

    Source

    x as write_u64 of its bits, on every target.

  • const fn write_length_prefix(ref self, len: usize)§

    Source

    Before a variable-length run of Hash values (a list's items).

  • const fn write_str(ref self, s: str)§

    Source

    A whole str, prefix-free on its own: never precede it with write_length_prefix.

BuildHasherSource

pub trait BuildHasher

Makes the Hashers of a Dict / Set: every one it builds hashes equal values alike.