]> source.dussan.org Git - rspamd.git/commitdiff
Add comparision function for shingles.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 17 Dec 2014 17:10:21 +0000 (17:10 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 17 Dec 2014 17:10:21 +0000 (17:10 +0000)
src/libutil/shingles.c
src/libutil/shingles.h

index 2307a318c662996895b2a81a48fdf7d5253c182c..653fa5356eeb2337ebd22c9635e15939f3c83388 100644 (file)
@@ -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;
+}
index 571199992ea2c8584049ba681fdd55b84bac7ecf..39e9cf38dd79a727c24e91a32d5f6b25640b1fe1 100644 (file)
@@ -57,6 +57,16 @@ struct rspamd_shingle* rspamd_shingles_generate (GArray *input,
                rspamd_shingles_filter filter,
                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
  */