Skip to content

Commit e4375a4

Browse files
committed
Fix build ef inconsistent use of argument n. Now it's number_of_nodes
1 parent 5924a68 commit e4375a4

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

cli/src/build/ef.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ use webgraph::prelude::*;
2323
#[derive(Parser, Debug, Clone)]
2424
#[command(name = "ef", about = "Builds the Elias-Fano representation of the offsets of a graph.", long_about = None)]
2525
pub struct CliArgs {
26-
/// The basename of the graph.
26+
/// The basename of the graph (or labels).
2727
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>,
3234
}
3335

3436
pub fn main(global_args: GlobalArgs, args: CliArgs) -> Result<()> {
@@ -65,7 +67,7 @@ where
6567
}
6668

6769
let basename = args.src.clone();
68-
if let Some(num_nodes) = args.n {
70+
if let Some(num_nodes) = args.number_of_nodes {
6971
pl.expected_updates(Some(num_nodes));
7072
// Horribly temporary duplicated code for the case of label offsets.
7173
let of_file_path = basename.with_extension(LABELOFFSETS_EXTENSION);
@@ -77,7 +79,7 @@ where
7779
.seek(std::io::SeekFrom::End(0))
7880
.with_context(|| format!("Could not seek to end of {}", labels_path.display()))?;
7981

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);
8183

8284
info!("The offsets file exists, reading it to build Elias-Fano");
8385

@@ -110,21 +112,24 @@ where
110112
// otherwise use the provided value, this is so we can build the Elias-Fano
111113
// for offsets of any custom format that might not use the standard
112114
// 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 '{}'",
122122
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>()?)
124132
})?;
125-
let map = java_properties::read(BufReader::new(f))?;
126-
Ok(map.get("nodes").unwrap().parse::<usize>()?)
127-
})?;
128133
pl.expected_updates(Some(num_nodes));
129134

130135
let mut efb = EliasFanoBuilder::new(num_nodes + 1, file_len as usize);

cli/tests/test_llp_pipeline.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ fn test_llp_pipeline() -> Result<()> {
2323
let basename = tmp_dir.path().join(graph_name).display().to_string();
2424

2525
// copy the graph files to the temporary directory
26-
for extension in [GRAPH_EXTENSION, PROPERTIES_EXTENSION, OFFSETS_EXTENSION] {
26+
for extension in [GRAPH_EXTENSION, PROPERTIES_EXTENSION] {
2727
std::fs::copy(
2828
copy_basename.with_extension(extension),
2929
tmp_dir.path().join(graph_name).with_extension(extension),
3030
)?;
3131
}
3232

33+
log::info!("Step 0: Built the Offsets");
34+
cli_main(vec!["webgraph", "build", "offsets", &basename])?;
3335
log::info!("Step 1: Creates the Elias Fano");
3436
cli_main(vec!["webgraph", "build", "ef", &basename])?;
3537
log::info!("Step 2: Run a BFS traversal to get the initial permutation");

0 commit comments

Comments
 (0)