@@ -23,12 +23,14 @@ use webgraph::prelude::*;
23
23
#[ derive( Parser , Debug , Clone ) ]
24
24
#[ command( name = "ef" , about = "Builds the Elias-Fano representation of the offsets of a graph." , long_about = None ) ]
25
25
pub struct CliArgs {
26
- /// The basename of the graph.
26
+ /// The basename of the graph (or labels) .
27
27
pub src : PathBuf ,
28
- /// The number of elements to be inserted in the Elias-Fano
29
- /// starting from a label offset file. It is usually one more than
30
- /// the number of nodes in the graph.
31
- pub n : Option < usize > ,
28
+ /// The number of nodes of the graph. When passed, we don't need to load the
29
+ /// `.properties` file. This allows to build Elias-Fano from the offsets of
30
+ /// something that might not be a graph but that has offsets, like labels.
31
+ /// For this reason, if passed, we will also try to read the `.labeloffsets`
32
+ /// file and then fallback to the usual `.offsets` file.
33
+ pub number_of_nodes : Option < usize > ,
32
34
}
33
35
34
36
pub fn main ( global_args : GlobalArgs , args : CliArgs ) -> Result < ( ) > {
65
67
}
66
68
67
69
let basename = args. src . clone ( ) ;
68
- if let Some ( num_nodes) = args. n {
70
+ if let Some ( num_nodes) = args. number_of_nodes {
69
71
pl. expected_updates ( Some ( num_nodes) ) ;
70
72
// Horribly temporary duplicated code for the case of label offsets.
71
73
let of_file_path = basename. with_extension ( LABELOFFSETS_EXTENSION ) ;
77
79
. seek ( std:: io:: SeekFrom :: End ( 0 ) )
78
80
. with_context ( || format ! ( "Could not seek to end of {}" , labels_path. display( ) ) ) ?;
79
81
80
- let mut efb = EliasFanoBuilder :: new ( num_nodes, file_len as usize ) ;
82
+ let mut efb = EliasFanoBuilder :: new ( num_nodes + 1 , file_len as usize ) ;
81
83
82
84
info ! ( "The offsets file exists, reading it to build Elias-Fano" ) ;
83
85
@@ -110,21 +112,24 @@ where
110
112
// otherwise use the provided value, this is so we can build the Elias-Fano
111
113
// for offsets of any custom format that might not use the standard
112
114
// properties file
113
- let num_nodes = args. n . map ( Ok :: < _ , anyhow:: Error > ) . unwrap_or_else ( || {
114
- let properties_path = basename. with_extension ( PROPERTIES_EXTENSION ) ;
115
- info ! (
116
- "Reading num_of_nodes from properties file at '{}'" ,
117
- properties_path. display( )
118
- ) ;
119
- let f = File :: open ( & properties_path) . with_context ( || {
120
- format ! (
121
- "Could not open properties file: {}" ,
115
+ let num_nodes = args
116
+ . number_of_nodes
117
+ . map ( Ok :: < _ , anyhow:: Error > )
118
+ . unwrap_or_else ( || {
119
+ let properties_path = basename. with_extension ( PROPERTIES_EXTENSION ) ;
120
+ info ! (
121
+ "Reading num_of_nodes from properties file at '{}'" ,
122
122
properties_path. display( )
123
- )
123
+ ) ;
124
+ let f = File :: open ( & properties_path) . with_context ( || {
125
+ format ! (
126
+ "Could not open properties file: {}" ,
127
+ properties_path. display( )
128
+ )
129
+ } ) ?;
130
+ let map = java_properties:: read ( BufReader :: new ( f) ) ?;
131
+ Ok ( map. get ( "nodes" ) . unwrap ( ) . parse :: < usize > ( ) ?)
124
132
} ) ?;
125
- let map = java_properties:: read ( BufReader :: new ( f) ) ?;
126
- Ok ( map. get ( "nodes" ) . unwrap ( ) . parse :: < usize > ( ) ?)
127
- } ) ?;
128
133
pl. expected_updates ( Some ( num_nodes) ) ;
129
134
130
135
let mut efb = EliasFanoBuilder :: new ( num_nodes + 1 , file_len as usize ) ;
0 commit comments