24
24
25
25
#define MAX_POINTS_FOR_USING_BITSET 10000000
26
26
27
+ #define USE_MAP_OF_FILE 1
28
+
27
29
namespace diskann
28
30
{
29
31
@@ -223,7 +225,7 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
223
225
// If not compacted, saving the whole data as the points may be spread around.
224
226
const unsigned node_count = _data_compacted ? _nd + _num_frozen_pts : _max_points + _num_frozen_pts;
225
227
226
- #ifdef _WINDOWS
228
+ #ifdef USE_MAP_OF_FILE
227
229
228
230
const size_t size_of_data = node_count * _aligned_dim * sizeof (T);
229
231
const size_t total_size = 2 * sizeof (uint32_t ) + size_of_data;
@@ -241,6 +243,10 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
241
243
242
244
return size_of_data;
243
245
#else
246
+ Log (logging::Info,
247
+ " save_data" ,
248
+ " Saving data using ofstream" );
249
+
244
250
return save_data_in_base_dimensions (data_file, _data, node_count, _dim, _aligned_dim);
245
251
#endif
246
252
}
@@ -250,7 +256,7 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
250
256
// 4 byte unsigned)
251
257
template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT>::save_graph(const std::string& graph_file) const
252
258
{
253
- #if _WINDOWS
259
+ #if USE_MAP_OF_FILE
254
260
255
261
Log (logging::Info, " save_graph" , " Saving graph data using file map" );
256
262
@@ -322,6 +328,8 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
322
328
return index_size;
323
329
324
330
#else
331
+ Log (logging::Info, " save_graph" , " Saving graph data using ofstream" );
332
+
325
333
std::ofstream out;
326
334
open_file_to_write (out, graph_file);
327
335
@@ -337,12 +345,12 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
337
345
out.write ((char *)&_start, sizeof (_start));
338
346
out.write ((char *)&_num_frozen_pts, sizeof (_num_frozen_pts));
339
347
340
- size_t data_compacted_output = _data_compacted ? 1 : 0 ;
348
+ const size_t data_compacted_output = _data_compacted ? 1 : 0 ;
341
349
out.write ((char *)&data_compacted_output, sizeof (data_compacted_output));
342
350
343
- const _u64 header_size = sizeof (index_size) + sizeof (_max_observed_degree)
344
- + sizeof (_start ) + sizeof (_num_frozen_pts)
345
- + sizeof (data_compacted_output);
351
+ const _u64 header_size = sizeof (index_size) + sizeof (_max_observed_degree) + sizeof (_start) +
352
+ sizeof (_num_frozen_pts ) + sizeof (data_compacted_output);
353
+
346
354
index_size = header_size;
347
355
348
356
// If the graph is compacted, either _nd == _max_points or any frozen points have been
@@ -378,7 +386,9 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
378
386
Log (logging::Info,
379
387
" save_graph" ,
380
388
" Graph data saved, total points: %u, empty out nodes: %u, max_degree: %u" ,
381
- total_points, empty_out_neighbors, max_degree);
389
+ total_points,
390
+ empty_out_neighbors,
391
+ max_degree);
382
392
383
393
return index_size; // number of bytes written
384
394
#endif
@@ -470,10 +480,10 @@ void Index<T, TagT, LabelT>::save(const char *filename, bool compact_before_save
470
480
}
471
481
}
472
482
473
- std::string graph_file = std::string (filename);
474
- std::string tags_file = std::string (filename) + " .tags" ;
475
- std::string data_file = std::string (filename) + " .data" ;
476
- std::string delete_list_file = std::string (filename) + " .del" ;
483
+ const std::string graph_file = std::string (filename);
484
+ const std::string tags_file = std::string (filename) + " .tags" ;
485
+ const std::string data_file = std::string (filename) + " .data" ;
486
+ const std::string delete_list_file = std::string (filename) + " .del" ;
477
487
478
488
// Because the save_* functions use append mode, ensure that
479
489
// the files are deleted before save. Ideally, we should check
0 commit comments