1 #ifndef _JELLYFISH_H_
2 #define _JELLYFISH_H_
3 
4 #include <stdlib.h>
5 
6 #if CJELLYFISH_PYTHON
7 #include <Python.h>
8 #define JFISH_UNICODE Py_UNICODE
9 #endif
10 
11 #ifndef MIN
12 #define MIN(a, b) ((a) < (b) ? (a) : (b))
13 #endif
14 
safe_malloc(size_t num,size_t size)15 static inline void* safe_malloc(size_t num, size_t size)
16 {
17     size_t alloc_size = num * size;
18     if (alloc_size / num != size)
19     {
20         return NULL;
21     }
22     return malloc(alloc_size);
23 }
24 
safe_matrix_malloc(size_t rows,size_t cols,size_t size)25 static inline void* safe_matrix_malloc(size_t rows, size_t cols, size_t size)
26 {
27     size_t matrix_size = rows * cols;
28     if (matrix_size / rows != cols)
29     {
30         return NULL;
31     }
32     return safe_malloc(matrix_size, size);
33 }
34 
35 double jaro_winkler_similarity(const JFISH_UNICODE *str1, int len1, const JFISH_UNICODE *str2, int len2, int long_tolerance);
36 double jaro_similarity(const JFISH_UNICODE *str1, int len1, const JFISH_UNICODE *str2, int len2);
37 
38 size_t hamming_distance(const JFISH_UNICODE *str1, int len1,
39         const JFISH_UNICODE *str2, int len2);
40 
41 int levenshtein_distance(const JFISH_UNICODE *str1, int len1, const JFISH_UNICODE *str2, int len2);
42 
43 int damerau_levenshtein_distance(const JFISH_UNICODE *str1, const JFISH_UNICODE *str2,
44         size_t len1, size_t len2);
45 
46 char* soundex(const char *str);
47 
48 char* metaphone(const char *str);
49 
50 JFISH_UNICODE *nysiis(const JFISH_UNICODE *str, int len);
51 
52 JFISH_UNICODE* match_rating_codex(const JFISH_UNICODE *str, size_t len);
53 int match_rating_comparison(const JFISH_UNICODE *str1, size_t len1, const JFISH_UNICODE *str2, size_t len2);
54 
55 struct stemmer;
56 extern struct stemmer * create_stemmer(void);
57 extern void free_stemmer(struct stemmer * z);
58 extern int stem(struct stemmer * z, JFISH_UNICODE * b, int k);
59 
60 #endif
61