From 94921c0b7448c982448cfc8308f9a12732c3c8af Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 24 Oct 2017 09:09:02 -0700 Subject: [PATCH] Remove the dead B-Tree interface. We're starting over from scratch. --- lib/cretonne/src/btree.rs | 112 -------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 lib/cretonne/src/btree.rs diff --git a/lib/cretonne/src/btree.rs b/lib/cretonne/src/btree.rs deleted file mode 100644 index e625b6108e..0000000000 --- a/lib/cretonne/src/btree.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! Generic B-Tree implementation. -//! -//! This module defines a `Btree` type which provides similar functionality to -//! `BtreeMap`, but with some important differences in the implementation: -//! -//! 1. Memory is allocated from a `NodePool` instead of the global heap. -//! 2. The footprint of a BTree is only 4 bytes. -//! 3. A BTree doesn't implement `Drop`, leaving it to the pool to manage memory. -//! -//! The node pool is intended to be used as a LIFO allocator. After building up a larger data -//! structure with many list references, the whole thing can be discarded quickly by clearing the -//! pool. - -use std::marker::PhantomData; - -// A Node reference is a direct index to an element of the pool. -type NodeRef = u32; - -/// A B-tree data structure which nodes are allocated from a pool. -pub struct BTree { - index: NodeRef, - unused1: PhantomData, - unused2: PhantomData, -} - -/// An enum representing a B-tree node. -/// Keys and values are required to implement Default. -enum Node { - Inner { - size: u8, - keys: [K; 7], - nodes: [NodeRef; 8], - }, - Leaf { - size: u8, - keys: [K; 7], - values: [V; 7], - }, -} - -/// Memory pool for nodes. -struct NodePool { - // The array containing the nodes. - data: Vec>, - - // A free list - freelist: Vec, -} - -impl NodePool { - /// Create a new NodePool. - pub fn new() -> NodePool { - NodePool { - data: Vec::new(), - freelist: Vec::new(), - } - } - - /// Get a B-tree node. - pub fn get(&self, index: u32) -> Option<&Node> { - unimplemented!() - } -} - -impl BTree { - /// Search for `key` and return a `Cursor` that either points at `key` or the position - /// where it would be inserted. - pub fn search(&mut self, key: K) -> Cursor { - unimplemented!() - } -} - -pub struct Cursor<'a, K: 'a, V: 'a> { - pool: &'a mut NodePool, - height: usize, - path: [(NodeRef, u8); 16], -} - -impl<'a, K: Default, V: Default> Cursor<'a, K, V> { - /// The key at the cursor position. Returns `None` when the cursor points off the end. - pub fn key(&self) -> Option { - unimplemented!() - } - - /// The value at the cursor position. Returns `None` when the cursor points off the end. - pub fn value(&self) -> Option<&V> { - unimplemented!() - } - - /// Move to the next element. - /// Returns `false` if that moves the cursor off the end. - pub fn next(&mut self) -> bool { - unimplemented!() - } - - /// Move to the previous element. - /// Returns `false` if this moves the cursor before the beginning. - pub fn prev(&mut self) -> bool { - unimplemented!() - } - - /// Insert a `(key, value)` pair at the cursor position. - /// It is an error to insert a key that would be out of order at this position. - pub fn insert(&mut self, key: K, value: V) { - unimplemented!() - } - - /// Remove the current element. - pub fn remove(&mut self) { - unimplemented!() - } -}