Skip to content

Commit cd6ccd0

Browse files
committed
Use all-caps for saved file names to avoid conflicts with custom files.
Also change the save_name variable to be consistent with those in knncolle. Bumped version for a new release.
1 parent ea6bf10 commit cd6ccd0

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

include/knncolle_annoy/Annoy.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222

2323
namespace knncolle_annoy {
2424

25+
/**
26+
* Name of the Annoy algorithm when registering a loading function to `knncolle::load_prebuilt_registry()`.
27+
*/
28+
inline static constexpr const char* annoy_prebuilt_save_name = "knncolle_annoy::Annoy";
29+
2530
/**
2631
* @brief Options for `AnnoyBuilder()`.
2732
*/
@@ -323,18 +328,18 @@ class AnnoyPrebuilt final : public knncolle::Prebuilt<Index_, Data_, Distance_>
323328

324329
public:
325330
void save(const std::string& prefix) const {
326-
knncolle::quick_save(prefix + "ALGORITHM", save_name, std::strlen(save_name));
327-
knncolle::quick_save(prefix + "num_obs", &my_obs, 1);
328-
knncolle::quick_save(prefix + "num_dim", &my_dim, 1);
329-
knncolle::quick_save(prefix + "search_mult", &my_search_mult, 1);
331+
knncolle::quick_save(prefix + "ALGORITHM", annoy_prebuilt_save_name, std::strlen(annoy_prebuilt_save_name));
332+
knncolle::quick_save(prefix + "NUM_OBS", &my_obs, 1);
333+
knncolle::quick_save(prefix + "NUM_DIM", &my_dim, 1);
334+
knncolle::quick_save(prefix + "SEARCH_MULT", &my_search_mult, 1);
330335

331336
knncolle::NumericType types[2];
332337
types[0] = knncolle::get_numeric_type<AnnoyIndex_>();
333338
types[1] = knncolle::get_numeric_type<AnnoyData_>();
334-
knncolle::quick_save(prefix + "types", types, 2);
339+
knncolle::quick_save(prefix + "TYPES", types, 2);
335340

336341
const auto dname = get_distance_name<AnnoyDistance_>();
337-
knncolle::quick_save(prefix + "distance", dname, std::strlen(dname));
342+
knncolle::quick_save(prefix + "DISTANCE", dname, std::strlen(dname));
338343

339344
// Handling custom Annoy types.
340345
auto& icust = custom_save_for_annoy_index<AnnoyIndex_>();
@@ -357,15 +362,15 @@ class AnnoyPrebuilt final : public knncolle::Prebuilt<Index_, Data_, Distance_>
357362

358363
// For reasons unknown to us, AnnoyIndex::save() is not const, so we have to do it manually.
359364
// Hopefully this will be fixed in the future.
360-
const auto idxpath = prefix + "index";
365+
const auto idxpath = prefix + "INDEX";
361366
knncolle::quick_save(idxpath, reinterpret_cast<char*>(my_index.get_nodes()), sanisizer::product<std::streamsize>(my_index.get_s(), my_index.get_n_nodes()));
362367
}
363368

364369
AnnoyPrebuilt(const std::string prefix, std::size_t ndim) : my_dim(ndim), my_index(ndim) {
365-
knncolle::quick_load(prefix + "num_obs", &my_obs, 1);
366-
knncolle::quick_load(prefix + "search_mult", &my_search_mult, 1);
370+
knncolle::quick_load(prefix + "NUM_OBS", &my_obs, 1);
371+
knncolle::quick_load(prefix + "SEARCH_MULT", &my_search_mult, 1);
367372

368-
const auto idxpath = prefix + "index";
373+
const auto idxpath = prefix + "INDEX";
369374
char* errbuf = NULL;
370375
if (!my_index.load(idxpath.c_str(), true, &errbuf)) {
371376
std::runtime_error ex(errbuf);

include/knncolle_annoy/load_annoy_prebuilt.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ struct AnnoyPrebuiltTypes {
4848
*/
4949
inline AnnoyPrebuiltTypes load_annoy_prebuilt_types(const std::string& prefix) {
5050
knncolle::NumericType types[2];
51-
knncolle::quick_load(prefix + "types", types, 2);
51+
knncolle::quick_load(prefix + "TYPES", types, 2);
5252

5353
AnnoyPrebuiltTypes config;
5454
config.index = types[0];
5555
config.data = types[1];
56-
config.distance = knncolle::quick_load_as_string(prefix + "distance");
56+
config.distance = knncolle::quick_load_as_string(prefix + "DISTANCE");
5757

5858
return config;
5959
}
@@ -105,7 +105,7 @@ template<
105105
>
106106
auto load_annoy_prebuilt(const std::string& prefix) {
107107
std::size_t ndim;
108-
knncolle::quick_load(prefix + "num_dim", &ndim, 1);
108+
knncolle::quick_load(prefix + "NUM_DIM", &ndim, 1);
109109
return new AnnoyPrebuilt<Index_, Data_, Distance_, AnnoyDistance_, AnnoyIndex_, AnnoyData_, AnnoyRng_, AnnoyThreadPolicy_>(prefix, ndim);
110110
}
111111

include/knncolle_annoy/utils.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717

1818
namespace knncolle_annoy {
1919

20-
/**
21-
* Name to store in the `ALGORITHM` file for Annoy `knncolle::Prebuilt` instances,
22-
* see `knncolle::Prebuilt::save()` for details.
23-
*/
24-
inline static const char* save_name = "knncolle_annoy::Annoy";
25-
2620
/**
2721
* @cond
2822
*/

0 commit comments

Comments
 (0)