1#ifndef KNNCOLLE_LOAD_PREBUILT_HPP
2#define KNNCOLLE_LOAD_PREBUILT_HPP
5#include <unordered_map>
30template<
typename Index_,
typename Data_,
typename Distance_>
31using LoadPrebuiltFunction = std::function<Prebuilt<Index_, Data_, Distance_>* (
const std::filesystem::path&)>;
44template<
typename Index_,
typename Data_,
typename Distance_>
46 static std::unordered_map<std::string, LoadPrebuiltFunction<Index_, Data_, Distance_> > registry;
61 std::runtime_error(
"cannot find a load_prebuilt_registry() function for '" + algorithm +
"' at '" + path.string() +
"'"),
62 my_algorithm(std::move(algorithm)),
63 my_path(std::move(path))
70 std::string my_algorithm;
71 std::filesystem::path my_path;
84 const std::filesystem::path&
get_path()
const {
104template<
typename Index_,
typename Data_,
typename Distance_>
106 const auto alg_path = dir /
"ALGORITHM";
110 auto it = reg.find(algorithm);
111 if (it == reg.end()) {
115 return (it->second)(dir);
131template<
typename Index_,
typename Data_,
typename Distance_>
149template<
typename Index_,
typename Data_,
typename Distance_>
194template<
typename Index_,
typename Data_,
typename Distance_,
typename Normalized_>
196 return new L2NormalizedPrebuilt<Index_, Data_, Distance_, Normalized_>(dir);
214template<
typename Index_,
typename Data_,
typename Distance_,
class DistanceMetric_ = DistanceMetric<Data_, Distance_> >
216 return new BruteforcePrebuilt<Index_, Data_, Distance_, DistanceMetric_>(dir);
234template<
typename Index_,
typename Data_,
typename Distance_,
class DistanceMetric_ = DistanceMetric<Data_, Distance_> >
236 return new VptreePrebuilt<Index_, Data_, Distance_, DistanceMetric_>(dir);
Implements a brute-force search for nearest neighbors.
Wrapper for L2 normalization prior to search.
Interface for prebuilt nearest-neighbor indices.
Implements a vantage point (VP) tree to search for nearest neighbors.
Exception for unknown search algorithms in load_prebuilt_raw().
Definition load_prebuilt.hpp:55
const std::string & get_algorithm() const
Definition load_prebuilt.hpp:77
const std::filesystem::path & get_path() const
Definition load_prebuilt.hpp:84
Interface for prebuilt nearest-neighbor search indices.
Definition Prebuilt.hpp:29
Collection of KNN algorithms.
Definition Bruteforce.hpp:29
std::function< Prebuilt< Index_, Data_, Distance_ > *(const std::filesystem::path &)> LoadPrebuiltFunction
Definition load_prebuilt.hpp:31
Prebuilt< Index_, Data_, Distance_ > * load_bruteforce_prebuilt(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:215
std::shared_ptr< Prebuilt< Index_, Data_, Distance_ > > load_prebuilt_shared(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:150
void quick_load(const std::filesystem::path &path, Input_ *const contents, const Length_ length)
Definition utils.hpp:57
Prebuilt< Index_, Data_, Distance_ > * load_prebuilt_raw(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:105
Prebuilt< Index_, Data_, Distance_ > * load_l2normalized_prebuilt(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:195
Prebuilt< Index_, Data_, Distance_ > * load_vptree_prebuilt(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:235
L2NormalizedPrebuiltTypes load_l2normalized_prebuilt_types(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:173
std::string quick_load_as_string(const std::filesystem::path &path)
Definition utils.hpp:74
NumericType
Definition NumericType.hpp:18
std::unique_ptr< Prebuilt< Index_, Data_, Distance_ > > load_prebuilt_unique(const std::filesystem::path &dir)
Definition load_prebuilt.hpp:132
std::unordered_map< std::string, LoadPrebuiltFunction< Index_, Data_, Distance_ > > & load_prebuilt_registry()
Definition load_prebuilt.hpp:45
Template type of a saved L2-normalized index.
Definition load_prebuilt.hpp:159
NumericType normalized
Definition load_prebuilt.hpp:163