Skip to content

Commit 50fcb78

Browse files
author
sprice
committed
FLANN uses much less RAM when decompressing saved index files. Should be backwards compatible with original index type.
1 parent bd1410d commit 50fcb78

File tree

4 files changed

+313
-71
lines changed

4 files changed

+313
-71
lines changed

src/cpp/flann/algorithms/autotuned_index.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,21 @@ class AutotunedIndex : public NNIndex<Distance>
208208

209209
void saveIndex(FILE* stream)
210210
{
211-
serialization::SaveArchive sa(stream);
212-
sa & *this;
211+
{
212+
serialization::SaveArchive sa(stream);
213+
sa & *this;
214+
}
213215

214216
bestIndex_->saveIndex(stream);
215217
}
216218

217219
void loadIndex(FILE* stream)
218220
{
219-
serialization::LoadArchive la(stream);
220-
la & *this;
221-
221+
{
222+
serialization::LoadArchive la(stream);
223+
la & *this;
224+
}
225+
222226
IndexParams params;
223227
flann_algorithm_t index_type = get_param<flann_algorithm_t>(bestParams_,"algorithm");
224228
bestIndex_ = create_index_by_type<Distance>((flann_algorithm_t)index_type, dataset_, params, distance_);

src/cpp/flann/algorithms/nn_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class NNIndex : public IndexBase
239239
if (Archive::is_loading::value) {
240240
if (strncmp(header.h.signature,
241241
FLANN_SIGNATURE_,
242-
strlen(FLANN_SIGNATURE_)) != 0) {
242+
strlen(FLANN_SIGNATURE_) - strlen("v0.0")) != 0) {
243243
throw FLANNException("Invalid index file, wrong signature");
244244
}
245245

src/cpp/flann/util/saving.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#ifdef FLANN_SIGNATURE_
4141
#undef FLANN_SIGNATURE_
4242
#endif
43-
#define FLANN_SIGNATURE_ "FLANN_INDEX_v1.0"
43+
#define FLANN_SIGNATURE_ "FLANN_INDEX_v1.1"
4444

4545
namespace flann
4646
{
@@ -60,7 +60,7 @@ struct IndexHeader
6060
strcpy(h.version, FLANN_VERSION_);
6161

6262
h.compression = 0;
63-
h.uncompressed_size = 0;
63+
h.first_block_size = 0;
6464
}
6565

6666
private:
@@ -74,7 +74,7 @@ struct IndexHeader
7474
ar & h.rows;
7575
ar & h.cols;
7676
ar & h.compression;
77-
ar & h.uncompressed_size;
77+
ar & h.first_block_size;
7878
}
7979
friend struct serialization::access;
8080
};
@@ -114,7 +114,7 @@ inline IndexHeader load_header(FILE* stream)
114114

115115
if (strncmp(header.h.signature,
116116
FLANN_SIGNATURE_,
117-
strlen(FLANN_SIGNATURE_)) != 0) {
117+
strlen(FLANN_SIGNATURE_) - strlen("v0.0")) != 0) {
118118
throw FLANNException("Invalid index file, wrong signature");
119119
}
120120

0 commit comments

Comments
 (0)