1 #ifndef CGPERF_SEARCH_H
2 #define CGPERF_SEARCH_H
5 #include "keyword_list.h"
7 #include "bool-array.h"
8 /*------------------------------------------------------------------------------------------------*/
9 #include "namespace/search.h"
10 #include "namespace/keyword.h"
11 #include "namespace/keyword_list.h"
12 #include "namespace/positions.h"
13 #include "namespace/bool-array.h"
14 /* for the Search local types */
15 #include "namespace/search.c"
16 /*---------------------------i--------------------------------------------------------------------*/
20 struct Keyword_List
*head
;
21 /* total number of keywords, counting duplicates */
23 /* maximum length of the longest keyword */
25 /* minimum length of the shortest keyword */
27 /* whether the hash function includes the length */
28 bool hash_includes_len
;
29 /* user-specified or computed key positions */
30 struct Positions
*key_positions
;
31 /* adjustments to add to bytes add specific key positions */
33 /* size of alphabet */
36 * alphabet character unification, either the identity or a mapping from upper case
37 * characters to lower case characters (and maybe more)
40 /* maximum _selchars_length over all keywords */
41 u32 max_selchars_length
;
43 * total number of duplicates that have been moved to _duplicate_link lists (not counting
44 * their representatives which stay on the main list)
48 * Counts occurrences of each key set character. occurrences[c] is the number of times that
49 * c occurs among the _selchars of a keyword.
52 /* value associated with each character */
54 /*}}} public -- END */
56 /* maximal possible hash value */
58 /* exclusive upper bound for every _asso_values[c]. A power of 2. */
60 /* Initial value for asso_values table. -1 means random. */
61 s32 initial_asso_value
;
62 /* Jump length when trying alternative values. 0 means random. */
64 /* Length of _head list. Number of keywords, not counting duplicates. */
66 /* sparse bit vector for collision detection */
67 struct Bool_Array
*collision_detector
;
68 /*}}} private -- END */
71 /*{{{ public static methods */
72 static struct Search
*schr_new(struct Keyword_List
*list
);
73 static void schr_del(struct Search
*t
);
74 static void schr_optimize(struct Search
*t
);
75 /*}}} public static methods -- END */
76 /*{{{ private static methods */
77 static void schr_prepare(struct Search
*t
);
78 static void schr_find_good_asso_values(struct Search
*t
);
79 static u32
schr_count_duplicates_tuple(struct Search
*t
);
80 static u32
schr_count_duplicates_tuple_do(struct Search
*t
, struct Positions
*positions
,
82 static void schr_find_positions(struct Search
*t
);
83 static void schr_find_alpha_inc(struct Search
*t
);
84 static u32
*schr_compute_alpha_unify(struct Search
*t
);
85 static u32
*schr_compute_alpha_unify_with_inc(struct Search
*t
, struct Positions
*positions
,
87 static u32
schr_compute_alpha_size(void);
88 static u32
schr_compute_alpha_size_with_inc(struct Search
*t
, u32
*alpha_inc
);
89 static void schr_init_selchars_tuple(struct Search
*t
, struct Positions
*positions
,
91 static void schr_delete_selchars(struct Search
*t
);
92 static u32
schr_count_duplicates_multiset(struct Search
*t
, u32
*alpha_inc
);
93 static void schr_init_selchars_multiset(struct Search
*t
, struct Positions
*positions
,
94 u32
*alpha_unify
, u32
*alpha_inc
);
95 static void schr_prepare_asso_values(struct Search
*t
);
96 static void schr_find_asso_values(struct Search
*t
);
97 struct EquivalenceClass
;
98 static struct EquivalenceClass
*schr_compute_partition(struct Search
*t
, bool *undetermined
);
99 static u32
schr_count_possible_collisions(struct Search
*t
, struct EquivalenceClass
*partition
,
101 static bool schr_unchanged_partition(struct Search
*t
, struct EquivalenceClass
*partition
, u32 c
);
102 static s32
schr_compute_hash(struct Search
*t
, struct Keyword
*kw
);
103 static void schr_sort(struct Search
*t
);
104 /*}}} private static methods -- END */
105 /*------------------------------------------------------------------------------------------------*/
107 #include "namespace/search.h"
108 #include "namespace/keyword.h"
109 #include "namespace/keyword_list.h"
110 #include "namespace/positions.h"
111 #include "namespace/bool-array.h"
112 /* for the Search local types */
113 #include "namespace/search.c"
115 /*------------------------------------------------------------------------------------------------*/