hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 9565a773ac5d576c573a0891cdf374fae4cb9e83
parent 32e423860a9e40a27578dc1f9cbd46fbed521d6c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 21 Jun 2021 15:27:25 -0400

hash::crc*: style fixes

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mhash/crc16/crc16.ha | 26+++++++++++++-------------
Mhash/crc32/crc32.ha | 20++++++++++----------
Mhash/crc64/crc64.ha | 14+++++++-------
3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/hash/crc16/crc16.ha b/hash/crc16/crc16.ha @@ -8,20 +8,20 @@ export def SIZE: size = 2; // CRC-CCITT polynomial for CRC-16. The most commonly used polynomial, used in // Bluetooth, X.25, XMODEM, and many other places. Also known as CRC-X25. -export const CCITT: u16 = 0x8408; +export def CCITT: u16 = 0x8408; // CMDA200 polynomial for CRC-16. Used in the infrastructure of mobile networks. -export const CMDA2000: u16 = 0xE613; +export def CMDA2000: u16 = 0xE613; // DECT polynomial for CRC-16. Typically used in cordless phones. -export const DECT: u16 = 0x91A0; +export def DECT: u16 = 0x91A0; // ANSI polynomial for CRC-16. Another widely used polynomial, it's seen in USB // devices, Modbus, ANSI X3.28, and many others places. Also known as CRC-IBM. -export const ANSI: u16 = 0xA001; +export def ANSI: u16 = 0xA001; // Table of memoized values for each byte with the CCITT polynomial. -export const CCITT_TABLE: [256]u16 = [ +export const ccitt_table: [256]u16 = [ 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, @@ -54,7 +54,7 @@ export const CCITT_TABLE: [256]u16 = [ ]; // Table of memoized values for each byte with the CMDA2000 polynomial. -export const CMDA2000_TABLE: [256]u16 = [ +export const cmda2000_table: [256]u16 = [ 0x0000, 0x5A7A, 0xB4F4, 0xEE8E, 0xA5CF, 0xFFB5, 0x113B, 0x4B41, 0x87B9, 0xDDC3, 0x334D, 0x6937, 0x2276, 0x780C, 0x9682, 0xCCF8, 0xC355, 0x992F, 0x77A1, 0x2DDB, 0x669A, 0x3CE0, 0xD26E, 0x8814, 0x44EC, 0x1E96, 0xF018, @@ -88,7 +88,7 @@ export const CMDA2000_TABLE: [256]u16 = [ // Table of memoized values for each byte with the DECT polynomial. -export const DECT_TABLE: [256]u16 = [ +export const dect_table: [256]u16 = [ 0x0000, 0x49F3, 0x93E6, 0xDA15, 0x048D, 0x4D7E, 0x976B, 0xDE98, 0x091A, 0x40E9, 0x9AFC, 0xD30F, 0x0D97, 0x4464, 0x9E71, 0xD782, 0x1234, 0x5BC7, 0x81D2, 0xC821, 0x16B9, 0x5F4A, 0x855F, 0xCCAC, 0x1B2E, 0x52DD, 0x88C8, @@ -121,7 +121,7 @@ export const DECT_TABLE: [256]u16 = [ ]; // Table of memoized values for each byte with the ANSI polynomial. -export const ANSI_TABLE: [256]u16 = [ +export const ansi_table: [256]u16 = [ 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, @@ -180,7 +180,7 @@ type state = struct { // Creates a [[hash::hash]] which computes the CRC-16 algorithm. // // It takes a table of memoized values for a given polynomail (for example, -// [[CCITT_TABLE]], [[DECT_TABLE]], or [[ANSI_TABLE]]); a table for a +// [[ccitt_table]], [[dect_table]], or [[ansi_table]]); a table for a // custom polynomial, populated by [[memoize]] function, may also be used. export fn crc16(table: *[256]u16) *hash::hash = alloc(state { hash = hash::hash { @@ -237,16 +237,16 @@ export fn sum16(h: *hash::hash) u16 = { 0xB0E8, 0xFE1F, 0x4659, 0x5062), ]; - let crc_ccitt = crc16(&CCITT_TABLE); + let crc_ccitt = crc16(&ccitt_table); defer hash::close(crc_ccitt); - let crc_cmda2000 = crc16(&CMDA2000_TABLE); + let crc_cmda2000 = crc16(&cmda2000_table); defer hash::close(crc_cmda2000); - let crc_dect = crc16(&DECT_TABLE); + let crc_dect = crc16(&dect_table); defer hash::close(crc_dect); - let crc_ansi = crc16(&ANSI_TABLE); + let crc_ansi = crc16(&ansi_table); defer hash::close(crc_ansi); let buf: [SIZE]u8 = [0...]; diff --git a/hash/crc32/crc32.ha b/hash/crc32/crc32.ha @@ -8,19 +8,19 @@ export def SIZE: size = 4; // IEEE polynomial for CRC-32. Used in ethernet, SATA, MPEG-2, gzip, bzip2, // cksum, PNG, etc. It is by far the most common polynomial used. -export const IEEE: u32 = 0xedb88320; +export def IEEE: u32 = 0xedb88320; // Castagnoli polynomial for CRC-32. Used in iSCSI, SCTP, SSE4.2, btrfs, ext4, // and others. It's known to have better error detection than IEEE. -export const CASTAGNOLI: u32 = 0x82f63b78; +export def CASTAGNOLI: u32 = 0x82f63b78; // Koopman polnomial for CRC-32. It has good performance for small datasets, but // poor performance for large ones. Like the Castagnoli polynomial, it has // better error detection than the IEEE polynomial. -export const KOOPMAN: u32 = 0xeb31d82e; +export def KOOPMAN: u32 = 0xeb31d82e; // Table of memoized values for each byte with the IEEE polynomial. -export const IEEE_TABLE: [256]u32 = [ +export const ieee_table: [256]u32 = [ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, @@ -67,7 +67,7 @@ export const IEEE_TABLE: [256]u32 = [ ]; // Table of memoized values for each byte with the Castagnoli polynomial. -export const CASTAGNOLI_TABLE: [256]u32 = [ +export const castagnoli_table: [256]u32 = [ 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB, 0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24, 0x105EC76F, 0xE235446C, @@ -114,7 +114,7 @@ export const CASTAGNOLI_TABLE: [256]u32 = [ ]; // Table of memoized values for each byte with the Koopman polynomial. -export const KOOPMAN_TABLE: [256]u32 = [ +export const koopman_table: [256]u32 = [ 0x00000000, 0x9695C4CA, 0xFB4839C9, 0x6DDDFD03, 0x20F3C3CF, 0xB6660705, 0xDBBBFA06, 0x4D2E3ECC, 0x41E7879E, 0xD7724354, 0xBAAFBE57, 0x2C3A7A9D, 0x61144451, 0xF781809B, 0x9A5C7D98, 0x0CC9B952, 0x83CF0F3C, 0x155ACBF6, @@ -187,7 +187,7 @@ type state = struct { // Creates a [[hash::hash]] which computes the CRC-32 algorithm. // // It takes a table of memoized values for a given polynomail (for example, -// [[IEEE_TABLE]], [[CASTAGNOLI_TABLE]], or [[KOOPMAN_TABLE]]); a table for a +// [[ieee_table]], [[castagnoli_table]], or [[koopman_table]]); a table for a // custom polynomial, populated by [[memoize]] function, may also be used. export fn crc32(table: *[256]u32) *hash::hash = alloc(state { hash = hash::hash { @@ -243,13 +243,13 @@ export fn sum32(h: *hash::hash) u32 = { ("GNU's not UNIX", 224734747, 200511816, 332335539) ]; - let crc_ieee = crc32(&IEEE_TABLE); + let crc_ieee = crc32(&ieee_table); defer hash::close(crc_ieee); - let crc_castagnoli = crc32(&CASTAGNOLI_TABLE); + let crc_castagnoli = crc32(&castagnoli_table); defer hash::close(crc_castagnoli); - let crc_koopman = crc32(&KOOPMAN_TABLE); + let crc_koopman = crc32(&koopman_table); defer hash::close(crc_koopman); let buf: [SIZE]u8 = [0...]; diff --git a/hash/crc64/crc64.ha b/hash/crc64/crc64.ha @@ -7,13 +7,13 @@ use strings; export def SIZE: size = 8; // ECMA polynomial for CRC-64. Used in ECMA-182 and xz-utils. -export const ECMA: u64 = 0xC96C5795D7870F42; +export def ECMA: u64 = 0xC96C5795D7870F42; // ISO polynomial for CRC-64. Used in ISO 3309 (high-level data link controls). -export const ISO: u64 = 0xD800000000000000; +export def ISO: u64 = 0xD800000000000000; // Table of memoized values for each byte with the ECMA polynomial. -export const ECMA_TABLE: [256]u64 = [ +export const ecma_table: [256]u64 = [ 0x0000000000000000, 0xB32E4CBE03A75F6F, 0xF4843657A840A05B, 0x47AA7AE9ABE7FF34, 0x7BD0C384FF8F5E33, 0xC8FE8F3AFC28015C, 0x8F54F5D357CFFE68, 0x3C7AB96D5468A107, 0xF7A18709FF1EBC66, @@ -103,7 +103,7 @@ export const ECMA_TABLE: [256]u64 = [ ]; // Table of memoized values for each byte with the ISO polynomial. -export const ISO_TABLE: [256]u64 = [ +export const iso_table: [256]u64 = [ 0x0000000000000000, 0x01B0000000000000, 0x0360000000000000, 0x02D0000000000000, 0x06C0000000000000, 0x0770000000000000, 0x05A0000000000000, 0x0410000000000000, 0x0D80000000000000, @@ -219,7 +219,7 @@ type state = struct { // Creates a [[hash::hash]] which computes the CRC-64 algorithm. // // It takes a table of memoized values for a given polynomail (for example, -// [[ISO_TABLE]] or [[ECMA_TABLE]]); a table for a custom polynomial, populated +// [[iso_table]] or [[ecma_table]]); a table for a custom polynomial, populated // by [[memoize]] function, may also be used. export fn crc64(table: *[256]u64) *hash::hash = alloc(state { hash = hash::hash { @@ -274,10 +274,10 @@ export fn sum64(h: *hash::hash) u64 = { 0x7DFC4F7CE9552D23, 0xF71B429C925D99AE), ]; - let crc_ecma = crc64(&ECMA_TABLE); + let crc_ecma = crc64(&ecma_table); defer hash::close(crc_ecma); - let crc_iso = crc64(&ISO_TABLE); + let crc_iso = crc64(&iso_table); defer hash::close(crc_iso); let buf: [SIZE]u8 = [0...];