Skip to content

Commit ead0fdf

Browse files
committed
Better names
1 parent 373c150 commit ead0fdf

File tree

12 files changed

+71
-60
lines changed

12 files changed

+71
-60
lines changed

algo/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [0.3.0] -
4+
5+
### Changed
6+
7+
* Visits have been moved to the main WebGraph crate.
8+
39
## [0.2.0] - 2025-05-23
410

511
### Changed

algo/src/distances/exact_sum_sweep/computer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<
508508
[v],
509509
pl.clone(),
510510
|pl, event| {
511-
if let EventNoPred::Unknown { node, .. } = event {
511+
if let EventNoPred::Visit { node, .. } = event {
512512
pl.light_update();
513513
radial_vertices.set(node, true, Ordering::Relaxed)
514514
}
@@ -576,7 +576,7 @@ impl<
576576
[start],
577577
pl.clone(),
578578
|pl, event| {
579-
if let EventNoPred::Unknown { node, distance, .. } = event {
579+
if let EventNoPred::Visit { node, distance, .. } = event {
580580
pl.light_update();
581581
// Safety for unsafe blocks: each node gets accessed exactly once, so no data races can happen
582582
max_dist.fetch_max(distance, Ordering::Relaxed);
@@ -655,7 +655,7 @@ impl<
655655
[start],
656656
pl.clone(),
657657
|pl, event| {
658-
if let EventNoPred::Unknown { node, distance, .. } = event {
658+
if let EventNoPred::Visit { node, distance, .. } = event {
659659
// SAFETY: each node gets accessed exactly once, so no data races can happen
660660
pl.light_update();
661661
max_dist.fetch_max(distance, Ordering::Relaxed);
@@ -759,7 +759,7 @@ impl<
759759
bfs.par_visit_filtered(
760760
[p],
761761
|event| {
762-
if let EventNoPred::Unknown { node, distance, .. } = event {
762+
if let EventNoPred::Visit { node, distance, .. } = event {
763763
// Safety: each node is accessed exactly once
764764
unsafe { dist_pivot_mut[node].set(distance) };
765765
component_ecc_pivot.store(distance, Ordering::Relaxed);

algo/src/sccs/symm_par.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn symm_par(
4747
|pl, event| {
4848
match event {
4949
EventNoPred::Init { .. } => {}
50-
EventNoPred::Unknown { node, .. } => {
50+
EventNoPred::Visit { node, .. } => {
5151
pl.light_update();
5252
unsafe {
5353
slice[node].set(MaybeUninit::new(

algo/src/sccs/tarjan.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ pub fn tarjan(graph: impl RandomAccessGraph, pl: &mut impl ProgressLog) -> Sccs
7676
}
7777
}
7878
}
79-
EventPred::Postvisit { node, pred, .. } => {
79+
EventPred::Postvisit {
80+
node, parent: pred, ..
81+
} => {
8082
// Safe as the stack is never empty
8183
if lead.pop().unwrap() {
8284
// Set the component index of nodes in the component

algo/src/visits/breadth_first/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! Note that since [`EventPred`] contains the predecessor of the visited node,
1616
//! all post-initialization visit events can be interpreted as arc events. The
17-
//! only exception is the [`Unknown`](EventPred::Unknown) event at the root.
17+
//! only exception is the [`Visit`](EventPred::Visit) event at the root.
1818
1919
mod seq;
2020
pub use seq::*;
@@ -36,10 +36,12 @@ pub enum EventPred {
3636
Init {},
3737
/// The node has been encountered for the first time: we are traversing a
3838
/// new tree arc, unless all node fields are equal to the root.
39-
Unknown {
39+
Visit {
4040
/// The current node.
4141
node: usize,
42-
/// The predecessor of [node](`EventPred::Unknown::node`).
42+
/// The parent of [node](`EventPred::Visit::node`) in the visit tree,
43+
/// or [`node`](`EventPred::Visit::node`) if
44+
/// [`node`](`EventPred::Visit::node`) is one of the roots.
4345
pred: usize,
4446
/// The distance of the current node from the roots.
4547
distance: usize,
@@ -48,12 +50,12 @@ pub enum EventPred {
4850
/// forward arc, or a cross arc.
4951
///
5052
/// Note however that in parallel contexts it might happen that callback
51-
/// with event [`Unknown`](`EventPred::Unknown`) has not been called yet by
53+
/// with event [`Visit`](`EventPred::Visit`) has not been called yet by
5254
/// the thread who discovered the node.
53-
Known {
55+
Revisit {
5456
/// The current node.
5557
node: usize,
56-
/// The predecessor of [node](`EventPred::Known::node`).
58+
/// The predecessor of [node](`EventPred::Revisit::node`).
5759
pred: usize,
5860
},
5961
/// The size of the frontier at a given distance.
@@ -108,8 +110,8 @@ pub enum EventNoPred {
108110
/// is, all of the roots are already visited or filtered.
109111
Init {},
110112
/// The node has been encountered for the first time: we are traversing a
111-
/// new tree arc, unless all node fields are equal to the root.
112-
Unknown {
113+
/// new tree arc, unless the node is one of the roots.
114+
Visit {
113115
/// The current node.
114116
node: usize,
115117
/// The distance of the current node from the roots.
@@ -121,7 +123,7 @@ pub enum EventNoPred {
121123
/// Note however that in parallel contexts it might happen that callback
122124
/// with event [`Unknown`](`EventNoPred::Unknown`) has not been called yet
123125
/// by the thread who discovered the node.
124-
Known {
126+
Revisit {
125127
/// The current node.
126128
node: usize,
127129
},

algo/src/visits/breadth_first/par_fair.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<G: RandomAccessGraph + Sync> Parallel<EventNoPred> for ParFair<G, false> {
202202
.chunks(self.granularity)
203203
.try_for_each_with(init.clone(), |init, chunk| {
204204
chunk.into_iter().try_for_each(|&node| {
205-
callback(init, EventNoPred::Unknown { node, distance })?;
205+
callback(init, EventNoPred::Visit { node, distance })?;
206206
self.graph
207207
.successors(node)
208208
.into_iter()
@@ -219,7 +219,7 @@ impl<G: RandomAccessGraph + Sync> Parallel<EventNoPred> for ParFair<G, false> {
219219
if !self.visited.swap(succ, true, Ordering::Relaxed) {
220220
next_frontier.push(succ);
221221
} else {
222-
callback(init, EventNoPred::Known { node })?;
222+
callback(init, EventNoPred::Revisit { node })?;
223223
}
224224
}
225225

@@ -313,7 +313,7 @@ impl<G: RandomAccessGraph + Sync> Parallel<EventPred> for ParFair<G, true> {
313313
chunk.into_iter().try_for_each(|&(node, pred)| {
314314
callback(
315315
init,
316-
EventPred::Unknown {
316+
EventPred::Visit {
317317
node,
318318
pred,
319319
distance,
@@ -335,7 +335,7 @@ impl<G: RandomAccessGraph + Sync> Parallel<EventPred> for ParFair<G, true> {
335335
if !self.visited.swap(succ, true, Ordering::Relaxed) {
336336
next_frontier.push((node, pred));
337337
} else {
338-
callback(init, EventPred::Known { node, pred })?;
338+
callback(init, EventPred::Revisit { node, pred })?;
339339
}
340340
}
341341

algo/src/visits/breadth_first/par_low_mem.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use webgraph::{traits::RandomAccessGraph, utils::Granularity};
6060
/// |event|
6161
/// {
6262
/// // Store the parent
63-
/// if let EventPred::Unknown { node, pred, ..} = event {
63+
/// if let EventPred::Visit { node, pred, ..} = event {
6464
/// // There will be exactly one set for each node
6565
/// unsafe { tree_sync[node].set(pred) };
6666
/// }
@@ -155,7 +155,7 @@ impl<G: RandomAccessGraph + Sync> Parallel<EventPred> for ParLowMem<G> {
155155

156156
callback(
157157
&mut init,
158-
EventPred::Unknown {
158+
EventPred::Visit {
159159
node: root,
160160
pred: root,
161161
distance: 0,
@@ -206,15 +206,15 @@ impl<G: RandomAccessGraph + Sync> Parallel<EventPred> for ParLowMem<G> {
206206
if !self.visited.swap(succ, true, Ordering::Relaxed) {
207207
callback(
208208
init,
209-
EventPred::Unknown {
209+
EventPred::Visit {
210210
node,
211211
pred,
212212
distance,
213213
},
214214
)?;
215215
next_frontier.push(succ);
216216
} else {
217-
callback(init, EventPred::Known { node, pred })?;
217+
callback(init, EventPred::Revisit { node, pred })?;
218218
}
219219
}
220220

algo/src/visits/breadth_first/seq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use webgraph::traits::{RandomAccessGraph, RandomAccessLabeling};
6060
/// minimize resource usage, we count nodes in the filter function, rather than
6161
/// as the result of an event. In this way, node at distance two are counted but
6262
/// not included in the queue, as it would happen if we were counting during an
63-
/// [`EventPred::Unknown`] event.
63+
/// [`EventPred::Visit`] event.
6464
///
6565
/// ```
6666
/// use std::convert::Infallible;
@@ -169,7 +169,7 @@ impl<'a, G: RandomAccessGraph> Sequential<EventPred> for Seq<'a, G> {
169169

170170
callback(
171171
&mut init,
172-
EventPred::Unknown {
172+
EventPred::Visit {
173173
node: root,
174174
pred: root,
175175
distance: 0,
@@ -212,7 +212,7 @@ impl<'a, G: RandomAccessGraph> Sequential<EventPred> for Seq<'a, G> {
212212
self.visited.set(succ, true);
213213
callback(
214214
&mut init,
215-
EventPred::Unknown {
215+
EventPred::Visit {
216216
node,
217217
pred,
218218

@@ -225,7 +225,7 @@ impl<'a, G: RandomAccessGraph> Sequential<EventPred> for Seq<'a, G> {
225225
))
226226
}
227227
} else {
228-
callback(&mut init, EventPred::Known { node, pred })?;
228+
callback(&mut init, EventPred::Revisit { node, pred })?;
229229
}
230230
}
231231
}

algo/src/visits/depth_first/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum EventNoPred {
4141
root: usize,
4242
/// The depth of the visit, that is, the length of the visit path from
4343
/// the [root](`EventNoPred::Previsit::root`) to
44-
/// [node](`EventNoPred::Previsit::node`).
44+
/// [`node`](`EventNoPred::Previsit::node`).
4545
depth: usize,
4646
},
4747
/// The node has been encountered before: we are traversing a back arc, a
@@ -53,7 +53,7 @@ pub enum EventNoPred {
5353
root: usize,
5454
/// The depth of the visit, that is, the length of the visit path from
5555
/// the [root](`EventNoPred::Revisit::root`) to
56-
/// [node](`EventNoPred::Revisit::node`).
56+
/// [`node`](`EventNoPred::Revisit::node`).
5757
depth: usize,
5858
},
5959
/// The visit has been completed.
@@ -75,7 +75,7 @@ pub struct FilterArgsNoPred {
7575
/// The root of the current visit tree.
7676
pub root: usize,
7777
/// The depth of the visit, that is, the length of the visit path from the
78-
/// [root](`Self::root`) to [node](`Self::node`).
78+
/// [root](`Self::root`) to [`node`](`Self::node`).
7979
pub depth: usize,
8080
}
8181

@@ -101,20 +101,23 @@ pub enum EventPred {
101101
Previsit {
102102
/// The current node.
103103
node: usize,
104-
/// The parent of [node](`EventPred::Previsit::node`) in the visit tree.
105-
pred: usize,
104+
/// The parent of [`node`](`EventPred::Previsit::node`) in the visit
105+
/// tree, or [`root`](`EventPred::Previsit::root`) if
106+
/// [`node`](`EventPred::Previsit::node`) is the root.
107+
parent: usize,
106108
/// The root of the current visit tree.
107109
root: usize,
108110
/// The depth of the visit, that is, the length of the visit path from the
109-
/// [root](`EventPred::Previsit::root`) to [node](`EventPred::Previsit::node`).
111+
/// [root](`EventPred::Previsit::root`) to [`node`](`EventPred::Previsit::node`).
110112
depth: usize,
111113
},
112114
/// The node has been encountered before: we are traversing a back arc, a
113115
/// forward arc, or a cross arc.
114116
Revisit {
115117
/// The current node.
116118
node: usize,
117-
/// The parent of [node](`EventPred::Revisit::node`) in the visit tree.
119+
/// The predecessor of [`node`](`EventPred::Revisit::node`) used to
120+
/// reach it.
118121
pred: usize,
119122
/// The root of the current visit tree.
120123
root: usize,
@@ -132,13 +135,15 @@ pub enum EventPred {
132135
Postvisit {
133136
/// The current node.
134137
node: usize,
135-
/// The parent of [curr](`EventPred::Postvisit::node`) in the visit tree.
136-
pred: usize,
138+
/// The parent of [`node`](`EventPred::Postvisit::node`) in the visit
139+
/// tree, or [`root`](`EventPred::Postvisit::root`) if
140+
/// [`node`](`EventPred::Postvisit::node`) is the root.
141+
parent: usize,
137142
/// The root of the current visit tree.
138143
root: usize,
139144
/// The depth of the visit, that is, the length of the visit path from
140145
/// the [root](`EventPred::Postvisit::root`) to
141-
/// [node](`EventPred::Postvisit::node`).
146+
/// [`node`](`EventPred::Postvisit::node`).
142147
depth: usize,
143148
},
144149
/// The visit has been completed.
@@ -157,12 +162,13 @@ pub enum EventPred {
157162
pub struct FilterArgsPred {
158163
/// The current node.
159164
pub node: usize,
160-
/// The parent of [node](`Self::node`) in the visit tree.
165+
/// The parent of [`node`](`Self::node`) in the visit tree, or
166+
/// [`root`](Self::root) if [`node`](`Self::node`) is the root.
161167
pub pred: usize,
162168
/// The root of the current visit tree.
163169
pub root: usize,
164170
/// The depth of the visit, that is, the length of the visit path from the
165-
/// [root](`Self::root`) to [node](`Self::node`).
171+
/// [root](`Self::root`) to [`node`](`Self::node`).
166172
pub depth: usize,
167173
}
168174

algo/src/visits/depth_first/seq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<S: NodeStates, G: RandomAccessGraph> Sequential<EventPred> for SeqIter<'_,
333333
&mut init,
334334
EventPred::Previsit {
335335
node: root,
336-
pred: root,
336+
parent: root,
337337
root,
338338
depth: 0,
339339
},
@@ -385,7 +385,7 @@ impl<S: NodeStates, G: RandomAccessGraph> Sequential<EventPred> for SeqIter<'_,
385385
&mut init,
386386
EventPred::Previsit {
387387
node: succ,
388-
pred: curr,
388+
parent: curr,
389389
root,
390390
depth,
391391
},
@@ -408,7 +408,7 @@ impl<S: NodeStates, G: RandomAccessGraph> Sequential<EventPred> for SeqIter<'_,
408408
&mut init,
409409
EventPred::Postvisit {
410410
node: curr,
411-
pred: *parent,
411+
parent: *parent,
412412
root,
413413
depth: depth - 1,
414414
},

0 commit comments

Comments
 (0)