Cthulhu  0.2.10
Cthulhu compiler collection
typeinfo.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #include "std/typeinfo.h"
4 
5 #include "base/util.h"
6 
7 #include "common.h"
8 
9 size_t info_ptr_hash(const void *key) { return ctu_ptrhash(key); }
10 bool info_ptr_equal(const void *lhs, const void *rhs) { return lhs == rhs; }
11 
12 size_t info_str_hash(const void *key) { return str_hash(key); }
13 
14 bool info_str_equal(const void *lhs, const void *rhs)
15 {
16  if (lhs == rhs) return true;
17  if (lhs == NULL || rhs == NULL) return false;
18 
19  return str_equal(lhs, rhs);
20 }
21 
22 size_t info_text_hash(const void *key)
23 {
24  text_view_t *view = (text_view_t*)key;
25  return text_hash(*view);
26 }
27 
28 bool info_text_equal(const void *lhs, const void *rhs)
29 {
30  text_view_t *l = (text_view_t*)lhs;
31  text_view_t *r = (text_view_t*)rhs;
32  return text_equal(*l, *r);
33 }
34 
36  .size = sizeof(char*),
37  .hash = info_str_hash,
38  .equals = info_str_equal,
39 };
40 
42  .size = sizeof(void*),
43  .hash = info_ptr_hash,
44  .equals = info_ptr_equal,
45 };
46 
48  .size = sizeof(text_view_t),
49  .hash = info_text_hash,
50  .equals = info_text_equal,
51 };
CT_NODISCARD CT_CONSTFN CT_BASE_API ctu_hash_t ctu_ptrhash(const void *ptr)
hash a pointer value
Definition: util.c:16
CT_NODISCARD CT_PUREFN CT_BASE_API ctu_hash_t text_hash(text_view_t text)
hash a string with a provided length
Definition: util.c:44
CT_NODISCARD CT_PUREFN CT_BASE_API bool str_equal(const char *lhs, const char *rhs)
compare strings equality
Definition: util.c:76
CT_PUREFN CT_BASE_API bool text_equal(text_view_t lhs, text_view_t rhs)
check if two text objects are equal
Definition: util.c:196
CT_NODISCARD CT_PUREFN CT_BASE_API ctu_hash_t str_hash(const char *str)
hash a string
Definition: util.c:29
const hash_info_t kTypeInfoString
type information for a c style string
Definition: typeinfo.c:35
const hash_info_t kTypeInfoPtr
type information for a generic pointer this operates on the pointer itself and not the data it points...
Definition: typeinfo.c:41
const hash_info_t kTypeInfoText
type information for a text_view_t
Definition: typeinfo.c:47
information for using a type in a hashset or hashmap
Definition: typeinfo.h:39
a non-owning view of text
Definition: text.h:24
bool info_ptr_equal(const void *lhs, const void *rhs)
Definition: typeinfo.c:10
bool info_str_equal(const void *lhs, const void *rhs)
Definition: typeinfo.c:14
size_t info_str_hash(const void *key)
Definition: typeinfo.c:12
size_t info_text_hash(const void *key)
Definition: typeinfo.c:22
size_t info_ptr_hash(const void *key)
Definition: typeinfo.c:9
bool info_text_equal(const void *lhs, const void *rhs)
Definition: typeinfo.c:28