]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/hashfunc.h
tableprinter: code cleanup
[libucw.git] / ucw / hashfunc.h
index b2b03e941a3e1c139f7d8e2b4cb85aed3d63a928..8d198e1bd6e0cb875fd2aa69c59cb4988b5e4d29 100644 (file)
 
 /*** === String hashes [[strhash]] ***/
 
-/* The following functions need str to be aligned to sizeof(uns).  */
-uns str_len_aligned(const char *str) PURE; /** Get the string length (not a really useful hash function, but there is no better place for it). The string must be aligned to sizeof(uns). For unaligned see @str_len(). **/
-uns hash_string_aligned(const char *str) PURE; /** Hash the string. The string must be aligned to sizeof(uns). For unaligned see @hash_string(). **/
-uns hash_block_aligned(const byte *buf, uns len) PURE; /** Hash arbitrary data. They must be aligned to sizeof(uns). For unaligned see @hash_block(). **/
+/* The following functions need str to be aligned to sizeof(uint).  */
+uint str_len_aligned(const char *str) PURE; /** Get the string length (not a really useful hash function, but there is no better place for it). The string must be aligned to sizeof(uint). For unaligned see @str_len(). **/
+uint hash_string_aligned(const char *str) PURE; /** Hash the string. The string must be aligned to sizeof(uint). For unaligned see @hash_string(). **/
+uint hash_block_aligned(const byte *buf, uint len) PURE; /** Hash arbitrary data. They must be aligned to sizeof(uint). For unaligned see @hash_block(). **/
 
 #ifdef CPU_ALLOW_UNALIGNED
 #undef str_len
@@ -38,12 +38,12 @@ uns hash_block_aligned(const byte *buf, uns len) PURE; /** Hash arbitrary data.
 #define        hash_string(str)        hash_string_aligned(str)
 #define        hash_block(str, len)    hash_block_aligned(str, len)
 #else
-uns str_len(const char *str) PURE; /** Get the string length. If you know it is aligned to sizeof(uns), you can use faster @str_len_aligned(). **/
-uns hash_string(const char *str) PURE; /** Hash the string. If it is aligned to sizeof(uns), you can use faster @hash_string_aligned(). **/
-uns hash_block(const byte *buf, uns len) PURE; /** Hash arbitrary data. If they are aligned to sizeof(uns), use faster @hash_block_aligned(). **/
+uint str_len(const char *str) PURE; /** Get the string length. If you know it is aligned to sizeof(uint), you can use faster @str_len_aligned(). **/
+uint hash_string(const char *str) PURE; /** Hash the string. If it is aligned to sizeof(uint), you can use faster @hash_string_aligned(). **/
+uint hash_block(const byte *buf, uint len) PURE; /** Hash arbitrary data. If they are aligned to sizeof(uint), use faster @hash_block_aligned(). **/
 #endif
 
-uns hash_string_nocase(const char *str) PURE; /** Hash the string in a case insensitive way. Works only with ASCII characters. **/
+uint hash_string_nocase(const char *str) PURE; /** Hash the string in a case insensitive way. Works only with ASCII characters. **/
 
 /*** === Integer hashes [[inthash]] ***/
 
@@ -53,8 +53,8 @@ uns hash_string_nocase(const char *str) PURE; /** Hash the string in a case inse
  * of using shifts and adds on architectures where multiplication
  * instructions are slow).
  */
-static inline uns CONST hash_u32(uns x) { return 0x01008041*x; } /** Hash a 32 bit unsigned integer. **/
-static inline uns CONST hash_u64(u64 x) { return hash_u32((uns)x ^ (uns)(x >> 32)); } /** Hash a 64 bit unsigned integer. **/
-static inline uns CONST hash_pointer(void *x) { return ((sizeof(x) <= 4) ? hash_u32((uns)(uintptr_t)x) : hash_u64((u64)(uintptr_t)x)); } /** Hash a pointer. **/
+static inline uint CONST hash_u32(uint x) { return 0x01008041*x; } /** Hash a 32 bit unsigned integer. **/
+static inline uint CONST hash_u64(u64 x) { return hash_u32((uint)x ^ (uint)(x >> 32)); } /** Hash a 64 bit unsigned integer. **/
+static inline uint CONST hash_pointer(void *x) { return ((sizeof(x) <= 4) ? hash_u32((uint)(uintptr_t)x) : hash_u64((u64)(uintptr_t)x)); } /** Hash a pointer. **/
 
 #endif