Remove the "BPlus" prefix from bforest::* types.

We'll just use the bforest:: namespace for these types, avoiding the
confusing mix of prefixed and non-prefixed names.

No functional change intended.
This commit is contained in:
Jakob Stoklund Olesen
2017-11-20 14:09:25 -08:00
parent d51a4c1065
commit d3778e56bb
5 changed files with 61 additions and 61 deletions

View File

@@ -2,7 +2,7 @@
use packed_option::PackedOption; use packed_option::PackedOption;
use std::marker::PhantomData; use std::marker::PhantomData;
use super::{INNER_SIZE, BPlusComparator, Forest, NodePool, Node, NodeData, Path}; use super::{INNER_SIZE, Comparator, Forest, NodePool, Node, NodeData, Path};
/// Tag type defining forest types for a map. /// Tag type defining forest types for a map.
struct MapTypes<K, V, C>(PhantomData<(K, V, C)>); struct MapTypes<K, V, C>(PhantomData<(K, V, C)>);
@@ -11,7 +11,7 @@ impl<K, V, C> Forest for MapTypes<K, V, C>
where where
K: Copy, K: Copy,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
type Key = K; type Key = K;
type Value = V; type Value = V;
@@ -28,12 +28,12 @@ where
} }
} }
/// Memory pool for a forest of `BPlusMap` instances. /// Memory pool for a forest of `Map` instances.
pub struct MapForest<K, V, C> pub struct MapForest<K, V, C>
where where
K: Copy, K: Copy,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
nodes: NodePool<MapTypes<K, V, C>>, nodes: NodePool<MapTypes<K, V, C>>,
} }
@@ -42,7 +42,7 @@ impl<K, V, C> MapForest<K, V, C>
where where
K: Copy, K: Copy,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Create a new empty forest. /// Create a new empty forest.
pub fn new() -> MapForest<K, V, C> { pub fn new() -> MapForest<K, V, C> {
@@ -51,7 +51,7 @@ where
/// Clear all maps in the forest. /// Clear all maps in the forest.
/// ///
/// All `BPlusMap` instances belong to this forest are invalidated and should no longer be used. /// All `Map` instances belong to this forest are invalidated and should no longer be used.
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.nodes.clear(); self.nodes.clear();
} }
@@ -61,25 +61,25 @@ where
/// ///
/// This is not a general-purpose replacement for `BTreeMap`. See the [module /// This is not a general-purpose replacement for `BTreeMap`. See the [module
/// documentation](index.html) for more information about design tradeoffs. /// documentation](index.html) for more information about design tradeoffs.
pub struct BPlusMap<K, V, C> pub struct Map<K, V, C>
where where
K: Copy, K: Copy,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
root: PackedOption<Node>, root: PackedOption<Node>,
unused: PhantomData<(K, V, C)>, unused: PhantomData<(K, V, C)>,
} }
impl<K, V, C> BPlusMap<K, V, C> impl<K, V, C> Map<K, V, C>
where where
K: Copy, K: Copy,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Make an empty map. /// Make an empty map.
pub fn new() -> BPlusMap<K, V, C> { pub fn new() -> Map<K, V, C> {
BPlusMap { Map {
root: None.into(), root: None.into(),
unused: PhantomData, unused: PhantomData,
} }
@@ -130,11 +130,11 @@ where
} }
#[cfg(test)] #[cfg(test)]
impl<K, V, C> BPlusMap<K, V, C> impl<K, V, C> Map<K, V, C>
where where
K: Copy + ::std::fmt::Display, K: Copy + ::std::fmt::Display,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Verify consistency. /// Verify consistency.
fn verify(&self, forest: &MapForest<K, V, C>, comp: &C) fn verify(&self, forest: &MapForest<K, V, C>, comp: &C)
@@ -159,7 +159,7 @@ where
} }
} }
/// A position in a `BPlusMap` used to navigate and modify the ordered map. /// A position in a `Map` used to navigate and modify the ordered map.
/// ///
/// A cursor always points at a key-value pair in the map, or "off the end" which is a position /// A cursor always points at a key-value pair in the map, or "off the end" which is a position
/// after the last entry in the map. /// after the last entry in the map.
@@ -167,7 +167,7 @@ pub struct MapCursor<'a, K, V, C>
where where
K: 'a + Copy, K: 'a + Copy,
V: 'a + Copy, V: 'a + Copy,
C: 'a + BPlusComparator<K>, C: 'a + Comparator<K>,
{ {
root: &'a mut PackedOption<Node>, root: &'a mut PackedOption<Node>,
pool: &'a mut NodePool<MapTypes<K, V, C>>, pool: &'a mut NodePool<MapTypes<K, V, C>>,
@@ -179,11 +179,11 @@ impl<'a, K, V, C> MapCursor<'a, K, V, C>
where where
K: Copy, K: Copy,
V: Copy, V: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Create a cursor with a default (off-the-end) location. /// Create a cursor with a default (off-the-end) location.
fn new( fn new(
container: &'a mut BPlusMap<K, V, C>, container: &'a mut Map<K, V, C>,
forest: &'a mut MapForest<K, V, C>, forest: &'a mut MapForest<K, V, C>,
comp: &'a C, comp: &'a C,
) -> MapCursor<'a, K, V, C> { ) -> MapCursor<'a, K, V, C> {
@@ -289,7 +289,7 @@ impl<'a, K, V, C> MapCursor<'a, K, V, C>
where where
K: Copy + ::std::fmt::Display, K: Copy + ::std::fmt::Display,
V: Copy + ::std::fmt::Display, V: Copy + ::std::fmt::Display,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
fn verify(&self) { fn verify(&self) {
self.path.verify(self.pool); self.path.verify(self.pool);
@@ -320,7 +320,7 @@ mod test {
let mut f = MapForest::<u32, f32, ()>::new(); let mut f = MapForest::<u32, f32, ()>::new();
f.clear(); f.clear();
let mut m = BPlusMap::<u32, f32, ()>::new(); let mut m = Map::<u32, f32, ()>::new();
assert!(m.is_empty()); assert!(m.is_empty());
assert_eq!(m.get(7, &f, &()), None); assert_eq!(m.get(7, &f, &()), None);
@@ -338,7 +338,7 @@ mod test {
#[test] #[test]
fn inserting() { fn inserting() {
let f = &mut MapForest::<u32, f32, ()>::new(); let f = &mut MapForest::<u32, f32, ()>::new();
let mut m = BPlusMap::<u32, f32, ()>::new(); let mut m = Map::<u32, f32, ()>::new();
// The first seven values stay in a single leaf node. // The first seven values stay in a single leaf node.
assert_eq!(m.insert(50, 5.0, f, &()), None); assert_eq!(m.insert(50, 5.0, f, &()), None);
@@ -428,8 +428,8 @@ mod test {
// Various ways of splitting a full leaf node at level 0. // Various ways of splitting a full leaf node at level 0.
let f = &mut MapForest::<u32, f32, ()>::new(); let f = &mut MapForest::<u32, f32, ()>::new();
fn full_leaf(f: &mut MapForest<u32, f32, ()>) -> BPlusMap<u32, f32, ()> { fn full_leaf(f: &mut MapForest<u32, f32, ()>) -> Map<u32, f32, ()> {
let mut m = BPlusMap::new(); let mut m = Map::new();
for n in 1..8 { for n in 1..8 {
m.insert(n * 10, n as f32 * 1.1, f, &()); m.insert(n * 10, n as f32 * 1.1, f, &());
} }
@@ -473,8 +473,8 @@ mod test {
// 210, 220, ..., 270 // 210, 220, ..., 270
// ... // ...
// 810, 820, ..., 870 // 810, 820, ..., 870
fn full(f: &mut MapForest<u32, f32, ()>) -> BPlusMap<u32, f32, ()> { fn full(f: &mut MapForest<u32, f32, ()>) -> Map<u32, f32, ()> {
let mut m = BPlusMap::new(); let mut m = Map::new();
// Start by inserting elements in order. // Start by inserting elements in order.
// This should leave 8 leaf nodes with 4 elements in each. // This should leave 8 leaf nodes with 4 elements in each.
@@ -583,9 +583,9 @@ mod test {
// Make a tree with two barely healthy leaf nodes: // Make a tree with two barely healthy leaf nodes:
// [ 10 20 30 40 ] [ 50 60 70 80 ] // [ 10 20 30 40 ] [ 50 60 70 80 ]
fn two_leaf(f: &mut MapForest<u32, f32, ()>) -> BPlusMap<u32, f32, ()> { fn two_leaf(f: &mut MapForest<u32, f32, ()>) -> Map<u32, f32, ()> {
f.clear(); f.clear();
let mut m = BPlusMap::new(); let mut m = Map::new();
for n in 1..9 { for n in 1..9 {
m.insert(n * 10, n as f32, f, &()); m.insert(n * 10, n as f32, f, &());
} }
@@ -679,9 +679,9 @@ mod test {
// Make a 3-level tree with barely healthy nodes. // Make a 3-level tree with barely healthy nodes.
// 1 root, 8 inner nodes, 7*4+5=33 leaf nodes, 4 entries each. // 1 root, 8 inner nodes, 7*4+5=33 leaf nodes, 4 entries each.
fn level3_sparse(f: &mut MapForest<u32, f32, ()>) -> BPlusMap<u32, f32, ()> { fn level3_sparse(f: &mut MapForest<u32, f32, ()>) -> Map<u32, f32, ()> {
f.clear(); f.clear();
let mut m = BPlusMap::new(); let mut m = Map::new();
for n in 1..133 { for n in 1..133 {
m.insert(n * 10, n as f32, f, &()); m.insert(n * 10, n as f32, f, &());
} }
@@ -722,7 +722,7 @@ mod test {
#[test] #[test]
fn insert_many() { fn insert_many() {
let f = &mut MapForest::<u32, f32, ()>::new(); let f = &mut MapForest::<u32, f32, ()>::new();
let mut m = BPlusMap::<u32, f32, ()>::new(); let mut m = Map::<u32, f32, ()>::new();
let mm = 4096; let mm = 4096;
let mut x = 0; let mut x = 0;

View File

@@ -22,8 +22,8 @@ mod path;
mod pool; mod pool;
mod set; mod set;
pub use self::map::{MapForest, BPlusMap, MapCursor}; pub use self::map::{MapForest, Map, MapCursor};
pub use self::set::{SetForest, BPlusSet, SetCursor}; pub use self::set::{SetForest, Set, SetCursor};
use self::node::NodeData; use self::node::NodeData;
use self::path::Path; use self::path::Path;
@@ -42,7 +42,7 @@ const MAX_PATH: usize = 16;
/// ///
/// Keys don't need to implement `Ord`. They are compared using a comparator object which /// Keys don't need to implement `Ord`. They are compared using a comparator object which
/// provides a context for comparison. /// provides a context for comparison.
pub trait BPlusComparator<K> pub trait Comparator<K>
where where
K: Copy, K: Copy,
{ {
@@ -63,7 +63,7 @@ where
} }
/// Trivial comparator that doesn't actually provide any context. /// Trivial comparator that doesn't actually provide any context.
impl<K> BPlusComparator<K> for () impl<K> Comparator<K> for ()
where where
K: Copy + Ord, K: Copy + Ord,
{ {
@@ -87,7 +87,7 @@ trait Forest {
type LeafValues: Copy + BorrowMut<[Self::Value]>; type LeafValues: Copy + BorrowMut<[Self::Value]>;
/// Type used for key comparisons. /// Type used for key comparisons.
type Comparator: BPlusComparator<Self::Key>; type Comparator: Comparator<Self::Key>;
/// Splat a single key into a whole array. /// Splat a single key into a whole array.
fn splat_key(key: Self::Key) -> Self::LeafKeys; fn splat_key(key: Self::Key) -> Self::LeafKeys;

View File

@@ -2,7 +2,7 @@
use std::borrow::Borrow; use std::borrow::Borrow;
use std::marker::PhantomData; use std::marker::PhantomData;
use super::{Forest, Node, NodeData, NodePool, MAX_PATH, BPlusComparator, slice_insert, slice_shift}; use super::{Forest, Node, NodeData, NodePool, MAX_PATH, Comparator, slice_insert, slice_shift};
use super::node::Removed; use super::node::Removed;
#[cfg(test)] #[cfg(test)]
@@ -690,7 +690,7 @@ mod test {
struct TC(); struct TC();
impl BPlusComparator<i32> for TC { impl Comparator<i32> for TC {
fn cmp(&self, a: i32, b: i32) -> Ordering { fn cmp(&self, a: i32, b: i32) -> Ordering {
a.cmp(&b) a.cmp(&b)
} }

View File

@@ -64,7 +64,7 @@ impl<F: Forest> NodePool<F> {
{ {
use std::borrow::Borrow; use std::borrow::Borrow;
use std::cmp::Ordering; use std::cmp::Ordering;
use super::BPlusComparator; use super::Comparator;
use entity::SparseSet; use entity::SparseSet;
// The root node can't be an inner node with just a single sub-tree. It should have been // The root node can't be an inner node with just a single sub-tree. It should have been

View File

@@ -2,7 +2,7 @@
use packed_option::PackedOption; use packed_option::PackedOption;
use std::marker::PhantomData; use std::marker::PhantomData;
use super::{INNER_SIZE, BPlusComparator, Forest, NodePool, Node, NodeData, Path, SetValue}; use super::{INNER_SIZE, Comparator, Forest, NodePool, Node, NodeData, Path, SetValue};
/// Tag type defining forest types for a set. /// Tag type defining forest types for a set.
struct SetTypes<K, C>(PhantomData<(K, C)>); struct SetTypes<K, C>(PhantomData<(K, C)>);
@@ -10,7 +10,7 @@ struct SetTypes<K, C>(PhantomData<(K, C)>);
impl<K, C> Forest for SetTypes<K, C> impl<K, C> Forest for SetTypes<K, C>
where where
K: Copy, K: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
type Key = K; type Key = K;
type Value = SetValue; type Value = SetValue;
@@ -27,11 +27,11 @@ where
} }
} }
/// Memory pool for a forest of `BPlusSet` instances. /// Memory pool for a forest of `Set` instances.
pub struct SetForest<K, C> pub struct SetForest<K, C>
where where
K: Copy, K: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
nodes: NodePool<SetTypes<K, C>>, nodes: NodePool<SetTypes<K, C>>,
} }
@@ -39,7 +39,7 @@ where
impl<K, C> SetForest<K, C> impl<K, C> SetForest<K, C>
where where
K: Copy, K: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Create a new empty forest. /// Create a new empty forest.
pub fn new() -> SetForest<K, C> { pub fn new() -> SetForest<K, C> {
@@ -48,7 +48,7 @@ where
/// Clear all sets in the forest. /// Clear all sets in the forest.
/// ///
/// All `BPlusSet` instances belong to this forest are invalidated and should no longer be used. /// All `Set` instances belong to this forest are invalidated and should no longer be used.
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.nodes.clear(); self.nodes.clear();
} }
@@ -58,23 +58,23 @@ where
/// ///
/// This is not a general-purpose replacement for `BTreeSet`. See the [module /// This is not a general-purpose replacement for `BTreeSet`. See the [module
/// documentation](index.html) for more information about design tradeoffs. /// documentation](index.html) for more information about design tradeoffs.
pub struct BPlusSet<K, C> pub struct Set<K, C>
where where
K: Copy, K: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
root: PackedOption<Node>, root: PackedOption<Node>,
unused: PhantomData<(K, C)>, unused: PhantomData<(K, C)>,
} }
impl<K, C> BPlusSet<K, C> impl<K, C> Set<K, C>
where where
K: Copy, K: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Make an empty set. /// Make an empty set.
pub fn new() -> BPlusSet<K, C> { pub fn new() -> Set<K, C> {
BPlusSet { Set {
root: None.into(), root: None.into(),
unused: PhantomData, unused: PhantomData,
} }
@@ -126,14 +126,14 @@ where
} }
} }
/// A position in a `BPlusSet` used to navigate and modify the ordered set. /// A position in a `Set` used to navigate and modify the ordered set.
/// ///
/// A cursor always points at an element in the set, or "off the end" which is a position after the /// A cursor always points at an element in the set, or "off the end" which is a position after the
/// last element in the set. /// last element in the set.
pub struct SetCursor<'a, K, C> pub struct SetCursor<'a, K, C>
where where
K: 'a + Copy, K: 'a + Copy,
C: 'a + BPlusComparator<K>, C: 'a + Comparator<K>,
{ {
root: &'a mut PackedOption<Node>, root: &'a mut PackedOption<Node>,
pool: &'a mut NodePool<SetTypes<K, C>>, pool: &'a mut NodePool<SetTypes<K, C>>,
@@ -144,11 +144,11 @@ where
impl<'a, K, C> SetCursor<'a, K, C> impl<'a, K, C> SetCursor<'a, K, C>
where where
K: Copy, K: Copy,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
/// Create a cursor with a default (invalid) location. /// Create a cursor with a default (invalid) location.
fn new( fn new(
container: &'a mut BPlusSet<K, C>, container: &'a mut Set<K, C>,
forest: &'a mut SetForest<K, C>, forest: &'a mut SetForest<K, C>,
comp: &'a C, comp: &'a C,
) -> SetCursor<'a, K, C> { ) -> SetCursor<'a, K, C> {
@@ -250,7 +250,7 @@ where
impl<'a, K, C> SetCursor<'a, K, C> impl<'a, K, C> SetCursor<'a, K, C>
where where
K: Copy + ::std::fmt::Display, K: Copy + ::std::fmt::Display,
C: BPlusComparator<K>, C: Comparator<K>,
{ {
fn verify(&self) { fn verify(&self) {
self.path.verify(self.pool); self.path.verify(self.pool);
@@ -281,7 +281,7 @@ mod test {
let mut f = SetForest::<u32, ()>::new(); let mut f = SetForest::<u32, ()>::new();
f.clear(); f.clear();
let mut s = BPlusSet::<u32, ()>::new(); let mut s = Set::<u32, ()>::new();
assert!(s.is_empty()); assert!(s.is_empty());
assert!(!s.contains(7, &f, &())); assert!(!s.contains(7, &f, &()));
@@ -293,7 +293,7 @@ mod test {
#[test] #[test]
fn simple_cursor() { fn simple_cursor() {
let mut f = SetForest::<u32, ()>::new(); let mut f = SetForest::<u32, ()>::new();
let mut s = BPlusSet::<u32, ()>::new(); let mut s = Set::<u32, ()>::new();
let mut c = SetCursor::new(&mut s, &mut f, &()); let mut c = SetCursor::new(&mut s, &mut f, &());
assert!(c.insert(50)); assert!(c.insert(50));
@@ -335,7 +335,7 @@ mod test {
#[test] #[test]
fn two_level_sparse_tree() { fn two_level_sparse_tree() {
let mut f = SetForest::<u32, ()>::new(); let mut f = SetForest::<u32, ()>::new();
let mut s = BPlusSet::<u32, ()>::new(); let mut s = Set::<u32, ()>::new();
let mut c = SetCursor::new(&mut s, &mut f, &()); let mut c = SetCursor::new(&mut s, &mut f, &());
// Insert enough elements that we get a two-level tree. // Insert enough elements that we get a two-level tree.
@@ -381,7 +381,7 @@ mod test {
#[test] #[test]
fn three_level_sparse_tree() { fn three_level_sparse_tree() {
let mut f = SetForest::<u32, ()>::new(); let mut f = SetForest::<u32, ()>::new();
let mut s = BPlusSet::<u32, ()>::new(); let mut s = Set::<u32, ()>::new();
let mut c = SetCursor::new(&mut s, &mut f, &()); let mut c = SetCursor::new(&mut s, &mut f, &());
// Insert enough elements that we get a 3-level tree. // Insert enough elements that we get a 3-level tree.
@@ -433,9 +433,9 @@ mod test {
// Level 4: 512 leafs, up to 7680 elements // Level 4: 512 leafs, up to 7680 elements
// //
// A 3-level tree can hold at most 960 elements. // A 3-level tree can hold at most 960 elements.
fn dense4l(f: &mut SetForest<i32, ()>) -> BPlusSet<i32, ()> { fn dense4l(f: &mut SetForest<i32, ()>) -> Set<i32, ()> {
f.clear(); f.clear();
let mut s = BPlusSet::new(); let mut s = Set::new();
// Insert 400 elements in 7 passes over the range to avoid the half-full leaf node pattern // Insert 400 elements in 7 passes over the range to avoid the half-full leaf node pattern
// that comes from sequential insertion. This will generate a normal leaf layer. // that comes from sequential insertion. This will generate a normal leaf layer.