aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-12-17 17:10:21 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-12-17 17:10:21 +0000
commitc63bee1078c6b8370aadaa73f0bb5f2333fd78cf (patch)
tree06e7d5c41ab6b1fc3792f0dfc3cd60cb41b0d227
parent30e37db22654d400f2ac2f9d89e89678a7782131 (diff)
downloadrspamd-c63bee1078c6b8370aadaa73f0bb5f2333fd78cf.tar.gz
rspamd-c63bee1078c6b8370aadaa73f0bb5f2333fd78cf.zip
Add comparision function for shingles.
-rw-r--r--src/libutil/shingles.c15
-rw-r--r--src/libutil/shingles.h10
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c
index 2307a318c..653fa5356 100644
--- a/src/libutil/shingles.c
+++ b/src/libutil/shingles.c
@@ -135,3 +135,18 @@ rspamd_shingles_default_filter (guint64 *input, gsize count,
return minimal;
}
+
+
+gdouble rspamd_shingles_compare (const struct rspamd_shingle *a,
+ const struct rspamd_shingle *b)
+{
+ gint i, common = 0;
+
+ for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) {
+ if (a->hashes[i] == b->hashes[i]) {
+ common ++;
+ }
+ }
+
+ return (gdouble)common / 84.0;
+}
diff --git a/src/libutil/shingles.h b/src/libutil/shingles.h
index 571199992..39e9cf38d 100644
--- a/src/libutil/shingles.h
+++ b/src/libutil/shingles.h
@@ -58,6 +58,16 @@ struct rspamd_shingle* rspamd_shingles_generate (GArray *input,
gpointer filterd);
/**
+ * Compares two shingles and return result as a floating point value - 1.0
+ * for completely similar shingles and 0.0 for completely different ones
+ * @param a
+ * @param b
+ * @return
+ */
+gdouble rspamd_shingles_compare (const struct rspamd_shingle *a,
+ const struct rspamd_shingle *b);
+
+/**
* Default filtering function
*/
guint64 rspamd_shingles_default_filter (guint64 *input, gsize count,