Skip to main content

Mojo trait

Hasher

A trait for types that can incrementally compute hash values.

The Hasher trait defines the interface for hash algorithms that can process data in chunks and produce a final hash value.

Implementers must provide methods to initialize the hasher, update it with data, and finalize the hash computation.

Implemented traits

AnyType

Required methods

__init__

__init__(out self: _Self)

Initialize a new hasher instance.

Returns:

_Self

update

update[T: Hashable](mut self: _Self, value: T)

Update the hash with a value.

Parameters:

  • T (Hashable): The type of value to hash, which must implement Hashable.

Args:

  • value (T): The value to incorporate into the hash.

finish

finish(var self: _Self) -> UInt64

Finalize the hash computation and return the hash value.

Returns:

UInt64: The computed hash value as a 64-bit unsigned integer.

Was this page helpful?