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:
@@ -2,7 +2,7 @@
|
||||
|
||||
use packed_option::PackedOption;
|
||||
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.
|
||||
struct MapTypes<K, V, C>(PhantomData<(K, V, C)>);
|
||||
@@ -11,7 +11,7 @@ impl<K, V, C> Forest for MapTypes<K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
type Key = K;
|
||||
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>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
nodes: NodePool<MapTypes<K, V, C>>,
|
||||
}
|
||||
@@ -42,7 +42,7 @@ impl<K, V, C> MapForest<K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Create a new empty forest.
|
||||
pub fn new() -> MapForest<K, V, C> {
|
||||
@@ -51,7 +51,7 @@ where
|
||||
|
||||
/// 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) {
|
||||
self.nodes.clear();
|
||||
}
|
||||
@@ -61,25 +61,25 @@ where
|
||||
///
|
||||
/// This is not a general-purpose replacement for `BTreeMap`. See the [module
|
||||
/// documentation](index.html) for more information about design tradeoffs.
|
||||
pub struct BPlusMap<K, V, C>
|
||||
pub struct Map<K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
root: PackedOption<Node>,
|
||||
unused: PhantomData<(K, V, C)>,
|
||||
}
|
||||
|
||||
impl<K, V, C> BPlusMap<K, V, C>
|
||||
impl<K, V, C> Map<K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Make an empty map.
|
||||
pub fn new() -> BPlusMap<K, V, C> {
|
||||
BPlusMap {
|
||||
pub fn new() -> Map<K, V, C> {
|
||||
Map {
|
||||
root: None.into(),
|
||||
unused: PhantomData,
|
||||
}
|
||||
@@ -130,11 +130,11 @@ where
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<K, V, C> BPlusMap<K, V, C>
|
||||
impl<K, V, C> Map<K, V, C>
|
||||
where
|
||||
K: Copy + ::std::fmt::Display,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Verify consistency.
|
||||
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
|
||||
/// after the last entry in the map.
|
||||
@@ -167,7 +167,7 @@ pub struct MapCursor<'a, K, V, C>
|
||||
where
|
||||
K: 'a + Copy,
|
||||
V: 'a + Copy,
|
||||
C: 'a + BPlusComparator<K>,
|
||||
C: 'a + Comparator<K>,
|
||||
{
|
||||
root: &'a mut PackedOption<Node>,
|
||||
pool: &'a mut NodePool<MapTypes<K, V, C>>,
|
||||
@@ -179,11 +179,11 @@ impl<'a, K, V, C> MapCursor<'a, K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Create a cursor with a default (off-the-end) location.
|
||||
fn new(
|
||||
container: &'a mut BPlusMap<K, V, C>,
|
||||
container: &'a mut Map<K, V, C>,
|
||||
forest: &'a mut MapForest<K, V, C>,
|
||||
comp: &'a C,
|
||||
) -> MapCursor<'a, K, V, C> {
|
||||
@@ -289,7 +289,7 @@ impl<'a, K, V, C> MapCursor<'a, K, V, C>
|
||||
where
|
||||
K: Copy + ::std::fmt::Display,
|
||||
V: Copy + ::std::fmt::Display,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
fn verify(&self) {
|
||||
self.path.verify(self.pool);
|
||||
@@ -320,7 +320,7 @@ mod test {
|
||||
let mut f = MapForest::<u32, f32, ()>::new();
|
||||
f.clear();
|
||||
|
||||
let mut m = BPlusMap::<u32, f32, ()>::new();
|
||||
let mut m = Map::<u32, f32, ()>::new();
|
||||
assert!(m.is_empty());
|
||||
|
||||
assert_eq!(m.get(7, &f, &()), None);
|
||||
@@ -338,7 +338,7 @@ mod test {
|
||||
#[test]
|
||||
fn inserting() {
|
||||
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.
|
||||
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.
|
||||
let f = &mut MapForest::<u32, f32, ()>::new();
|
||||
|
||||
fn full_leaf(f: &mut MapForest<u32, f32, ()>) -> BPlusMap<u32, f32, ()> {
|
||||
let mut m = BPlusMap::new();
|
||||
fn full_leaf(f: &mut MapForest<u32, f32, ()>) -> Map<u32, f32, ()> {
|
||||
let mut m = Map::new();
|
||||
for n in 1..8 {
|
||||
m.insert(n * 10, n as f32 * 1.1, f, &());
|
||||
}
|
||||
@@ -473,8 +473,8 @@ mod test {
|
||||
// 210, 220, ..., 270
|
||||
// ...
|
||||
// 810, 820, ..., 870
|
||||
fn full(f: &mut MapForest<u32, f32, ()>) -> BPlusMap<u32, f32, ()> {
|
||||
let mut m = BPlusMap::new();
|
||||
fn full(f: &mut MapForest<u32, f32, ()>) -> Map<u32, f32, ()> {
|
||||
let mut m = Map::new();
|
||||
|
||||
// Start by inserting elements in order.
|
||||
// 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:
|
||||
// [ 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();
|
||||
let mut m = BPlusMap::new();
|
||||
let mut m = Map::new();
|
||||
for n in 1..9 {
|
||||
m.insert(n * 10, n as f32, f, &());
|
||||
}
|
||||
@@ -679,9 +679,9 @@ mod test {
|
||||
|
||||
// Make a 3-level tree with barely healthy nodes.
|
||||
// 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();
|
||||
let mut m = BPlusMap::new();
|
||||
let mut m = Map::new();
|
||||
for n in 1..133 {
|
||||
m.insert(n * 10, n as f32, f, &());
|
||||
}
|
||||
@@ -722,7 +722,7 @@ mod test {
|
||||
#[test]
|
||||
fn insert_many() {
|
||||
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 mut x = 0;
|
||||
|
||||
@@ -22,8 +22,8 @@ mod path;
|
||||
mod pool;
|
||||
mod set;
|
||||
|
||||
pub use self::map::{MapForest, BPlusMap, MapCursor};
|
||||
pub use self::set::{SetForest, BPlusSet, SetCursor};
|
||||
pub use self::map::{MapForest, Map, MapCursor};
|
||||
pub use self::set::{SetForest, Set, SetCursor};
|
||||
|
||||
use self::node::NodeData;
|
||||
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
|
||||
/// provides a context for comparison.
|
||||
pub trait BPlusComparator<K>
|
||||
pub trait Comparator<K>
|
||||
where
|
||||
K: Copy,
|
||||
{
|
||||
@@ -63,7 +63,7 @@ where
|
||||
}
|
||||
|
||||
/// Trivial comparator that doesn't actually provide any context.
|
||||
impl<K> BPlusComparator<K> for ()
|
||||
impl<K> Comparator<K> for ()
|
||||
where
|
||||
K: Copy + Ord,
|
||||
{
|
||||
@@ -87,7 +87,7 @@ trait Forest {
|
||||
type LeafValues: Copy + BorrowMut<[Self::Value]>;
|
||||
|
||||
/// Type used for key comparisons.
|
||||
type Comparator: BPlusComparator<Self::Key>;
|
||||
type Comparator: Comparator<Self::Key>;
|
||||
|
||||
/// Splat a single key into a whole array.
|
||||
fn splat_key(key: Self::Key) -> Self::LeafKeys;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::borrow::Borrow;
|
||||
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;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -690,7 +690,7 @@ mod test {
|
||||
|
||||
struct TC();
|
||||
|
||||
impl BPlusComparator<i32> for TC {
|
||||
impl Comparator<i32> for TC {
|
||||
fn cmp(&self, a: i32, b: i32) -> Ordering {
|
||||
a.cmp(&b)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ impl<F: Forest> NodePool<F> {
|
||||
{
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::Ordering;
|
||||
use super::BPlusComparator;
|
||||
use super::Comparator;
|
||||
use entity::SparseSet;
|
||||
|
||||
// The root node can't be an inner node with just a single sub-tree. It should have been
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use packed_option::PackedOption;
|
||||
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.
|
||||
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>
|
||||
where
|
||||
K: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
type Key = K;
|
||||
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>
|
||||
where
|
||||
K: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
nodes: NodePool<SetTypes<K, C>>,
|
||||
}
|
||||
@@ -39,7 +39,7 @@ where
|
||||
impl<K, C> SetForest<K, C>
|
||||
where
|
||||
K: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Create a new empty forest.
|
||||
pub fn new() -> SetForest<K, C> {
|
||||
@@ -48,7 +48,7 @@ where
|
||||
|
||||
/// 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) {
|
||||
self.nodes.clear();
|
||||
}
|
||||
@@ -58,23 +58,23 @@ where
|
||||
///
|
||||
/// This is not a general-purpose replacement for `BTreeSet`. See the [module
|
||||
/// documentation](index.html) for more information about design tradeoffs.
|
||||
pub struct BPlusSet<K, C>
|
||||
pub struct Set<K, C>
|
||||
where
|
||||
K: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
root: PackedOption<Node>,
|
||||
unused: PhantomData<(K, C)>,
|
||||
}
|
||||
|
||||
impl<K, C> BPlusSet<K, C>
|
||||
impl<K, C> Set<K, C>
|
||||
where
|
||||
K: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Make an empty set.
|
||||
pub fn new() -> BPlusSet<K, C> {
|
||||
BPlusSet {
|
||||
pub fn new() -> Set<K, C> {
|
||||
Set {
|
||||
root: None.into(),
|
||||
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
|
||||
/// last element in the set.
|
||||
pub struct SetCursor<'a, K, C>
|
||||
where
|
||||
K: 'a + Copy,
|
||||
C: 'a + BPlusComparator<K>,
|
||||
C: 'a + Comparator<K>,
|
||||
{
|
||||
root: &'a mut PackedOption<Node>,
|
||||
pool: &'a mut NodePool<SetTypes<K, C>>,
|
||||
@@ -144,11 +144,11 @@ where
|
||||
impl<'a, K, C> SetCursor<'a, K, C>
|
||||
where
|
||||
K: Copy,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
/// Create a cursor with a default (invalid) location.
|
||||
fn new(
|
||||
container: &'a mut BPlusSet<K, C>,
|
||||
container: &'a mut Set<K, C>,
|
||||
forest: &'a mut SetForest<K, C>,
|
||||
comp: &'a C,
|
||||
) -> SetCursor<'a, K, C> {
|
||||
@@ -250,7 +250,7 @@ where
|
||||
impl<'a, K, C> SetCursor<'a, K, C>
|
||||
where
|
||||
K: Copy + ::std::fmt::Display,
|
||||
C: BPlusComparator<K>,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
fn verify(&self) {
|
||||
self.path.verify(self.pool);
|
||||
@@ -281,7 +281,7 @@ mod test {
|
||||
let mut f = SetForest::<u32, ()>::new();
|
||||
f.clear();
|
||||
|
||||
let mut s = BPlusSet::<u32, ()>::new();
|
||||
let mut s = Set::<u32, ()>::new();
|
||||
assert!(s.is_empty());
|
||||
assert!(!s.contains(7, &f, &()));
|
||||
|
||||
@@ -293,7 +293,7 @@ mod test {
|
||||
#[test]
|
||||
fn simple_cursor() {
|
||||
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, &());
|
||||
|
||||
assert!(c.insert(50));
|
||||
@@ -335,7 +335,7 @@ mod test {
|
||||
#[test]
|
||||
fn two_level_sparse_tree() {
|
||||
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, &());
|
||||
|
||||
// Insert enough elements that we get a two-level tree.
|
||||
@@ -381,7 +381,7 @@ mod test {
|
||||
#[test]
|
||||
fn three_level_sparse_tree() {
|
||||
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, &());
|
||||
|
||||
// Insert enough elements that we get a 3-level tree.
|
||||
@@ -433,9 +433,9 @@ mod test {
|
||||
// Level 4: 512 leafs, up to 7680 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();
|
||||
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
|
||||
// that comes from sequential insertion. This will generate a normal leaf layer.
|
||||
|
||||
Reference in New Issue
Block a user