Greatly simplify lifetime captures in edition 2024
This commit is contained in:
parent
46420c9607
commit
12e3911d81
84 changed files with 223 additions and 294 deletions
|
@ -193,11 +193,11 @@ impl<N: Debug, E: Debug> Graph<N, E> {
|
|||
AdjacentEdges { graph: self, direction, next: first_edge }
|
||||
}
|
||||
|
||||
pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
|
||||
pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> {
|
||||
self.outgoing_edges(source).targets()
|
||||
}
|
||||
|
||||
pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
|
||||
pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> {
|
||||
self.incoming_edges(target).sources()
|
||||
}
|
||||
|
||||
|
@ -255,11 +255,11 @@ pub struct AdjacentEdges<'g, N, E> {
|
|||
}
|
||||
|
||||
impl<'g, N: Debug, E: Debug> AdjacentEdges<'g, N, E> {
|
||||
fn targets(self) -> impl Iterator<Item = NodeIndex> + 'g {
|
||||
fn targets(self) -> impl Iterator<Item = NodeIndex> {
|
||||
self.map(|(_, edge)| edge.target)
|
||||
}
|
||||
|
||||
fn sources(self) -> impl Iterator<Item = NodeIndex> + 'g {
|
||||
fn sources(self) -> impl Iterator<Item = NodeIndex> {
|
||||
self.map(|(_, edge)| edge.source)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ impl<N: Idx, S: Idx + Ord, A: Annotation> Sccs<N, S, A> {
|
|||
/// meaning that if `S1 -> S2`, we will visit `S2` first and `S1` after.
|
||||
/// This is convenient when the edges represent dependencies: when you visit
|
||||
/// `S1`, the value for `S2` will already have been computed.
|
||||
pub fn all_sccs(&self) -> impl Iterator<Item = S> + use<N, S, A> {
|
||||
pub fn all_sccs(&self) -> impl Iterator<Item = S> + 'static {
|
||||
(0..self.scc_data.len()).map(S::new)
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
|
|||
/// If there are multiple items that are equivalent to `key`, they will be yielded in
|
||||
/// insertion order.
|
||||
#[inline]
|
||||
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> + '_ {
|
||||
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> {
|
||||
self.get_by_key_enumerated(key).map(|(_, v)| v)
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
|
|||
/// If there are multiple items that are equivalent to `key`, they will be yielded in
|
||||
/// insertion order.
|
||||
#[inline]
|
||||
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> + '_ {
|
||||
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> {
|
||||
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
|
||||
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
|
||||
let (k, v) = &self.items[i];
|
||||
|
|
|
@ -165,7 +165,7 @@ impl<K, V> SsoHashMap<K, V> {
|
|||
|
||||
/// Clears the map, returning all key-value pairs as an iterator. Keeps the
|
||||
/// allocated memory for reuse.
|
||||
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_ {
|
||||
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> {
|
||||
match self {
|
||||
SsoHashMap::Array(array) => Either::Left(array.drain(..)),
|
||||
SsoHashMap::Map(map) => Either::Right(map.drain()),
|
||||
|
|
|
@ -80,7 +80,7 @@ impl<T> SsoHashSet<T> {
|
|||
|
||||
/// Clears the set, returning all elements in an iterator.
|
||||
#[inline]
|
||||
pub fn drain(&mut self) -> impl Iterator<Item = T> + '_ {
|
||||
pub fn drain(&mut self) -> impl Iterator<Item = T> {
|
||||
self.map.drain().map(entry_to_key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,14 +45,14 @@ impl<T: Copy> AppendOnlyVec<T> {
|
|||
self.vec.read().get(i).copied()
|
||||
}
|
||||
|
||||
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> + '_ {
|
||||
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> {
|
||||
(0..)
|
||||
.map(|i| (i, self.get(i)))
|
||||
.take_while(|(_, o)| o.is_some())
|
||||
.filter_map(|(i, o)| Some((i, o?)))
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = T> + '_ {
|
||||
pub fn iter(&self) -> impl Iterator<Item = T> {
|
||||
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -363,7 +363,7 @@ impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
|
|||
|
||||
/// Lists all the base edges in the graph: the initial _non-transitive_ set of element
|
||||
/// relations, which will be later used as the basis for the transitive closure computation.
|
||||
pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> + '_ {
|
||||
pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> {
|
||||
self.edges
|
||||
.iter()
|
||||
.map(move |edge| (self.elements[edge.source.0], self.elements[edge.target.0]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue