Skip to content

Commit d672603

Browse files
committed
Parallel sorting of SCCS is now actually parallel; Zipped lenders are sorted only if the components are sorted
1 parent 3798040 commit d672603

11 files changed

Lines changed: 36 additions & 36 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
[![Line count](https://tokei.rs/b1/github/vigna/webgraph-rs)](https://github.com/vigna/webgraph-rs)
55

66
A Rust implementation of the [WebGraph
7-
framework](http://webgraph.di.unimi.it/) for graph compression.
7+
framework](https://webgraph.di.unimi.it/) for graph compression.
88

99
## At a Glance
1010

1111
- Compressed graph representation (start from here):
12-
[`webgraph`](http://crates.io/crates/webgraph) ([repo](/webgraph))
12+
[`webgraph`](https://crates.io/crates/webgraph) ([repo](/webgraph))
1313

14-
- Algorithms: [`webgraph_algo`](http://crates.io/crates/webgraph_algo)
14+
- Algorithms: [`webgraph-algo`](https://crates.io/crates/webgraph_algo)
1515
([repo](/algo))
1616

17-
- CLI commands: [`webgraph_cli`](http://crates.io/crates/webgraph_cli)
17+
- CLI commands: [`webgraph-cli`](https://crates.io/crates/webgraph_cli)
1818
([repo](/cli))
1919

2020
## Acknowledgments

algo/src/sccs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<C: AsMut<[usize]> + AsRef<[usize]>> Sccs<C> {
142142
.as_mut()
143143
.par_iter_mut()
144144
.for_each(|node_component| *node_component = inv_perm[*node_component]);
145-
sizes.sort_by(|&x, &y| y.cmp(&x));
145+
sizes.par_sort_by(|&x, &y| y.cmp(&x));
146146
sizes
147147
}
148148
}

cli/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
- Floats without a specified precision are now printed using the `zmij` crate,
1414
which brings a 3-4x speed improvement.
1515

16-
- We use the crate `zmij` for saving floats in ASCII when no precision is
17-
specified, which brings a 3-4x speed improvement.
18-
1916
## [0.4.0] - 2026-02-18
2017

2118
### New

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "webgraph-cli"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition = "2024"
55
authors = [
66
"Tommaso Fontana <tommaso.fontana.96@gmail.com>",

webgraph/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
- `BvGraphSeq` was sub-preallocating the successor vector (+1% speed).
1212

13+
### Improved
14+
15+
- Temporary compression files are now immediately removed when they
16+
are no longer necessary.
17+
1318
## [0.6.0] - 2026-02-18
1419

1520
### New

webgraph/src/graphs/arc_list_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct ArcListGraph<I> {
2727
into_iter: I,
2828
}
2929

30-
impl<L: Clone + Copy + 'static, I: Iterator<Item = ((usize, usize), L)> + Clone> ArcListGraph<I> {
30+
impl<L: Copy + 'static, I: Iterator<Item = ((usize, usize), L)> + Clone> ArcListGraph<I> {
3131
/// Creates a new arc-list graph from the given [`IntoIterator`].
3232
#[inline(always)]
3333
pub fn new_labeled(num_nodes: usize, iter: I) -> Self {

webgraph/src/graphs/btree_graph.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::collections::BTreeMap;
2424
#[derive(Clone, Debug, PartialEq, Eq)]
2525
pub struct LabeledBTreeGraph<L: Clone + 'static = ()> {
2626
/// The number of arcs in the graph.
27-
number_of_arcs: u64,
27+
num_arcs: u64,
2828
/// For each node, its list of successors.
2929
succ: Vec<BTreeMap<usize, L>>,
3030
}
@@ -39,15 +39,15 @@ impl<L: Clone + 'static> LabeledBTreeGraph<L> {
3939
/// Creates a new empty graph.
4040
pub fn new() -> Self {
4141
Self {
42-
number_of_arcs: 0,
42+
num_arcs: 0,
4343
succ: vec![],
4444
}
4545
}
4646

4747
/// Creates a new empty graph with `n` nodes.
4848
pub fn empty(n: usize) -> Self {
4949
Self {
50-
number_of_arcs: 0,
50+
num_arcs: 0,
5151
succ: Vec::from_iter((0..n).map(|_| BTreeMap::new())),
5252
}
5353
}
@@ -73,7 +73,7 @@ impl<L: Clone + 'static> LabeledBTreeGraph<L> {
7373
);
7474
}
7575
let is_new_arc = self.succ[u].insert(v, l).is_none();
76-
self.number_of_arcs += is_new_arc as u64;
76+
self.num_arcs += is_new_arc as u64;
7777
is_new_arc
7878
}
7979

@@ -88,7 +88,7 @@ impl<L: Clone + 'static> LabeledBTreeGraph<L> {
8888
);
8989
}
9090
let arc_existed = self.succ[u].remove(&v).is_some();
91-
self.number_of_arcs -= arc_existed as u64;
91+
self.num_arcs -= arc_existed as u64;
9292
arc_existed
9393
}
9494

@@ -198,7 +198,7 @@ impl<L: Clone + 'static> RandomAccessLabeling for LabeledBTreeGraph<L> {
198198
L: 'succ;
199199
#[inline(always)]
200200
fn num_arcs(&self) -> u64 {
201-
self.number_of_arcs
201+
self.num_arcs
202202
}
203203

204204
#[inline(always)]
@@ -363,7 +363,7 @@ impl RandomAccessLabeling for BTreeGraph {
363363

364364
#[inline(always)]
365365
fn num_arcs(&self) -> u64 {
366-
self.0.number_of_arcs
366+
self.0.num_arcs
367367
}
368368

369369
#[inline(always)]

webgraph/src/graphs/csr_graph.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ pub type CompressedCsrGraph = CsrGraph<EF, BitFieldVec>;
2929
pub type CompressedCsrSortedGraph = CsrSortedGraph<EF, BitFieldVec>;
3030

3131
/// A compressed sparse-row graph.
32-
#[derive(Debug, Clone, Epserde)]
33-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3432
///
3533
/// It is a graph representation that stores the degree cumulative function
3634
/// (DCF) and the successors in a compressed format. The DCF is a sequence of
@@ -51,6 +49,8 @@ pub type CompressedCsrSortedGraph = CsrSortedGraph<EF, BitFieldVec>;
5149
/// using a [`BitFieldVec`]. There is also a [version with sorted
5250
/// successors](CompressedCsrSortedGraph). Their construction requires a
5351
/// sequential graph providing the number of arcs.
52+
#[derive(Debug, Clone, Epserde)]
53+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5454
pub struct CsrGraph<DCF = Box<[usize]>, S = Box<[usize]>> {
5555
dcf: DCF,
5656
successors: S,
@@ -268,7 +268,7 @@ where
268268
DCF: SliceByValue + IterateByValueFrom<Item = usize>,
269269
S: SliceByValue + IterateByValueFrom<Item = usize>,
270270
{
271-
type Lender = LenderImpl<IterFrom<'a, DCF>, IterFrom<'a, S>>;
271+
type Lender = NodeLabels<IterFrom<'a, DCF>, IterFrom<'a, S>>;
272272

273273
#[inline(always)]
274274
fn into_lender(self) -> Self::Lender {
@@ -299,7 +299,7 @@ where
299299
{
300300
type Label = usize;
301301
type Lender<'a>
302-
= LenderImpl<IterFrom<'a, DCF>, IterFrom<'a, S>>
302+
= NodeLabels<IterFrom<'a, DCF>, IterFrom<'a, S>>
303303
where
304304
Self: 'a;
305305

@@ -320,7 +320,7 @@ where
320320
// because it might not exist
321321
let offset = offsets_iter.next().unwrap_or(0);
322322

323-
LenderImpl {
323+
NodeLabels {
324324
node: from,
325325
last_offset: offset,
326326
current_offset: offset,
@@ -462,7 +462,7 @@ where
462462

463463
/// Sequential Lender for the CSR graph.
464464
#[derive(Debug, Clone)]
465-
pub struct LenderImpl<O: Iterator<Item = usize>, S: Iterator<Item = usize>> {
465+
pub struct NodeLabels<O: Iterator<Item = usize>, S: Iterator<Item = usize>> {
466466
/// The next node to lend labels for.
467467
node: usize,
468468
/// This is the offset of the last successor of the previous node.
@@ -477,11 +477,11 @@ pub struct LenderImpl<O: Iterator<Item = usize>, S: Iterator<Item = usize>> {
477477
}
478478

479479
unsafe impl<O: Iterator<Item = usize>, S: Iterator<Item = usize>> SortedLender
480-
for LenderImpl<O, S>
480+
for NodeLabels<O, S>
481481
{
482482
}
483483

484-
impl<'succ, I, D> NodeLabelsLender<'succ> for LenderImpl<I, D>
484+
impl<'succ, I, D> NodeLabelsLender<'succ> for NodeLabels<I, D>
485485
where
486486
I: Iterator<Item = usize>,
487487
D: Iterator<Item = usize>,
@@ -490,15 +490,15 @@ where
490490
type IntoIterator = SeqSucc<'succ, D>;
491491
}
492492

493-
impl<'succ, I, D> Lending<'succ> for LenderImpl<I, D>
493+
impl<'succ, I, D> Lending<'succ> for NodeLabels<I, D>
494494
where
495495
I: Iterator<Item = usize>,
496496
D: Iterator<Item = usize>,
497497
{
498498
type Lend = (usize, SeqSucc<'succ, D>);
499499
}
500500

501-
impl<I, D> Lender for LenderImpl<I, D>
501+
impl<I, D> Lender for NodeLabels<I, D>
502502
where
503503
I: Iterator<Item = usize>,
504504
D: Iterator<Item = usize>,
@@ -535,7 +535,7 @@ where
535535
/// Sequential Lender for the CSR graph.
536536
#[derive(Debug, Clone)]
537537
#[repr(transparent)]
538-
pub struct LenderSortedImpl<O: Iterator<Item = usize>, S: Iterator<Item = usize>>(LenderImpl<O, S>);
538+
pub struct LenderSortedImpl<O: Iterator<Item = usize>, S: Iterator<Item = usize>>(NodeLabels<O, S>);
539539

540540
unsafe impl<O: Iterator<Item = usize>, S: Iterator<Item = usize>> SortedLender
541541
for LenderSortedImpl<O, S>

webgraph/src/graphs/union_graph.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ impl<I: Iterator<Item = usize>, J: Iterator<Item = usize>> std::iter::FusedItera
213213

214214
#[cfg(test)]
215215
mod tests {
216-
use core::panic;
217-
218216
use super::*;
219217

220218
#[test]

webgraph/src/labels/zip.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ impl<G: RandomAccessGraph, L: RandomAccessLabeling> LabeledRandomAccessGraph<L::
173173
{
174174
}
175175

176-
unsafe impl<L, R> SortedLender for NodeLabels<L, R>
177-
where
178-
L: Lender + for<'next> NodeLabelsLender<'next>,
179-
R: Lender + for<'next> NodeLabelsLender<'next>,
176+
unsafe impl<
177+
L: SortedLender + for<'next> NodeLabelsLender<'next>,
178+
R: SortedLender + for<'next> NodeLabelsLender<'next>,
179+
> SortedLender for NodeLabels<L, R>
180180
{
181181
}
182182

0 commit comments

Comments
 (0)