@@ -264,8 +264,8 @@ struct LoadInit {
264
264
///
265
265
/// See example in tests::reload_with_mmap
266
266
/// ```text
267
- /// let directory = PathBuf::from (".");
268
- /// let mut reloader = HnswIo::new(directory.clone(), String::from( "mmapreloadtest") );
267
+ /// let directory = Path::new (".");
268
+ /// let mut reloader = HnswIo::new(directory, "mmapreloadtest");
269
269
/// let options = ReloadOptions::default().set_mmap(true);
270
270
/// reloader.set_options(options);
271
271
/// let hnsw_loaded : Hnsw<f32,DistL1>= reloader.load_hnsw::<f32, DistL1>().unwrap();
@@ -321,9 +321,9 @@ impl HnswIo {
321
321
}
322
322
323
323
/// same as preceding, avoids the call to [set_options](Self::set_options())
324
- pub fn new_with_options ( directory : PathBuf , basename : String , options : ReloadOptions ) -> Self {
324
+ pub fn new_with_options ( directory : & Path , basename : String , options : ReloadOptions ) -> Self {
325
325
HnswIo {
326
- dir : directory,
326
+ dir : directory. to_path_buf ( ) ,
327
327
basename,
328
328
options,
329
329
datamap : None ,
@@ -336,15 +336,15 @@ impl HnswIo {
336
336
/// It is an error to call set_values on an already defined Hswnio by any function other than [default](Self::default())
337
337
pub fn set_values (
338
338
& mut self ,
339
- directory : PathBuf ,
339
+ directory : & Path ,
340
340
basename : String ,
341
341
options : ReloadOptions ,
342
- ) -> anyhow :: Result < ( ) > {
342
+ ) -> Result < ( ) > {
343
343
if self . initialized {
344
344
return Err ( anyhow ! ( "Hnswio already initialized" ) ) ;
345
345
} ;
346
346
//
347
- self . dir = directory;
347
+ self . dir = directory. to_path_buf ( ) ;
348
348
self . basename = basename;
349
349
self . options = options;
350
350
self . datamap = None ;
@@ -355,7 +355,7 @@ impl HnswIo {
355
355
} // end of set_values
356
356
357
357
//
358
- fn init ( & self ) -> anyhow :: Result < LoadInit > {
358
+ fn init ( & self ) -> Result < LoadInit > {
359
359
//
360
360
info ! ( "reloading from basename : {}" , & self . basename) ;
361
361
//
@@ -418,11 +418,12 @@ impl HnswIo {
418
418
self . options = options;
419
419
}
420
420
421
- /// reload a previously dumped hnsw stucture
422
- pub fn load_hnsw < T , D > ( & mut self ) -> Result < Hnsw < T , D > >
423
- where
424
- T : ' static + Serialize + DeserializeOwned + Clone + Sized + Send + Sync + std:: fmt:: Debug ,
425
- D : Distance < T > + Default + Send + Sync ,
421
+ /// reload a previously dumped hnsw structure
422
+ pub fn load_hnsw < ' b , ' a , T , D > ( & ' a mut self ) -> Result < Hnsw < ' b , T , D > >
423
+ where
424
+ T : ' static + Serialize + DeserializeOwned + Clone + Sized + Send + Sync + std:: fmt:: Debug ,
425
+ D : Distance < T > + Default + Send + Sync ,
426
+ ' a : ' b ,
426
427
{
427
428
//
428
429
debug ! ( "HnswIo::load_hnsw " ) ;
@@ -745,9 +746,7 @@ impl HnswIo {
745
746
//
746
747
info ! (
747
748
"found entry point, origin_id {:?} , layer {:?}, rank in layer {:?} " ,
748
- origin_id,
749
- layer,
750
- rank_in_l
749
+ origin_id, layer, rank_in_l
751
750
) ;
752
751
let entry_point = Arc :: clone ( & points_by_layer[ layer as usize ] [ rank_in_l as usize ] ) ;
753
752
info ! (
@@ -970,8 +969,7 @@ pub fn load_description(io_in: &mut dyn Read) -> Result<Description> {
970
969
descr. dimension = usize:: from_ne_bytes ( it_slice) ;
971
970
info ! (
972
971
"nb_point {:?} dimension {:?} " ,
973
- descr. nb_point,
974
- descr. dimension
972
+ descr. nb_point, descr. dimension
975
973
) ;
976
974
// distance name
977
975
let mut it_slice = [ 0u8 ; std:: mem:: size_of :: < usize > ( ) ] ;
@@ -1184,10 +1182,7 @@ type PointGraphInfo = (usize, PointId, Vec<Vec<Neighbour>>);
1184
1182
1185
1183
// This function reads neighbourhood info and returns neighbourhood info.
1186
1184
// It suppose and requires that the file graph_in is just at beginning of info related to origin_id
1187
- fn load_point_graph (
1188
- graph_in : & mut dyn Read ,
1189
- descr : & Description ,
1190
- ) -> Result < PointGraphInfo > {
1185
+ fn load_point_graph ( graph_in : & mut dyn Read , descr : & Description ) -> Result < PointGraphInfo > {
1191
1186
//
1192
1187
trace ! ( "in load_point_graph" ) ;
1193
1188
// read and check magic
@@ -1213,8 +1208,7 @@ fn load_point_graph(
1213
1208
let p_id = PointId ( layer, rank_in_l) ;
1214
1209
debug ! (
1215
1210
"in load_point_graph, got origin_id : {}, p_id : {:?}" ,
1216
- origin_id,
1217
- p_id
1211
+ origin_id, p_id
1218
1212
) ;
1219
1213
//
1220
1214
// Now for each layer , read neighbours
0 commit comments