File tree Expand file tree Collapse file tree 3 files changed +60
-4
lines changed Expand file tree Collapse file tree 3 files changed +60
-4
lines changed Original file line number Diff line number Diff line change @@ -181,10 +181,8 @@ class LshIndex : public NNIndex<Distance>
181
181
ar & key_size_;
182
182
ar & multi_probe_level_;
183
183
184
- if (Archive::is_loading::value) {
185
- // Building the index is so fast we can afford not storing it
186
- buildIndex ();
187
- }
184
+ ar & xor_masks_;
185
+ ar & tables_;
188
186
189
187
if (Archive::is_loading::value) {
190
188
index_params_[" algorithm" ] = getType ();
Original file line number Diff line number Diff line change @@ -297,6 +297,33 @@ class LshTable
297
297
}
298
298
}
299
299
300
+ template <typename Archive>
301
+ void serialize (Archive& ar)
302
+ {
303
+ int val;
304
+ if (Archive::is_saving::value) {
305
+ val = (int )speed_level_;
306
+ }
307
+ ar & val;
308
+ if (Archive::is_loading::value) {
309
+ speed_level_ = (SpeedLevel) val;
310
+ }
311
+
312
+ ar & key_size_;
313
+ ar & mask_;
314
+
315
+ if (speed_level_==kArray ) {
316
+ ar & buckets_speed_;
317
+ }
318
+ if (speed_level_==kBitsetHash || speed_level_==kHash ) {
319
+ ar & buckets_space_;
320
+ }
321
+ if (speed_level_==kBitsetHash ) {
322
+ ar & key_bitset_;
323
+ }
324
+ }
325
+ friend struct serialization ::access;
326
+
300
327
/* * The vector of all the buckets if they are held for speed
301
328
*/
302
329
BucketsSpeed buckets_speed_;
Original file line number Diff line number Diff line change 2
2
#define SERIALIZATION_H_
3
3
4
4
#include < vector>
5
+ #include < map>
5
6
#include < stdio.h>
6
7
7
8
namespace flann
@@ -116,6 +117,36 @@ struct Serializer<std::vector<T> >
116
117
}
117
118
};
118
119
120
+ // serializer for std::vector
121
+ template <typename K, typename V>
122
+ struct Serializer <std::map<K,V> >
123
+ {
124
+ template <typename InputArchive>
125
+ static inline void load (InputArchive& ar, std::map<K,V>& map_val)
126
+ {
127
+ size_t size;
128
+ ar & size;
129
+ for (size_t i = 0 ; i < size; ++i)
130
+ {
131
+ K key;
132
+ ar & key;
133
+ V value;
134
+ ar & value;
135
+ map_val[key] = value;
136
+ }
137
+ }
138
+
139
+ template <typename OutputArchive>
140
+ static inline void save (OutputArchive& ar, const std::map<K,V>& map_val)
141
+ {
142
+ ar & map_val.size ();
143
+ for (typename std::map<K,V>::const_iterator i=map_val.begin (); i!=map_val.end (); ++i) {
144
+ ar & i->first ;
145
+ ar & i->second ;
146
+ }
147
+ }
148
+ };
149
+
119
150
template <typename T>
120
151
struct Serializer <T*>
121
152
{
You can’t perform that action at this time.
0 commit comments