XU XUv0.8.8
中文

API

#hash/crc32

import: #hash/crc32

counts: 7 fns, 4 methods, 2 types, 3 consts, 0 ifaces

IEEE/Castagnoli/Koopman CRC-32.

const ieee

XuAPI
pub const ieee = 3988292384

Purpose

CRC-32 aligned with `hash/crc32` (ieee / castagnoli / koopman). Pure i64 arithmetic with 32-bit masks — no mutable globals (each make_table) returns an owning 256-entry table). checksum_ieee uses a precomputed ieee table so small checksums do not rebuild 256 entries from the poly. Value `3988292384`.

Parameters

none

const castagnoli

XuAPI
pub const castagnoli = 2197175160

Purpose

Public constant `castagnoli`. Value `2197175160`.

Parameters

none

const koopman

XuAPI
pub const koopman = 3945912366

Purpose

Public constant `koopman`. Value `3945912366`.

Parameters

none

struct Table

XuAPI
pub struct Table {
    pub entries []int
}

Purpose

Public struct `Table`.

Parameters

entries []int
field ([]int)

make_table

XuAPI
pub fn make_table(poly int) Table

Purpose

Make table.

Parameters

poly int
poly (int)

Returns

Table — a value of this type

update

XuAPI
pub fn update(tab &Table, crc int, data &string) int

Purpose

update; returns int.

Parameters

tab &Table
tab (borrowed; caller keeps it; type &Table)
crc int
crc (int)
data &string
data (borrowed; caller keeps it; type &string)

Returns

int — a value of this type

checksum

XuAPI
pub fn checksum(data &string, tab &Table) int

Purpose

checksum; returns int.

Parameters

data &string
data (borrowed; caller keeps it; type &string)
tab &Table
tab (borrowed; caller keeps it; type &Table)

Returns

int — a value of this type

struct Digest

XuAPI
pub struct Digest {
    pub tab Table
    pub crc int
    pub is_ieee bool
}

Purpose

Public struct `Digest`.

Parameters

tab Table
field (Table)
crc int
field (int)
is_ieee bool
field (bool)

new_ieee

XuAPI
pub fn new_ieee() Digest

Purpose

Construct ieee.

Parameters

none

Returns

Digest — a value of this type

(&mut Digest) write

XuAPI
pub fn (d &mut Digest) write(p &string) int

Purpose

Method on `&mut Digest`: write data and return the byte count.

Parameters

d &mut Digest
receiver &mut Digest (exclusive borrow)
p &string
p (borrowed; caller keeps it; type &string)

Returns

int — bytes written

(&Digest) sum

XuAPI
pub fn (d &Digest) sum() int

Purpose

Method on `&Digest`: compute a digest (often lowercase hex).

Parameters

d &Digest
receiver &Digest (borrow)

Returns

int — a value of this type

(&Digest) size

XuAPI
pub fn (d &Digest) size() int

Purpose

Method on `&Digest`: return the size.

Parameters

d &Digest
receiver &Digest (borrow)

Returns

int — a value of this type

(&mut Digest) reset

XuAPI
pub fn (d &mut Digest) reset()

Purpose

Method on `&mut Digest`: clear internal state so the value can be reused.

Parameters

d &mut Digest
receiver &mut Digest (exclusive borrow)

checksum_ieee

XuAPI
pub fn checksum_ieee(data &string) int

Purpose

Checksum ieee.

Parameters

data &string
data (borrowed; caller keeps it; type &string)

Returns

int — a value of this type

checksum_castagnoli

XuAPI
pub fn checksum_castagnoli(data &string) int

Purpose

Checksum castagnoli.

Parameters

data &string
data (borrowed; caller keeps it; type &string)

Returns

int — a value of this type

checksum_koopman

XuAPI
pub fn checksum_koopman(data &string) int

Purpose

Checksum koopman.

Parameters

data &string
data (borrowed; caller keeps it; type &string)

Returns

int — a value of this type