summaryrefslogtreecommitdiff
path: root/include/qntan
diff options
context:
space:
mode:
Diffstat (limited to 'include/qntan')
-rw-r--r--include/qntan/Qntan.h52
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.