Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dca037d
Iterative version of some fork-tree methods
davxy Apr 5, 2022
1e746fc
Prune doesn't require its generic args to be 'clone'
davxy Apr 6, 2022
23cc533
Fork-tree import and drain-filter iterative implementations
davxy Apr 14, 2022
47d1759
Fork-tree map iterative implementation
davxy Apr 15, 2022
6477e73
Merge branch 'master' into davxy-iterative-fork-tree-methods
davxy Apr 15, 2022
acdbbb5
Optimization of some operations, e.g. rebalance only when required
davxy Apr 15, 2022
a090eb1
Destructuring assignments not supported by stable rustc 1.57
davxy Apr 15, 2022
051ac86
Nitpicks
davxy Apr 15, 2022
9163787
Safe implementation of 'map' and 'drain_filter' methods
davxy Apr 22, 2022
406b526
Remove dummy comment
davxy Apr 22, 2022
b79c4cf
Merge branch 'master' into davxy-iterative-fork-tree-methods
davxy Apr 22, 2022
9f8fd20
Trigger CI pipeline
davxy Apr 23, 2022
1dde93b
Test map for multi-root fork-tree and refactory of `find_node_index_w…
davxy Apr 26, 2022
7d8c7a3
Fix find node index with predicate
davxy Apr 28, 2022
29215b5
Nits
davxy Apr 28, 2022
e0e2d70
Merge branch 'master' into davxy-iterative-fork-tree-methods
davxy Apr 28, 2022
182d073
Tree traversal algorithm is not specified
davxy Apr 29, 2022
9cc8b51
Move unspecified tree traversal warning to 'map'
davxy Apr 29, 2022
f6d04e1
Immutable 'drain_filter' predicate
davxy Apr 29, 2022
863105f
Apply suggestions from code review
davxy May 10, 2022
bc5d9fb
Apply suggestions from code review
davxy May 10, 2022
f0269d4
Remove double mapping
davxy May 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Immutable 'drain_filter' predicate
  • Loading branch information
davxy committed Apr 29, 2022
commit f6d04e12c12f9db275db25815417d34796fce35f
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/authorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ where
where
F: Fn(&H, &H) -> Result<bool, E>,
{
let mut filter = |node_hash: &H, node_num: &N, _: &PendingChange<H, N>| {
let filter = |node_hash: &H, node_num: &N, _: &PendingChange<H, N>| {
if number >= *node_num &&
(is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
{
Expand All @@ -245,7 +245,7 @@ where
};

// Remove standard changes.
let _ = self.pending_standard_changes.drain_filter(&mut filter);
let _ = self.pending_standard_changes.drain_filter(&filter);

// Remove forced changes.
self.pending_forced_changes
Expand Down
6 changes: 4 additions & 2 deletions utils/fork-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,16 @@ where
}

/// Remove from the tree some nodes (and their subtrees) using a `filter` predicate.
///
/// The `filter` is called over tree nodes and returns a filter action:
/// - `Remove` if the node and its subtree should be removed;
/// - `KeepNode` if we should maintain the node and keep processing the tree.
/// - `KeepTree` if we should maintain the node and its entire subtree.
///
/// An iterator over all the pruned nodes is returned.
pub fn drain_filter<F>(&mut self, mut filter: F) -> impl Iterator<Item = (H, N, V)>
pub fn drain_filter<F>(&mut self, filter: F) -> impl Iterator<Item = (H, N, V)>
where
F: FnMut(&H, &N, &V) -> FilterAction,
F: Fn(&H, &N, &V) -> FilterAction,
{
let mut removed = vec![];
let mut retained = Vec::new();
Expand Down