Update to rustfmt-preview (#348)
* Update to rustfmt-preview. * Run "cargo fmt --all" with rustfmt 0.4.1. rustfmt 0.4.1 is the latest release of rustfmt-preview available on the stable channel. * Fix a long line that rustfmt 0.4.1 can't handle. * Remove unneeded commas left behind by rustfmt.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
use super::{Comparator, Forest, Node, NodeData, NodePool, Path, INNER_SIZE};
|
||||
use packed_option::PackedOption;
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(test)]
|
||||
use std::string::String;
|
||||
|
||||
@@ -50,7 +50,9 @@ where
|
||||
{
|
||||
/// Create a new empty forest.
|
||||
pub fn new() -> Self {
|
||||
Self { nodes: NodePool::new() }
|
||||
Self {
|
||||
nodes: NodePool::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear all maps in the forest.
|
||||
@@ -101,9 +103,9 @@ where
|
||||
|
||||
/// Get the value stored for `key`.
|
||||
pub fn get(&self, key: K, forest: &MapForest<K, V, C>, comp: &C) -> Option<V> {
|
||||
self.root.expand().and_then(|root| {
|
||||
Path::default().find(key, root, &forest.nodes, comp)
|
||||
})
|
||||
self.root
|
||||
.expand()
|
||||
.and_then(|root| Path::default().find(key, root, &forest.nodes, comp))
|
||||
}
|
||||
|
||||
/// Look up the value stored for `key`.
|
||||
@@ -292,30 +294,30 @@ where
|
||||
///
|
||||
/// If the cursor is already pointing at the first entry, leave it there and return `None`.
|
||||
pub fn prev(&mut self) -> Option<(K, V)> {
|
||||
self.root.expand().and_then(
|
||||
|root| self.path.prev(root, self.pool),
|
||||
)
|
||||
self.root
|
||||
.expand()
|
||||
.and_then(|root| self.path.prev(root, self.pool))
|
||||
}
|
||||
|
||||
/// Get the current key, or `None` if the cursor is at the end.
|
||||
pub fn key(&self) -> Option<K> {
|
||||
self.path.leaf_pos().and_then(|(node, entry)| {
|
||||
self.pool[node].unwrap_leaf().0.get(entry).cloned()
|
||||
})
|
||||
self.path
|
||||
.leaf_pos()
|
||||
.and_then(|(node, entry)| self.pool[node].unwrap_leaf().0.get(entry).cloned())
|
||||
}
|
||||
|
||||
/// Get the current value, or `None` if the cursor is at the end.
|
||||
pub fn value(&self) -> Option<V> {
|
||||
self.path.leaf_pos().and_then(|(node, entry)| {
|
||||
self.pool[node].unwrap_leaf().1.get(entry).cloned()
|
||||
})
|
||||
self.path
|
||||
.leaf_pos()
|
||||
.and_then(|(node, entry)| self.pool[node].unwrap_leaf().1.get(entry).cloned())
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the current value, or `None` if the cursor is at the end.
|
||||
pub fn value_mut(&mut self) -> Option<&mut V> {
|
||||
self.path.leaf_pos().and_then(move |(node, entry)| {
|
||||
self.pool[node].unwrap_leaf_mut().1.get_mut(entry)
|
||||
})
|
||||
self.path
|
||||
.leaf_pos()
|
||||
.and_then(move |(node, entry)| self.pool[node].unwrap_leaf_mut().1.get_mut(entry))
|
||||
}
|
||||
|
||||
/// Move this cursor to `key`.
|
||||
|
||||
@@ -362,16 +362,18 @@ impl<F: Forest> NodeData<F> {
|
||||
/// right sibling node is returned.
|
||||
pub fn balance(&mut self, crit_key: F::Key, rhs: &mut Self) -> Option<F::Key> {
|
||||
match (self, rhs) {
|
||||
(&mut NodeData::Inner {
|
||||
size: ref mut l_size,
|
||||
keys: ref mut l_keys,
|
||||
tree: ref mut l_tree,
|
||||
},
|
||||
&mut NodeData::Inner {
|
||||
size: ref mut r_size,
|
||||
keys: ref mut r_keys,
|
||||
tree: ref mut r_tree,
|
||||
}) => {
|
||||
(
|
||||
&mut NodeData::Inner {
|
||||
size: ref mut l_size,
|
||||
keys: ref mut l_keys,
|
||||
tree: ref mut l_tree,
|
||||
},
|
||||
&mut NodeData::Inner {
|
||||
size: ref mut r_size,
|
||||
keys: ref mut r_keys,
|
||||
tree: ref mut r_tree,
|
||||
},
|
||||
) => {
|
||||
let l_ents = usize::from(*l_size) + 1;
|
||||
let r_ents = usize::from(*r_size) + 1;
|
||||
let ents = l_ents + r_ents;
|
||||
@@ -408,16 +410,18 @@ impl<F: Forest> NodeData<F> {
|
||||
Some(new_crit)
|
||||
}
|
||||
}
|
||||
(&mut NodeData::Leaf {
|
||||
size: ref mut l_size,
|
||||
keys: ref mut l_keys,
|
||||
vals: ref mut l_vals,
|
||||
},
|
||||
&mut NodeData::Leaf {
|
||||
size: ref mut r_size,
|
||||
keys: ref mut r_keys,
|
||||
vals: ref mut r_vals,
|
||||
}) => {
|
||||
(
|
||||
&mut NodeData::Leaf {
|
||||
size: ref mut l_size,
|
||||
keys: ref mut l_keys,
|
||||
vals: ref mut l_vals,
|
||||
},
|
||||
&mut NodeData::Leaf {
|
||||
size: ref mut r_size,
|
||||
keys: ref mut r_keys,
|
||||
vals: ref mut r_vals,
|
||||
},
|
||||
) => {
|
||||
let l_ents = usize::from(*l_size);
|
||||
let l_keys = l_keys.borrow_mut();
|
||||
let l_vals = l_vals.borrow_mut();
|
||||
@@ -677,11 +681,7 @@ mod test {
|
||||
assert!(leaf.try_leaf_insert(2, 'c', SetValue()));
|
||||
assert_eq!(leaf.to_string(), "[ a b c d ]");
|
||||
for i in 4..15 {
|
||||
assert!(leaf.try_leaf_insert(
|
||||
usize::from(i),
|
||||
('a' as u8 + i) as char,
|
||||
SetValue(),
|
||||
));
|
||||
assert!(leaf.try_leaf_insert(usize::from(i), ('a' as u8 + i) as char, SetValue()));
|
||||
}
|
||||
assert_eq!(leaf.to_string(), "[ a b c d e f g h i j k l m n o ]");
|
||||
|
||||
@@ -779,21 +779,13 @@ mod test {
|
||||
fn leaf_balance() {
|
||||
let mut lhs = NodeData::<TF>::leaf('a', SetValue());
|
||||
for i in 1..6 {
|
||||
assert!(lhs.try_leaf_insert(
|
||||
usize::from(i),
|
||||
('a' as u8 + i) as char,
|
||||
SetValue(),
|
||||
));
|
||||
assert!(lhs.try_leaf_insert(usize::from(i), ('a' as u8 + i) as char, SetValue()));
|
||||
}
|
||||
assert_eq!(lhs.to_string(), "[ a b c d e f ]");
|
||||
|
||||
let mut rhs = NodeData::<TF>::leaf('0', SetValue());
|
||||
for i in 1..8 {
|
||||
assert!(rhs.try_leaf_insert(
|
||||
usize::from(i),
|
||||
('0' as u8 + i) as char,
|
||||
SetValue(),
|
||||
));
|
||||
assert!(rhs.try_leaf_insert(usize::from(i), ('0' as u8 + i) as char, SetValue()));
|
||||
}
|
||||
assert_eq!(rhs.to_string(), "[ 0 1 2 3 4 5 6 7 ]");
|
||||
|
||||
|
||||
@@ -303,9 +303,9 @@ impl<F: Forest> Path<F> {
|
||||
// When inserting into an inner node (`ins_node.is_some()`), we must point to a valid
|
||||
// entry in the current node since the new entry is inserted *after* the insert
|
||||
// location.
|
||||
if entry > split.lhs_entries ||
|
||||
(entry == split.lhs_entries &&
|
||||
(split.lhs_entries > split.rhs_entries || ins_node.is_some()))
|
||||
if entry > split.lhs_entries
|
||||
|| (entry == split.lhs_entries
|
||||
&& (split.lhs_entries > split.rhs_entries || ins_node.is_some()))
|
||||
{
|
||||
node = rhs_node;
|
||||
entry -= split.lhs_entries;
|
||||
@@ -406,7 +406,9 @@ impl<F: Forest> Path<F> {
|
||||
let crit_node = self.node[crit_level];
|
||||
|
||||
match pool[crit_node] {
|
||||
NodeData::Inner { size, ref mut keys, .. } => {
|
||||
NodeData::Inner {
|
||||
size, ref mut keys, ..
|
||||
} => {
|
||||
debug_assert!(crit_kidx < size);
|
||||
keys[usize::from(crit_kidx)] = crit_key;
|
||||
}
|
||||
@@ -436,7 +438,10 @@ impl<F: Forest> Path<F> {
|
||||
|
||||
// Discard the root node if it has shrunk to a single sub-tree.
|
||||
let mut ns = 0;
|
||||
while let NodeData::Inner { size: 0, ref tree, .. } = pool[self.node[ns]] {
|
||||
while let NodeData::Inner {
|
||||
size: 0, ref tree, ..
|
||||
} = pool[self.node[ns]]
|
||||
{
|
||||
ns += 1;
|
||||
self.node[ns] = tree[0];
|
||||
}
|
||||
@@ -616,9 +621,8 @@ impl<F: Forest> Path<F> {
|
||||
|
||||
/// Update the critical key for the right sibling node at `level`.
|
||||
fn update_right_crit_key(&self, level: usize, crit_key: F::Key, pool: &mut NodePool<F>) {
|
||||
let bl = self.right_sibling_branch_level(level, pool).expect(
|
||||
"No right sibling exists",
|
||||
);
|
||||
let bl = self.right_sibling_branch_level(level, pool)
|
||||
.expect("No right sibling exists");
|
||||
match pool[self.node[bl]] {
|
||||
NodeData::Inner { ref mut keys, .. } => {
|
||||
keys[usize::from(self.entry[bl])] = crit_key;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
use super::{Forest, Node, NodeData};
|
||||
use entity::PrimaryMap;
|
||||
use std::ops::{Index, IndexMut};
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
/// A pool of nodes, including a free list.
|
||||
pub(super) struct NodePool<F: Forest> {
|
||||
@@ -51,7 +51,9 @@ impl<F: Forest> NodePool<F> {
|
||||
pub fn free_node(&mut self, node: Node) {
|
||||
// Quick check for a double free.
|
||||
debug_assert!(!self.nodes[node].is_free(), "{} is already free", node);
|
||||
self.nodes[node] = NodeData::Free { next: self.freelist };
|
||||
self.nodes[node] = NodeData::Free {
|
||||
next: self.freelist,
|
||||
};
|
||||
self.freelist = Some(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
use super::{Comparator, Forest, Node, NodeData, NodePool, Path, SetValue, INNER_SIZE};
|
||||
use packed_option::PackedOption;
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(test)]
|
||||
use std::string::String;
|
||||
|
||||
@@ -47,7 +47,9 @@ where
|
||||
{
|
||||
/// Create a new empty forest.
|
||||
pub fn new() -> Self {
|
||||
Self { nodes: NodePool::new() }
|
||||
Self {
|
||||
nodes: NodePool::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear all sets in the forest.
|
||||
@@ -232,16 +234,16 @@ where
|
||||
///
|
||||
/// If the cursor is already pointing at the first element, leave it there and return `None`.
|
||||
pub fn prev(&mut self) -> Option<K> {
|
||||
self.root.expand().and_then(|root| {
|
||||
self.path.prev(root, self.pool).map(|(k, _)| k)
|
||||
})
|
||||
self.root
|
||||
.expand()
|
||||
.and_then(|root| self.path.prev(root, self.pool).map(|(k, _)| k))
|
||||
}
|
||||
|
||||
/// Get the current element, or `None` if the cursor is at the end.
|
||||
pub fn elem(&self) -> Option<K> {
|
||||
self.path.leaf_pos().and_then(|(node, entry)| {
|
||||
self.pool[node].unwrap_leaf().0.get(entry).cloned()
|
||||
})
|
||||
self.path
|
||||
.leaf_pos()
|
||||
.and_then(|(node, entry)| self.pool[node].unwrap_leaf().0.get(entry).cloned())
|
||||
}
|
||||
|
||||
/// Move this cursor to `elem`.
|
||||
|
||||
Reference in New Issue
Block a user