From d3778e56bbfb4f7dc6de4c9b4cf70708e2c7a6f1 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Mon, 20 Nov 2017 14:09:25 -0800 Subject: [PATCH] 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. --- lib/cretonne/src/bforest/map.rs | 60 ++++++++++++++++---------------- lib/cretonne/src/bforest/mod.rs | 10 +++--- lib/cretonne/src/bforest/path.rs | 4 +-- lib/cretonne/src/bforest/pool.rs | 2 +- lib/cretonne/src/bforest/set.rs | 46 ++++++++++++------------ 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/lib/cretonne/src/bforest/map.rs b/lib/cretonne/src/bforest/map.rs index 43855c4760..e9709c0b17 100644 --- a/lib/cretonne/src/bforest/map.rs +++ b/lib/cretonne/src/bforest/map.rs @@ -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(PhantomData<(K, V, C)>); @@ -11,7 +11,7 @@ impl Forest for MapTypes where K: Copy, V: Copy, - C: BPlusComparator, + C: Comparator, { 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 where K: Copy, V: Copy, - C: BPlusComparator, + C: Comparator, { nodes: NodePool>, } @@ -42,7 +42,7 @@ impl MapForest where K: Copy, V: Copy, - C: BPlusComparator, + C: Comparator, { /// Create a new empty forest. pub fn new() -> MapForest { @@ -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 +pub struct Map where K: Copy, V: Copy, - C: BPlusComparator, + C: Comparator, { root: PackedOption, unused: PhantomData<(K, V, C)>, } -impl BPlusMap +impl Map where K: Copy, V: Copy, - C: BPlusComparator, + C: Comparator, { /// Make an empty map. - pub fn new() -> BPlusMap { - BPlusMap { + pub fn new() -> Map { + Map { root: None.into(), unused: PhantomData, } @@ -130,11 +130,11 @@ where } #[cfg(test)] -impl BPlusMap +impl Map where K: Copy + ::std::fmt::Display, V: Copy, - C: BPlusComparator, + C: Comparator, { /// Verify consistency. fn verify(&self, forest: &MapForest, 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, + C: 'a + Comparator, { root: &'a mut PackedOption, pool: &'a mut NodePool>, @@ -179,11 +179,11 @@ impl<'a, K, V, C> MapCursor<'a, K, V, C> where K: Copy, V: Copy, - C: BPlusComparator, + C: Comparator, { /// Create a cursor with a default (off-the-end) location. fn new( - container: &'a mut BPlusMap, + container: &'a mut Map, forest: &'a mut MapForest, 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, + C: Comparator, { fn verify(&self) { self.path.verify(self.pool); @@ -320,7 +320,7 @@ mod test { let mut f = MapForest::::new(); f.clear(); - let mut m = BPlusMap::::new(); + let mut m = Map::::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::::new(); - let mut m = BPlusMap::::new(); + let mut m = Map::::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::::new(); - fn full_leaf(f: &mut MapForest) -> BPlusMap { - let mut m = BPlusMap::new(); + fn full_leaf(f: &mut MapForest) -> Map { + 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) -> BPlusMap { - let mut m = BPlusMap::new(); + fn full(f: &mut MapForest) -> Map { + 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) -> BPlusMap { + fn two_leaf(f: &mut MapForest) -> Map { 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) -> BPlusMap { + fn level3_sparse(f: &mut MapForest) -> Map { 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::::new(); - let mut m = BPlusMap::::new(); + let mut m = Map::::new(); let mm = 4096; let mut x = 0; diff --git a/lib/cretonne/src/bforest/mod.rs b/lib/cretonne/src/bforest/mod.rs index de8ee1092d..8234551b23 100644 --- a/lib/cretonne/src/bforest/mod.rs +++ b/lib/cretonne/src/bforest/mod.rs @@ -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 +pub trait Comparator where K: Copy, { @@ -63,7 +63,7 @@ where } /// Trivial comparator that doesn't actually provide any context. -impl BPlusComparator for () +impl Comparator 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; + type Comparator: Comparator; /// Splat a single key into a whole array. fn splat_key(key: Self::Key) -> Self::LeafKeys; diff --git a/lib/cretonne/src/bforest/path.rs b/lib/cretonne/src/bforest/path.rs index 2dceb805f4..aa42e2ecc8 100644 --- a/lib/cretonne/src/bforest/path.rs +++ b/lib/cretonne/src/bforest/path.rs @@ -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 for TC { + impl Comparator for TC { fn cmp(&self, a: i32, b: i32) -> Ordering { a.cmp(&b) } diff --git a/lib/cretonne/src/bforest/pool.rs b/lib/cretonne/src/bforest/pool.rs index 2dfcb35074..778fa082f4 100644 --- a/lib/cretonne/src/bforest/pool.rs +++ b/lib/cretonne/src/bforest/pool.rs @@ -64,7 +64,7 @@ impl NodePool { { 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 diff --git a/lib/cretonne/src/bforest/set.rs b/lib/cretonne/src/bforest/set.rs index e768ab64b9..efdf39b4c7 100644 --- a/lib/cretonne/src/bforest/set.rs +++ b/lib/cretonne/src/bforest/set.rs @@ -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(PhantomData<(K, C)>); @@ -10,7 +10,7 @@ struct SetTypes(PhantomData<(K, C)>); impl Forest for SetTypes where K: Copy, - C: BPlusComparator, + C: Comparator, { 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 where K: Copy, - C: BPlusComparator, + C: Comparator, { nodes: NodePool>, } @@ -39,7 +39,7 @@ where impl SetForest where K: Copy, - C: BPlusComparator, + C: Comparator, { /// Create a new empty forest. pub fn new() -> SetForest { @@ -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 +pub struct Set where K: Copy, - C: BPlusComparator, + C: Comparator, { root: PackedOption, unused: PhantomData<(K, C)>, } -impl BPlusSet +impl Set where K: Copy, - C: BPlusComparator, + C: Comparator, { /// Make an empty set. - pub fn new() -> BPlusSet { - BPlusSet { + pub fn new() -> Set { + 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, + C: 'a + Comparator, { root: &'a mut PackedOption, pool: &'a mut NodePool>, @@ -144,11 +144,11 @@ where impl<'a, K, C> SetCursor<'a, K, C> where K: Copy, - C: BPlusComparator, + C: Comparator, { /// Create a cursor with a default (invalid) location. fn new( - container: &'a mut BPlusSet, + container: &'a mut Set, forest: &'a mut SetForest, 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, + C: Comparator, { fn verify(&self) { self.path.verify(self.pool); @@ -281,7 +281,7 @@ mod test { let mut f = SetForest::::new(); f.clear(); - let mut s = BPlusSet::::new(); + let mut s = Set::::new(); assert!(s.is_empty()); assert!(!s.contains(7, &f, &())); @@ -293,7 +293,7 @@ mod test { #[test] fn simple_cursor() { let mut f = SetForest::::new(); - let mut s = BPlusSet::::new(); + let mut s = Set::::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::::new(); - let mut s = BPlusSet::::new(); + let mut s = Set::::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::::new(); - let mut s = BPlusSet::::new(); + let mut s = Set::::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) -> BPlusSet { + fn dense4l(f: &mut SetForest) -> Set { 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.