Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
/// assert_eq!(vec![(Vec::from("bar"), &2), ("baz".into(), &3), ("foo".into(), &1)],
/// map.iter().collect::<Vec<_>>());
/// ```
pub fn iter(&self) -> Iter<K, V> {
pub fn iter(&self) -> Iter<'_, K, V> {
Iter::new(self.tree.nodes(), Vec::new())
}

Expand All @@ -409,7 +409,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
/// }
/// assert_eq!(map.get("bar"), Some(&12));
/// ```
pub fn iter_mut(&mut self) -> IterMut<K, V> {
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
IterMut::new(self.tree.nodes_mut(), Vec::new())
}

Expand All @@ -425,7 +425,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
/// assert_eq!(vec![Vec::from("bar"), "baz".into(), "foo".into()],
/// map.keys().collect::<Vec<_>>());
/// ```
pub fn keys(&self) -> Keys<K, V> {
pub fn keys(&self) -> Keys<'_, K, V> {
Keys(self.iter())
}

Expand All @@ -441,7 +441,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
/// assert_eq!(vec![2, 3, 1],
/// map.values().cloned().collect::<Vec<_>>());
/// ```
pub fn values(&self) -> Values<V> {
pub fn values(&self) -> Values<'_, V> {
Values {
nodes: self.tree.nodes(),
}
Expand All @@ -462,7 +462,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
/// assert_eq!(vec![12, 13, 11],
/// map.values().cloned().collect::<Vec<_>>());
/// ```
pub fn values_mut(&mut self) -> ValuesMut<V> {
pub fn values_mut(&mut self) -> ValuesMut<'_, V> {
ValuesMut {
nodes: self.tree.nodes_mut(),
}
Expand Down
10 changes: 5 additions & 5 deletions src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A node which represents a subtree of a patricia tree.
use crate::BorrowedBytes;
use alloc::alloc::{alloc, dealloc, handle_alloc_error, Layout};
use alloc::alloc::{Layout, alloc, dealloc, handle_alloc_error};
use alloc::vec::Vec;
use core::marker::PhantomData;
use core::{mem, ptr, slice};
Expand Down Expand Up @@ -370,26 +370,26 @@ impl<V> Node<V> {
}

/// Gets an iterator which traverses the nodes in this tree, in depth first order.
pub fn iter(&self) -> Iter<V> {
pub fn iter(&self) -> Iter<'_, V> {
Iter {
stack: vec![(0, self)],
}
}

/// Gets a mutable iterator which traverses the nodes in this tree, in depth first order.
pub fn iter_mut(&mut self) -> IterMut<V> {
pub fn iter_mut(&mut self) -> IterMut<'_, V> {
IterMut {
stack: vec![(0, self)],
}
}

pub(crate) fn iter_descendant(&self) -> Iter<V> {
pub(crate) fn iter_descendant(&self) -> Iter<'_, V> {
Iter {
stack: vec![(0, self)],
}
}

pub(crate) fn iter_descendant_mut(&mut self) -> IterMut<V> {
pub(crate) fn iter_descendant_mut(&mut self) -> IterMut<'_, V> {
IterMut {
stack: vec![(0, self)],
}
Expand Down
4 changes: 2 additions & 2 deletions src/set.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! A set based on a patricia tree.
use crate::Bytes;
use crate::map::{self, GenericPatriciaMap};
#[cfg(any(feature = "serde", test))]
use crate::node::Node;
use crate::Bytes;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<T: Bytes> GenericPatriciaSet<T> {
///
/// assert_eq!(set.iter().collect::<Vec<_>>(), [Vec::from("bar"), "baz".into(), "foo".into()]);
/// ```
pub fn iter(&self) -> Iter<T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter(self.map.keys())
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::vec::Vec;

use crate::{
node::{self, Node, NodeMut},
BorrowedBytes,
node::{self, Node, NodeMut},
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -59,7 +59,10 @@ impl<V> PatriciaTree<V> {
.get_longest_common_prefix_mut(key, 0)
.map(|(n, v)| (&key.as_bytes()[..n], v))
}
pub fn iter_prefix<K: ?Sized + BorrowedBytes>(&self, prefix: &K) -> Option<(usize, Nodes<V>)> {
pub fn iter_prefix<K: ?Sized + BorrowedBytes>(
&self,
prefix: &K,
) -> Option<(usize, Nodes<'_, V>)> {
if let Some((common_prefix_len, node)) = self.root.get_prefix_node(prefix) {
let nodes = Nodes {
nodes: node.iter_descendant(),
Expand All @@ -73,7 +76,7 @@ impl<V> PatriciaTree<V> {
pub fn iter_prefix_mut<K: ?Sized + BorrowedBytes>(
&mut self,
prefix: &K,
) -> Option<(usize, NodesMut<V>)> {
) -> Option<(usize, NodesMut<'_, V>)> {
if let Some((common_prefix_len, node)) = self.root.get_prefix_node_mut(prefix) {
let nodes = NodesMut {
nodes: node.iter_descendant_mut(),
Expand Down Expand Up @@ -119,13 +122,13 @@ impl<V> PatriciaTree<V> {
pub fn len(&self) -> usize {
self.len
}
pub fn nodes(&self) -> Nodes<V> {
pub fn nodes(&self) -> Nodes<'_, V> {
Nodes {
nodes: self.root.iter(),
label_lens: Vec::new(),
}
}
pub fn nodes_mut(&mut self) -> NodesMut<V> {
pub fn nodes_mut(&mut self) -> NodesMut<'_, V> {
NodesMut {
nodes: self.root.iter_mut(),
label_lens: Vec::new(),
Expand Down