knncolle_annoy
Annoy nearest neighbors in knncolle
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#ifndef KNNCOLLE_ANNOY_UTILS_HPP
2#define KNNCOLLE_ANNOY_UTILS_HPP
3
4#include <string>
5#include <cstddef>
6#include <stdexcept>
7#include <type_traits>
8#include <functional>
9#include <filesystem>
10
11#include "knncolle/knncolle.hpp"
12
18namespace knncolle_annoy {
19
23template<typename Input_>
24using I = std::remove_cv_t<std::remove_reference_t<Input_> >;
25
26// Doing some SFINAE nonsense.
27template<typename AnnoyDistance_, typename Other_ = int>
28struct has_name {
29 static constexpr bool value = false;
30};
31
32template<typename AnnoyDistance_>
33struct has_name<AnnoyDistance_, decltype(AnnoyDistance_::name(), 0)> {
34 static constexpr bool value = std::is_same<decltype(AnnoyDistance_::name()), const char*>::value;
35};
47template<typename AnnoyDistance_>
48const char* get_distance_name() {
49 if constexpr(!has_name<AnnoyDistance_>::value) {
50 return "unknown";
51 } else {
52 return AnnoyDistance_::name();
53 }
54}
55
71template<class AnnoyIndex_>
72std::function<void(const std::filesystem::path&)>& custom_save_for_annoy_index() {
73 static std::function<void(const std::filesystem::path&)> fun;
74 return fun;
75}
76
92template<class AnnoyData_>
93std::function<void(const std::filesystem::path&)>& custom_save_for_annoy_data() {
94 static std::function<void(const std::filesystem::path&)> fun;
95 return fun;
96}
97
113template<class AnnoyDistance_>
114std::function<void(const std::filesystem::path&)>& custom_save_for_annoy_distance() {
115 static std::function<void(const std::filesystem::path&)> fun;
116 return fun;
117}
118
119}
120
121#endif
Approximate nearest neighbor search with Annoy.
Definition Annoy.hpp:24
const char * get_distance_name()
Definition utils.hpp:48
std::function< void(const std::filesystem::path &)> & custom_save_for_annoy_index()
Definition utils.hpp:72
std::function< void(const std::filesystem::path &)> & custom_save_for_annoy_data()
Definition utils.hpp:93
std::function< void(const std::filesystem::path &)> & custom_save_for_annoy_distance()
Definition utils.hpp:114