docs/Writerside/topics/hash_key.h.md

Sat, 25 Jan 2025 14:05:35 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 25 Jan 2025 14:05:35 +0100
branch
docs/3.1
changeset 1147
52802c36b261
parent 1145
1a8fe7b7dd8a
permissions
-rw-r--r--

fix minor bugs in hash_key.h and streams.h docs

relates to #451

1143
0559812df10c assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents: 1142
diff changeset
1 # Hash Function
1142
9437530176bc add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
2
1144
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
3 UCX implements the MurmurHash2 algorithm for computing hashes that are primarily used for [CxMap](map.h.md).
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
4 But it can be used for arbitrary custom scenarios, too.
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
5
1145
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
6 ## Overview
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
7 ```C
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
8 #include <cx/hash_key.h>
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
9
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
10 void cx_hash_murmur(CxHashKey *key);
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
11 CxHashKey cx_hash_key(const void *obj, size_t len);
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
12 CxHashKey cx_hash_key_str(const char *str);
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
13 CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len);
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
14 CxHashKey cx_hash_key_cxstr(cxstring str);
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
15 ```
1144
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
16
1145
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
17 ## Description
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
18
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
19 The primary function for creating a `CxHashKey` structure is `cx_hash_key()`.
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
20 The other functions do effectively the same, but
1144
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
21
1145
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
22 * `cx_hash_key_bytes()` is strongly typed if you want to avoid passing `void*`
1147
52802c36b261 fix minor bugs in hash_key.h and streams.h docs
Mike Becker <universe@uap-core.de>
parents: 1145
diff changeset
23 * `cx_hash_key_str()` conveniently takes a C string and computes the length
1145
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
24 * `cx_hash_key_cxstr()` conveniently takes a [UCX string](string.h.md)
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
25
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
26 In all cases, the hash will be available in the `hash` field of the returned structure.
1144
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
27
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
28 <note>
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
29 UCX assigns the hash value <code>1574210520</code> to the <code>NULL</code> pointer.
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
30 This is a careful choice which is not standard MurmurHash2 and an extension to support <code>NULL</code> pointers.
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
31 </note>
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
32
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
33 If you want to create a hash completely manually,
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
34 you can initialize the `data` and `len` members of `CxHashKey`
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
35 and call `cx_hash_murmur()`.
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
36 It is _not_ recommended to do so.
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
37
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
38 Example that is equivalent to `CxHashKey key = cx_hash_str(mystring)`
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
39 ```C
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
40 CxHashKey key;
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
41 key.data = mystring;
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
42 key.len = strlen(mystring);
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
43 cx_hash_murmur(&key);
b23d07fff6ca documentation of hash_key.h
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
44 ```
1145
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
45
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
46 <seealso>
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
47 <category ref="apidoc">
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
48 <a href="https://ucx.sourceforge.io/api/hash__key_8h.html">hash_key.h</a>
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
49 </category>
1a8fe7b7dd8a add stream.h docs and reworks hash_key.h docs
Mike Becker <universe@uap-core.de>
parents: 1144
diff changeset
50 </seealso>

mercurial