diff options
| author | hiddenalpha.ch | 2026-10-10 22:39:28 +0200 |
|---|---|---|
| committer | hiddenalpha.ch | 2026-10-10 22:39:28 +0200 |
| commit | 5f228dfea9cf1da47a75b835a45a281c1c1df364 (patch) | |
| tree | c94e080f34f3dc9e0907c8fe8d7326710d4ff491 /include/qntan | |
| parent | ff75445dac3a75bb77e7291b07a2c61fb7c3d128 (diff) | |
| download | Qntan-5f228dfea9cf1da47a75b835a45a281c1c1df364.tar.gz Qntan-5f228dfea9cf1da47a75b835a45a281c1c1df364.zip | |
Define Qntan_Hasher
Diffstat (limited to 'include/qntan')
| -rw-r--r-- | include/qntan/Qntan.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/include/qntan/Qntan.h b/include/qntan/Qntan.h index 09c0ed5..1848984 100644 --- a/include/qntan/Qntan.h +++ b/include/qntan/Qntan.h @@ -75,6 +75,7 @@ struct Qntan_FileSystem_Dirent; struct Qntan_FileSystem; struct Qntan_FourierTransform; struct Qntan_Process; +struct Qntan_Hasher; struct Qntan_HshIdx; struct Qntan_HshTbl; struct Qntan_HshTbl_Cursor; @@ -975,6 +976,57 @@ struct Qntan_Process { +struct Qntan_Hasher { + /* Genetic hash abstraction. Could be SHA1, SHA256, MD5, whatever + * your UseCase needs. Usually the one requesting an implementation + * of this interface specifies what hash should be given. + */ + void (*reset)( struct Qntan_Hasher**, + void(*onDone)(int err,Qntan_Cls arg), Qntan_Cls arg ); + /* Resets the internal hashing state so the next call to `add()` + * will be as the 1st chunk of data of the data-to-be hashed. + * `err` is zero if OK, or negative on error. Positive values are + * reserved. + */ + void (*add)( struct Qntan_Hasher**, char const*buf, int buf_len, + void(*onDone)(int err,Qntan_Cls arg), Qntan_Cls arg ); + /* Append (some also say "update") more data to the current hash + * calculation. + * Caller MUST ensure `buf` stays valid until `onDone()` gets called. + * `err` is zero if OK, or negative on error. Positive values are + * reserved. + * The implementation is free when to call `onDone`. For very + * lightweight hashes this could be even from the same thread + * directly. For more CPU intensive hashes, an impl should offload + * the work to a worker thread. But still it can decide to call + * `onDone` early, that means if the buffer got copied away and + * queued to a worker thead somewhere else. Or it also could + * callbacl only as soon the worker thead already did process the + * given input. The only thing is (as always) that `onDone()` + * should be called on the EventLoop, NOT from some other worker + * thread! + */ + void (*finalize)( struct Qntan_Hasher**, + void(*onDone)(int err, char const*result, Qntan_Cls arg), + Qntan_Cls arg ); + /* Finalize (for example process remaining/buffered data etc) and then get + * the result hash back. + * `err` is negative on error. Positive values indicate how many + * octets the `result` is in length (num octets). + * `result` is the !!BINARY-REPRESENTATION!! of the hash result! (NOT + * STRING, NOT HEX, or any shit like that!). + */ +}; + + + + + + + + + + struct Qntan_HshIdx { /* An n-dimensional HashTable. Where as many properties as wanted * can be used to index into the table. |
