Added .hash() functions for vectors (#2043)

* Added .hash() functions for vectors
* Update test to a non-zero sized vector
* Changed vector hash functions to hash the underlying bytes in a char slice, the same approch is used for arrays
* Added test for hashed
* Updated formatting to be consistant with C3 code style
* Formatting, use "self"

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
Sander van den Bosch
2025-03-31 16:33:48 +02:00
committed by GitHub
parent 63e5aa58c5
commit 561a683230
2 changed files with 114 additions and 12 deletions

View File

@@ -63,17 +63,78 @@ fn void test_prefetch()
fn void test_hash()
{
(char){}.hash();
(char[<100>]){}.hash();
(char[100]){}.hash();
(ichar){}.hash();
(ichar[<100>]){}.hash();
(ichar[100]){}.hash();
(short){}.hash();
(short[<100>]){}.hash();
(short[100]){}.hash();
(ushort){}.hash();
(ushort[<100>]){}.hash();
(ushort[100]){}.hash();
(int){}.hash();
(int[<100>]){}.hash();
(int[100]){}.hash();
(uint){}.hash();
(uint[<100>]){}.hash();
(uint[100]){}.hash();
(long){}.hash();
(long[<100>]){}.hash();
(long[100]){}.hash();
(ulong){}.hash();
(ulong[<100>]){}.hash();
(ulong[100]){}.hash();
(int128){}.hash();
(int128[<100>]){}.hash();
(int128[100]){}.hash();
(uint128){}.hash();
(uint128[<100>]){}.hash();
(uint128[100]){}.hash();
(bool){}.hash();
(bool[<100>]){}.hash();
(bool[100]){}.hash();
String x = "abc";
char[] y = "abc";
assert(x.hash() == y.hash());
assert(int.typeid.hash());
}
}
fn void test_hash_repeat()
{
assert((char){}.hash() == (char){}.hash());
assert((char[<100>]){}.hash() == (char[<100>]){}.hash());
assert((char[100]){}.hash() == (char[100]){}.hash());
assert((ichar){}.hash() == (ichar){}.hash());
assert((ichar[<100>]){}.hash() == (ichar[<100>]){}.hash());
assert((ichar[100]){}.hash() == (ichar[100]){}.hash());
assert((short){}.hash() == (short){}.hash());
assert((short[<100>]){}.hash() == (short[<100>]){}.hash());
assert((short[100]){}.hash() == (short[100]){}.hash());
assert((ushort){}.hash() == (ushort){}.hash());
assert((ushort[<100>]){}.hash() == (ushort[<100>]){}.hash());
assert((ushort[100]){}.hash() == (ushort[100]){}.hash());
assert((int){}.hash() == (int){}.hash());
assert((int[<100>]){}.hash() == (int[<100>]){}.hash());
assert((int[100]){}.hash() == (int[100]){}.hash());
assert((uint){}.hash() == (uint){}.hash());
assert((uint[<100>]){}.hash() == (uint[<100>]){}.hash());
assert((uint[100]){}.hash() == (uint[100]){}.hash());
assert((long){}.hash() == (long){}.hash());
assert((long[<100>]){}.hash() == (long[<100>]){}.hash());
assert((long[100]){}.hash() == (long[100]){}.hash());
assert((ulong){}.hash() == (ulong){}.hash());
assert((ulong[<100>]){}.hash() == (ulong[<100>]){}.hash());
assert((ulong[100]){}.hash() == (ulong[100]){}.hash());
assert((int128){}.hash() == (int128){}.hash());
assert((int128[<100>]){}.hash() == (int128[<100>]){}.hash());
assert((int128[100]){}.hash() == (int128[100]){}.hash());
assert((uint128){}.hash() == (uint128){}.hash());
assert((uint128[<100>]){}.hash() == (uint128[<100>]){}.hash());
assert((uint128[100]){}.hash() == (uint128[100]){}.hash());
assert((bool){}.hash() == (bool){}.hash());
assert((bool[<100>]){}.hash() == (bool[<100>]){}.hash());
assert((bool[100]){}.hash() == (bool[100]){}.hash());
assert(int.typeid.hash() == int.typeid.hash());
}