Skip to content

Commit 28c318d

Browse files
committed
VQF: disable sorting by default, as sorting isn't guaranteed to work, and because it needes more space
1 parent b7c969e commit 28c318d

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

benchmarks/bulk-insert-and-query.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ int main(int argc, char * argv[]) {
731731
cout << setw(NAME_WIDTH) << names[a] << cf << endl;
732732
}
733733
a = 31;
734-
if (algorithmId == a || (algos.find(a) != algos.end())) {
734+
if (algorithmId == a || algorithmId < 0 || (algos.find(a) != algos.end())) {
735735
auto cf = FilterBenchmark<
736736
VQFilter<uint64_t, SimpleMixSplit>>(
737737
add_count, to_add, intersectionsize, mixed_sets, true, false);

src/vqf/vqf_cpp.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ enum Status {
2121
NotSupported = 3,
2222
};
2323

24+
// #define SORTED_ADD
25+
2426
template <typename ItemType, typename HashFamily = SimpleMixSplit>
2527
class 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
120125
template <typename ItemType, typename HashFamily>
121126
Status 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

Comments
 (0)