1#ifndef KNNCOLLE_HNSW_DISTANCES_HPP
2#define KNNCOLLE_HNSW_DISTANCES_HPP
20template<
typename Dim_,
typename InternalData_>
27 std::function<hnswlib::SpaceInterface<InternalData_>*(Dim_)>
create;
34 std::function<InternalData_(InternalData_)>
normalize;
42template<
typename InternalData_>
58 size_t get_data_size() {
62 hnswlib::DISTFUNC<InternalData_> get_dist_func() {
66 void * get_dist_func_param() {
71 static InternalData_ L1(
const void *pVect1v,
const void *pVect2v,
const void *qty_ptr) {
72 const InternalData_* pVect1 =
static_cast<const InternalData_*
>(pVect1v);
73 const InternalData_* pVect2 =
static_cast<const InternalData_*
>(pVect2v);
74 size_t qty = *((
size_t *) qty_ptr);
75 InternalData_ res = 0;
76 for (; qty > 0; --qty, ++pVect1, ++pVect2) {
77 res += std::abs(*pVect1 - *pVect2);
91template<
typename InternalData_>
107 size_t get_data_size() {
111 hnswlib::DISTFUNC<InternalData_> get_dist_func() {
115 void * get_dist_func_param() {
120 static InternalData_ L2(
const void *pVect1v,
const void *pVect2v,
const void *qty_ptr) {
121 const InternalData_* pVect1 =
static_cast<const InternalData_*
>(pVect1v);
122 const InternalData_* pVect2 =
static_cast<const InternalData_*
>(pVect2v);
123 size_t qty = *((
size_t *) qty_ptr);
124 InternalData_ res = 0;
125 for (; qty > 0; --qty, ++pVect1, ++pVect2) {
126 auto delta = *pVect1 - *pVect2;
127 res += delta * delta;
Manhattan distance.
Definition distances.hpp:43
ManhattanDistance(size_t dim)
Definition distances.hpp:52
Squared Euclidean distance.
Definition distances.hpp:92
SquaredEuclideanDistance(size_t dim)
Definition distances.hpp:101
knncolle bindings for HNSW search.
Definition distances.hpp:12
Distance options for the HNSW index.
Definition distances.hpp:21
std::function< hnswlib::SpaceInterface< InternalData_ > *(Dim_)> create
Definition distances.hpp:27
std::function< InternalData_(InternalData_)> normalize
Definition distances.hpp:34