This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
annoygomodule.h
92 lines (84 loc) · 2.27 KB
/
annoygomodule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "annoylib.h"
#include "kissrandom.h"
namespace GoAnnoy {
class AnnoyIndex {
protected:
::AnnoyIndexInterface<int32_t, float> *ptr;
int f;
public:
~AnnoyIndex() {
delete ptr;
};
void addItem(int item, const float* w) {
ptr->add_item(item, w);
};
void build(int q) {
ptr->build(q);
};
bool save(const char* filename, bool prefault) {
return ptr->save(filename, prefault);
};
bool save(const char* filename) {
return ptr->save(filename, true);
};
void unload() {
ptr->unload();
};
bool load(const char* filename, bool prefault) {
return ptr->load(filename, prefault);
};
bool load(const char* filename) {
return ptr->load(filename, true);
};
float getDistance(int i, int j) {
return ptr->get_distance(i, j);
};
void getNnsByItem(int item, int n, int search_k, vector<int32_t>* result, vector<float>* distances) {
ptr->get_nns_by_item(item, n, search_k, result, distances);
};
void getNnsByVector(const float* w, int n, int search_k, vector<int32_t>* result, vector<float>* distances) {
ptr->get_nns_by_vector(w, n, search_k, result, distances);
};
void getNnsByItem(int item, int n, int search_k, vector<int32_t>* result) {
ptr->get_nns_by_item(item, n, search_k, result, NULL);
};
void getNnsByVector(const float* w, int n, int search_k, vector<int32_t>* result) {
ptr->get_nns_by_vector(w, n, search_k, result, NULL);
};
int getNItems() {
return (int)ptr->get_n_items();
};
void verbose(bool v) {
ptr->verbose(v);
};
void getItem(int item, vector<float> *v) {
v->resize(this->f);
ptr->get_item(item, &v->front());
};
bool onDiskBuild(const char* filename) {
return ptr->on_disk_build(filename);
};
};
class AnnoyIndexAngular : public AnnoyIndex
{
public:
AnnoyIndexAngular(int f) {
ptr = new ::AnnoyIndex<int32_t, float, ::Angular, ::Kiss64Random>(f);
this->f = f;
}
};
class AnnoyIndexEuclidean : public AnnoyIndex {
public:
AnnoyIndexEuclidean(int f) {
ptr = new ::AnnoyIndex<int32_t, float, ::Euclidean, ::Kiss64Random>(f);
this->f = f;
}
};
class AnnoyIndexManhattan : public AnnoyIndex {
public:
AnnoyIndexManhattan(int f) {
ptr = new ::AnnoyIndex<int32_t, float, ::Manhattan, ::Kiss64Random>(f);
this->f = f;
}
};
}