@@ -21,6 +21,8 @@ enum Status {
2121 NotSupported = 3 ,
2222};
2323
24+ // #define SORTED_ADD
25+
2426template <typename ItemType, typename HashFamily = SimpleMixSplit>
2527class VQFilter {
2628
@@ -37,10 +39,13 @@ class VQFilter {
3739 public:
3840 explicit VQFilter (const size_t n) : hasher() {
3941
40- // when inserting in random order
41- // uint64_t nslots = (uint64_t) (n / 0.94);
42+ #ifdef SORTED_ADD
4243 // when inserting in sorted order
43- uint64_t nslots = (uint64_t ) (n / 0.89 );
44+ uint64_t nslots = (uint64_t ) (n / 0.85 );
45+ #else
46+ // when inserting in random order
47+ uint64_t nslots = (uint64_t ) (n / 0.94 );
48+ #endif
4449
4550 if ((filter = vqf_init (nslots)) == NULL ) {
4651 std::cout << " Can't allocate.\n " ;
@@ -120,13 +125,7 @@ void VQFilter<ItemType, HashFamily>::ApplyBlock(uint64_t *tmp, int block, int le
120125template <typename ItemType, typename HashFamily>
121126Status VQFilter<ItemType, HashFamily>::AddAll(
122127 const ItemType* keys, const size_t start, const size_t end) {
123- /*
124- for (size_t i = start; i < end; i++) {
125- uint64_t key = keys[i];
126- uint64_t hash = hasher(key);
127- std::cout << "adding " << hash << "\n";
128- }
129- */
128+ #ifdef SORTED_ADD
130129 int blocks = 1 + (end - start) / blockLen;
131130 uint64_t *tmp = new uint64_t [blocks * blockLen];
132131 int *tmpLen = new int [blocks]();
@@ -151,6 +150,18 @@ Status VQFilter<ItemType, HashFamily>::AddAll(
151150 }
152151 delete[] tmp;
153152 delete[] tmpLen;
153+ #else
154+ // unsorted
155+ for (size_t i = start; i < end; i++) {
156+ uint64_t key = keys[i];
157+ uint64_t hash = hasher (key);
158+ bool ret = vqf_insert (filter, hash);
159+ if (!ret) {
160+ std::cout << " failed insertion for key.\n " ;
161+ abort ();
162+ }
163+ }
164+ #endif
154165 return Ok;
155166}
156167
0 commit comments