Skip to content

Commit

Permalink
Add const qualifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed Oct 20, 2018
1 parent 420b489 commit 111a07d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
11 changes: 6 additions & 5 deletions inst/include/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {

std::default_random_engine level_generator_;

inline labeltype getExternalLabel(tableint internal_id) {
inline labeltype getExternalLabel(tableint internal_id) const {
return *((labeltype *) (data_level0_memory_ + internal_id * size_data_per_element_ + label_offset_));
}

inline labeltype *getExternalLabeLp(tableint internal_id) {
inline labeltype *getExternalLabeLp(tableint internal_id) const {
return (labeltype *) (data_level0_memory_ + internal_id * size_data_per_element_ + label_offset_);
}

inline char *getDataByInternalId(tableint internal_id) {
inline char *getDataByInternalId(tableint internal_id) const {
return (data_level0_memory_ + internal_id * size_data_per_element_ + offsetData_);
}

Expand Down Expand Up @@ -220,7 +220,7 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
}

std::priority_queue<std::pair<dist_t, tableint>, std::vector<std::pair<dist_t, tableint>>, CompareByFirst>
searchBaseLayerST(tableint ep_id, void *data_point, size_t ef) {
searchBaseLayerST(tableint ep_id, const void *data_point, size_t ef) const {
VisitedList *vl = visited_list_pool_->getFreeVisitedList();
vl_type *visited_array = vl->mass;
vl_type visited_array_tag = vl->curV;
Expand Down Expand Up @@ -721,7 +721,7 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
return cur_c;
};

std::priority_queue<std::pair<dist_t, labeltype >> searchKnn(void *query_data, size_t k) {
std::priority_queue<std::pair<dist_t, labeltype >> searchKnn(const void *query_data, size_t k) const {
tableint currObj = enterpoint_node_;
dist_t curdist = fstdistfunc_(query_data, getDataByInternalId(enterpoint_node_), dist_func_param_);

Expand Down Expand Up @@ -767,3 +767,4 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
};

}

57 changes: 28 additions & 29 deletions inst/include/hnswlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,43 @@
#endif

namespace hnswlib {
typedef size_t labeltype;
typedef size_t labeltype;

template<typename T>
static void writeBinaryPOD(std::ostream &out, const T &podRef) {
out.write((char *) &podRef, sizeof(T));
}
template<typename T>
static void writeBinaryPOD(std::ostream &out, const T &podRef) {
out.write((char *) &podRef, sizeof(T));
}

template<typename T>
static void readBinaryPOD(std::istream &in, T &podRef) {
in.read((char *) &podRef, sizeof(T));
}
template<typename T>
static void readBinaryPOD(std::istream &in, T &podRef) {
in.read((char *) &podRef, sizeof(T));
}

template<typename MTYPE>
using DISTFUNC = MTYPE(*)(const void *, const void *, const void *);
template<typename MTYPE>
using DISTFUNC = MTYPE(*)(const void *, const void *, const void *);


template<typename MTYPE>
class SpaceInterface {
public:
//virtual void search(void *);
virtual size_t get_data_size() = 0;
template<typename MTYPE>
class SpaceInterface {
public:
//virtual void search(void *);
virtual size_t get_data_size() = 0;

virtual DISTFUNC<MTYPE> get_dist_func() = 0;
virtual DISTFUNC<MTYPE> get_dist_func() = 0;

virtual void *get_dist_func_param() = 0;
virtual void *get_dist_func_param() = 0;

virtual ~SpaceInterface() {}
};
};

template<typename dist_t>
class AlgorithmInterface {
public:
virtual void addPoint(void *datapoint, labeltype label)=0;
virtual std::priority_queue<std::pair<dist_t, labeltype >> searchKnn(void *, size_t) = 0;
virtual void saveIndex(const std::string &location)=0;
virtual ~AlgorithmInterface(){
}
};
template<typename dist_t>
class AlgorithmInterface {
public:
virtual void addPoint(void *datapoint, labeltype label)=0;
virtual std::priority_queue<std::pair<dist_t, labeltype >> searchKnn(const void *, size_t) const = 0;
virtual void saveIndex(const std::string &location)=0;
virtual ~AlgorithmInterface(){
}
};


}
Expand Down

0 comments on commit 111a07d

Please sign in to comment.