hash

MoonBit hash: provide hash functions similar to Go.

hash
algorithm
moonbit
moon add gmlewis/hash@0.20.11
Download zip
Author
Version
0.20.11
License
Apache-2.0
Last updated
8 days ago
Downloads
25K

Dependencies

README

#gmlewis/hash

check

This package provides hash functions based on Go's implementation: https://cs.opensource.google/go/go/+/refs/tags/go1.23.3:src/hash/hash.go;l=26 which has the copyright notice:

// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.

#Status

The code has been updated to support compiler:

$ moon version --all moon 0.1.20260803 (c19f78e 2026-08-03) ~/.moon/bin/moon moonc v0.10.6+80dc50f24 (2026-08-04) ~/.moon/bin/moonc moonrun 0.1.20260803 (c19f78e 2026-08-03) ~/.moon/bin/moonrun

#
Hash

pub(open) trait Hash {
fn write(Self,
Slice
[Byte]) -> (Int,
IOError
?)
fn sum(Self,
Slice
[Byte]) ->
Slice
[Byte]
fn reset(Self) -> Unit
fn size(Self) -> Int
fn block_size(Self) -> Int
}

Hash is the common interface implemented by all hash functions.

Hash implementations in the standard library (e.g. [hash/crc32] and [crypto/sha256]) implement the [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] interfaces. Marshaling a hash implementation allows its internal state to be saved and used for additional processing later, without having to re-write the data previously written to the hash. The hash state may contain portions of the input in its original form, which users are expected to handle for any possible security implications.

Compatibility: Any future changes to hash or crypto packages will endeavor to maintain compatibility with state encoded using previous versions. That is, any released versions of the packages should be able to decode data written with any previously released version, subject to issues such as security fixes. See the Go compatibility document for background: https://golang.org/doc/go1compat

#
Hash32

pub(open) trait Hash32 {
fn sum32(Self) -> UInt
fn write(Self,
Slice
[Byte]) -> (Int,
IOError
?)
fn sum(Self,
Slice
[Byte]) ->
Slice
[Byte]
fn reset(Self) -> Unit
fn size(Self) -> Int
fn block_size(Self) -> Int
}

Hash32 is the common interface implemented by all 32-bit hash functions.

#
Hash64

pub(open) trait Hash64 {
fn sum64() -> UInt64
fn write(Self,
Slice
[Byte]) -> (Int,
IOError
?)
fn sum(Self,
Slice
[Byte]) ->
Slice
[Byte]
fn reset(Self) -> Unit
fn size(Self) -> Int
fn block_size(Self) -> Int
}

Hash64 is the common interface implemented by all 64-bit hash functions.

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io