Sign in

    crc32

    MoonBit crc32: provide simple crc32 hash algorithm.

    crc32
    hash
    algorithm
    moonbit
    Download zip
    Author
    Version
    0.9.2
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    5K

    #gmlewis/crc32

    check

    This is a simple crc32 hash algorithm based on the Go Rosetta Stone implementation found here: https://rosettacode.org/wiki/CRC-32 which has the copyright notice:

    Content is available under GNU Free Document License 1.3 unless otherwise noted.

    #Status

    The code has been updated to support compiler:

    $ moon version --all moon 0.1.20261016 (1af328f 2026-10-16) ~/.moon/bin/moon moonc v0.10.16+b1a0e846e (2026-10-16) ~/.moon/bin/moonc moonrun 0.1.20261016 (1af328f 2026-10-16) ~/.moon/bin/moonrun

    HashFunc

    pub(open) trait HashFunc {
    fn name(Self) -> String
    fn reset(Self) -> Unit
    fn size(Self) -> Int
    fn write(Self, Byte) -> Unit
    fn check_sum(Self) -> String
    }

    HashFunc represents a hash algorithm like @crc32, @md5, or @sha256.

    A HashFunc can be injected into other packages as a trait object (&HashFunc), which lets a caller feed data to an algorithm it does not know statically, reuse that algorithm across inputs via reset, and identify it at runtime via name.

    Implementers in other packages should declare the promotion explicitly. Promoting a trait's methods to inherent methods is deprecated (moonc warns implicit_impl_as_method), so a foreign implementation also needs a declaration such as: pub extend MyDigest with @crc32.HashFunc::{name, reset, size, write, check_sum}

    Digest

    pub(all) struct Digest {
    crc : UInt
    name : String
    }

    @crc32.Digest implements the 32-bit cyclic redundancy check, or CRC-32, checksum. See https://en.wikipedia.org/wiki/Cyclic_redundancy_check for information. This package is based on the Go Rosetta Stone implementation found here: https://rosettacode.org/wiki/CRC-32
    impl HashFunc for Digest

    Digest::check_sum

    fn Digest::check_sum(self : Digest) -> String

    Digest::digest

    fn Digest::digest(self : Digest) -> UInt

    digest returns the final crc32 as a UInt.

    Digest::name

    fn Digest::name(self : Digest) -> String

    Digest::new

    fn Digest::new() -> Digest

    Digest::new returns a new, reset Digest, ready to sum.

    Digest::reset

    fn Digest::reset(self : Digest) -> Unit

    Digest::size

    fn Digest::size(_self : Digest) -> Int

    Digest::write

    fn Digest::write(self : Digest, b : Byte) -> Unit

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io