diff options
| author | Steven Fackler <sfackler@gmail.com> | 2013-08-17 01:46:32 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-08-20 22:09:47 -0400 |
| commit | 934a5eba50aa90b7ab1822d62a2903255614eeef (patch) | |
| tree | cf2881f03b63ad02d684bae590eeb4f6ddce0b0b | |
| parent | 5f3a637b7cbd026d0cb8f8ce2139fa6287d06b56 (diff) | |
| download | rust-934a5eba50aa90b7ab1822d62a2903255614eeef.tar.gz rust-934a5eba50aa90b7ab1822d62a2903255614eeef.zip | |
Deleted fun_treemap
@thestinger and I talked about this in IRC. There are a couple of use cases for a persistent map, but they aren't common enough to justify inclusion in libextra and vary enough that they would require multiple implementations anyways. In any case, fun_treemap in its current state is basically useless.
| -rw-r--r-- | src/libextra/extra.rs | 1 | ||||
| -rw-r--r-- | src/libextra/fun_treemap.rs | 84 |
2 files changed, 0 insertions, 85 deletions
diff --git a/src/libextra/extra.rs b/src/libextra/extra.rs index da6525f7815..caf2c41d31d 100644 --- a/src/libextra/extra.rs +++ b/src/libextra/extra.rs @@ -55,7 +55,6 @@ pub mod flatpipes; pub mod container; pub mod bitv; -pub mod fun_treemap; pub mod list; pub mod ringbuf; pub mod priority_queue; diff --git a/src/libextra/fun_treemap.rs b/src/libextra/fun_treemap.rs deleted file mode 100644 index edbe323ec2d..00000000000 --- a/src/libextra/fun_treemap.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - * A functional key,value store that works on anything. - * - * This works using a binary search tree. In the first version, it's a - * very naive algorithm, but it will probably be updated to be a - * red-black tree or something else. - * - * This is copied and modified from treemap right now. It's missing a lot - * of features. - */ - - -use std::cmp::{Eq, Ord}; -use std::option::{Some, None}; - -pub type Treemap<K, V> = @TreeNode<K, V>; - -enum TreeNode<K, V> { - Empty, - Node(@K, @V, @TreeNode<K, V>, @TreeNode<K, V>) -} - -/// Create a treemap -pub fn init<K: 'static, V: 'static>() -> Treemap<K, V> { - @Empty -} - -/// Insert a value into the map -pub fn insert<K:Eq + Ord + 'static, - V:'static>( - m: Treemap<K, V>, - k: K, - v: V) - -> Treemap<K, V> { - @match m { - @Empty => Node(@k, @v, @Empty, @Empty), - @Node(kk, vv, left, right) => cond!( - (k < *kk) { Node(kk, vv, insert(left, k, v), right) } - (k == *kk) { Node(kk, @v, left, right) } - _ { Node(kk, vv, left, insert(right, k, v)) } - ) - } -} - -/// Find a value based on the key -pub fn find<K:Eq + Ord + 'static, - V:Clone + 'static>( - m: Treemap<K, V>, - k: K) - -> Option<V> { - match *m { - Empty => None, - Node(kk, v, left, right) => cond!( - (k == *kk) { Some((*v).clone()) } - (k < *kk) { find(left, k) } - _ { find(right, k) } - ) - } -} - -/// Visit all pairs in the map in order. -pub fn traverse<K, V>(m: Treemap<K, V>, f: &fn(&K, &V)) { - match *m { - Empty => (), - // Previously, this had what looked like redundant - // matches to me, so I changed it. but that may be a - // de-optimization -- tjc - Node(@ref k, @ref v, left, right) => { - traverse(left, |k,v| f(k,v)); - f(k, v); - traverse(right, |k,v| f(k,v)); - } - } -} |
