diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-20 18:35:30 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-20 18:35:30 +0300 |
commit | afdaddc4d0745a5bcefad73dd74fd4c03ae3de15 (patch) | |
tree | 83d86453410f1d88ee3ed0116ce90e730c99aa9e /src/fuzzy.h | |
parent | fb00c75abdfeaa15302a5922859e424b0313d5b5 (diff) | |
download | rspamd-afdaddc4d0745a5bcefad73dd74fd4c03ae3de15.tar.gz rspamd-afdaddc4d0745a5bcefad73dd74fd4c03ae3de15.zip |
* Add fuzzy hashes implementation (with adler-32 roll hash and FNV-32 hash)
* Add test case for fuzzy hashing check
Diffstat (limited to 'src/fuzzy.h')
-rw-r--r-- | src/fuzzy.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/fuzzy.h b/src/fuzzy.h new file mode 100644 index 000000000..91e6512c6 --- /dev/null +++ b/src/fuzzy.h @@ -0,0 +1,40 @@ +/** + * @file fuzzy.h + * Fuzzy hashes API + */ + +#ifndef RSPAMD_FUZZY_H +#define RSPAMD_FUZZY_H + +#include "config.h" +#include "mem_pool.h" +#include "fstring.h" + +#define FUZZY_HASHLEN 64 + +typedef struct fuzzy_hash_s { + char hash_pipe[FUZZY_HASHLEN]; /**< result hash */ + uint32_t block_size; /**< current blocksize */ + uint32_t rh; /**< roll hash value */ + uint32_t h; /**< hash of block */ + uint32_t hi; /**< current index in hash pipe */ +} fuzzy_hash_t; + +/** + * Calculate fuzzy hash for specified string + * @param in input string + * @param pool pool object + * @return fuzzy_hash object allocated in pool + */ +fuzzy_hash_t * fuzzy_init (f_str_t *in, memory_pool_t *pool); + +/** + * Compare score of difference between two hashes + * @param h1 first hash + * @param h2 second hash + * @return result in percents 0 - different hashes, 100 - identical hashes + */ +int fuzzy_compare_hashes (fuzzy_hash_t *h1, fuzzy_hash_t *h2); + + +#endif |