├── LICENSE
├── README.md
└── th64.h
/LICENSE:
--------------------------------------------------------------------------------
1 | This software is available as a choice of the following licenses. Choose
2 | whichever you prefer.
3 |
4 | ===============================================================================
5 | ALTERNATIVE 1 - Public Domain (www.unlicense.org)
6 | ===============================================================================
7 | This is free and unencumbered software released into the public domain.
8 |
9 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
10 | software, either in source code form or as a compiled binary, for any purpose,
11 | commercial or non-commercial, and by any means.
12 |
13 | In jurisdictions that recognize copyright laws, the author or authors of this
14 | software dedicate any and all copyright interest in the software to the public
15 | domain. We make this dedication for the benefit of the public at large and to
16 | the detriment of our heirs and successors. We intend this dedication to be an
17 | overt act of relinquishment in perpetuity of all present and future rights to
18 | this software under copyright law.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 |
27 | For more information, please refer to
28 |
29 | ===============================================================================
30 | ALTERNATIVE 2 - MIT No Attribution
31 | ===============================================================================
32 | Copyright (c) 2024 Joshua J Baker (https://github.com/tidwall/th64)
33 |
34 | Permission is hereby granted, free of charge, to any person obtaining a copy of
35 | this software and associated documentation files (the "Software"), to deal in
36 | the Software without restriction, including without limitation the rights to
37 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 | of the Software, and to permit persons to whom the Software is furnished to do
39 | so.
40 |
41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47 | SOFTWARE.
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # th64
2 |
3 | A tiny hash function in C.
4 |
5 | Passes all tests in [SMhasher3](https://gitlab.com/fwojcik/smhasher3).
6 | It's fast for small keys at 43 cycles/hash (1-32 bytes) and fast for big keys too at 2.61 bytes/cycle (8.52 GiB/sec).
7 |
8 | ```c
9 | static uint64_t th64(const void *data, size_t len, uint64_t seed) {
10 | uint8_t*p=(uint8_t*)data,*e=p+len;
11 | uint64_t r=0x14020a57acced8b7,x,h=seed;
12 | while(p+8<=e)memcpy(&x,p,8),x*=r,p+=8,x=x<<31|x>>33,h=h*r^x,h=h<<31|h>>33;
13 | while(p>31,h*=r,h^=h>>31,h*=r,h^=h>>31,h*=r,h);
15 | }
16 | ```
17 |
18 | ## License
19 |
20 | Public domain or MIT-0, your choice.
21 |
--------------------------------------------------------------------------------
/th64.h:
--------------------------------------------------------------------------------
1 | // https://github.com/tidwall/th64
2 | //
3 | // Copyright (c) 2024 Joshua J Baker.
4 | // This software is available as a choice of Public Domain or MIT-0.
5 |
6 | #ifndef TH64_H
7 | #define TH64_H
8 |
9 | #include
10 | #include
11 |
12 | static uint64_t th64(const void *data, size_t len, uint64_t seed) {
13 | uint64_t r=0x14020a57acced8b7,x,h=seed;
14 | uint8_t *p=(uint8_t*)data,*e=p+len;
15 | while(p+8<=e)memcpy(&x,p,8),x*=r,p+=8,x=x<<31|x>>33,h=h*r^x,h=h<<31|h>>33;
16 | while(p>31,h*=r,h^=h>>31,h*=r,h^=h>>31,h*=r,h);
18 | }
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------