2#include <unordered_map>
8 template<
typename dist_t>
26 std::runtime_error(
"Not enough memory: BruteforceSearch failed to allocate data");
60 throw std::runtime_error(
"The number of elements exceeds the specified limit\n");
90 std::priority_queue<std::pair<dist_t, labeltype >>
92 std::priority_queue<std::pair<dist_t, labeltype >> topResults;
94 for (
int i = 0; i < k; i++) {
99 dist_t lastdist = topResults.top().first;
102 if (dist <= lastdist) {
105 if (topResults.size() > k)
107 lastdist = topResults.top().first;
115 std::ofstream output(location, std::ios::binary);
116 std::streampos position;
130 std::ifstream input(location, std::ios::binary);
131 std::streampos position;
142 if (
data_ ==
nullptr)
143 std::runtime_error(
"Not enough memory: loadIndex failed to allocate data");
Definition bruteforce.h:9
void * dist_func_param_
Definition bruteforce.h:41
std::unordered_map< labeltype, size_t > dict_external_to_internal
Definition bruteforce.h:44
size_t size_per_element_
Definition bruteforce.h:37
~BruteforceSearch()
Definition bruteforce.h:30
DISTFUNC< dist_t > fstdistfunc_
Definition bruteforce.h:40
BruteforceSearch(SpaceInterface< dist_t > *s, const std::string &location)
Definition bruteforce.h:14
BruteforceSearch(SpaceInterface< dist_t > *s, size_t maxElements)
Definition bruteforce.h:18
void saveIndex(const std::string &location)
Definition bruteforce.h:114
char * data_
Definition bruteforce.h:34
size_t cur_element_count
Definition bruteforce.h:36
void loadIndex(const std::string &location, SpaceInterface< dist_t > *s)
Definition bruteforce.h:127
void addPoint(const void *datapoint, labeltype label)
Definition bruteforce.h:46
BruteforceSearch(SpaceInterface< dist_t > *)
Definition bruteforce.h:11
std::priority_queue< std::pair< dist_t, labeltype > > searchKnn(const void *query_data, size_t k) const
Definition bruteforce.h:91
size_t maxelements_
Definition bruteforce.h:35
void removePoint(labeltype cur_external)
Definition bruteforce.h:75
std::mutex index_lock
Definition bruteforce.h:42
size_t data_size_
Definition bruteforce.h:39
virtual size_t get_data_size()=0
virtual void * get_dist_func_param()=0
virtual DISTFUNC< MTYPE > get_dist_func()=0
Definition bruteforce.h:7
size_t labeltype
Definition hnswlib.h:117
static void writeBinaryPOD(std::ostream &out, const T &podRef)
Definition hnswlib.h:128
static void readBinaryPOD(std::istream &in, T &podRef)
Definition hnswlib.h:133
MTYPE(*)(const void *, const void *, const void *) DISTFUNC
Definition hnswlib.h:138