mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
s/Tree/BTree
This commit is contained in:
parent
6c00f9c5ff
commit
0bd4dc68e6
@ -15,7 +15,7 @@ use std::default::Default;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use {Decodable, Encodable, Decoder, Encoder};
|
||||
use std::collections::{DList, RingBuf, TreeMap, TreeSet, HashMap, HashSet,
|
||||
use std::collections::{DList, RingBuf, BTreeMap, BTreeSet, HashMap, HashSet,
|
||||
TrieMap, TrieSet, VecMap};
|
||||
use std::collections::enum_set::{EnumSet, CLike};
|
||||
|
||||
@ -78,7 +78,7 @@ impl<
|
||||
S: Encoder<E>,
|
||||
K: Encodable<S, E> + PartialEq + Ord,
|
||||
V: Encodable<S, E> + PartialEq
|
||||
> Encodable<S, E> for TreeMap<K, V> {
|
||||
> Encodable<S, E> for BTreeMap<K, V> {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
e.emit_map(self.len(), |e| {
|
||||
let mut i = 0;
|
||||
@ -97,10 +97,10 @@ impl<
|
||||
D: Decoder<E>,
|
||||
K: Decodable<D, E> + PartialEq + Ord,
|
||||
V: Decodable<D, E> + PartialEq
|
||||
> Decodable<D, E> for TreeMap<K, V> {
|
||||
> Decodable<D, E> for BTreeMap<K, V> {
|
||||
fn decode(d: &mut D) -> Result<TreeMap<K, V>, E> {
|
||||
d.read_map(|d, len| {
|
||||
let mut map = TreeMap::new();
|
||||
let mut map = BTreeMap::new();
|
||||
for i in range(0u, len) {
|
||||
let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
|
||||
let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
|
||||
@ -115,7 +115,7 @@ impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
T: Encodable<S, E> + PartialEq + Ord
|
||||
> Encodable<S, E> for TreeSet<T> {
|
||||
> Encodable<S, E> for BTreeSet<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
let mut i = 0;
|
||||
@ -132,10 +132,10 @@ impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
T: Decodable<D, E> + PartialEq + Ord
|
||||
> Decodable<D, E> for TreeSet<T> {
|
||||
> Decodable<D, E> for BTreeSet<T> {
|
||||
fn decode(d: &mut D) -> Result<TreeSet<T>, E> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut set = TreeSet::new();
|
||||
let mut set = BTreeSet::new();
|
||||
for i in range(0u, len) {
|
||||
set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
|
@ -151,7 +151,7 @@
|
||||
//!
|
||||
//! ```rust
|
||||
//! extern crate serialize;
|
||||
//! use std::collections::TreeMap;
|
||||
//! use std::collections::BTreeMap;
|
||||
//! use serialize::json::{mod, Json, ToJson};
|
||||
//!
|
||||
//! // Only generate `Decodable` trait implementation
|
||||
@ -165,7 +165,7 @@
|
||||
//! // Specify encoding method manually
|
||||
//! impl ToJson for TestStruct {
|
||||
//! fn to_json(&self) -> Json {
|
||||
//! let mut d = TreeMap::new();
|
||||
//! let mut d = BTreeMap::new();
|
||||
//! // All standard types implement `to_json()`, so use it
|
||||
//! d.insert("data_int".to_string(), self.data_int.to_json());
|
||||
//! d.insert("data_str".to_string(), self.data_str.to_json());
|
||||
@ -198,7 +198,7 @@ use self::ParserState::*;
|
||||
use self::InternalStackElement::*;
|
||||
|
||||
use std;
|
||||
use std::collections::{HashMap, TreeMap};
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::{char, f64, fmt, io, num, str};
|
||||
use std::mem::{swap, transmute};
|
||||
use std::num::{Float, FPNaN, FPInfinite, Int};
|
||||
@ -223,7 +223,7 @@ pub enum Json {
|
||||
}
|
||||
|
||||
pub type Array = Vec<Json>;
|
||||
pub type Object = TreeMap<string::String, Json>;
|
||||
pub type Object = BTreeMap<string::String, Json>;
|
||||
|
||||
/// The errors that can arise while parsing a JSON stream.
|
||||
#[deriving(Clone, PartialEq)]
|
||||
@ -973,7 +973,7 @@ impl Json {
|
||||
self.as_object().is_some()
|
||||
}
|
||||
|
||||
/// If the Json value is an Object, returns the associated TreeMap.
|
||||
/// If the Json value is an Object, returns the associated BTreeMap.
|
||||
/// Returns None otherwise.
|
||||
pub fn as_object<'a>(&'a self) -> Option<&'a Object> {
|
||||
match self {
|
||||
@ -1909,7 +1909,7 @@ impl<T: Iterator<char>> Builder<T> {
|
||||
fn build_object(&mut self) -> Result<Json, BuilderError> {
|
||||
self.bump();
|
||||
|
||||
let mut values = TreeMap::new();
|
||||
let mut values = BTreeMap::new();
|
||||
|
||||
loop {
|
||||
match self.token {
|
||||
@ -2391,9 +2391,9 @@ impl<A: ToJson> ToJson for Vec<A> {
|
||||
fn to_json(&self) -> Json { Json::Array(self.iter().map(|elt| elt.to_json()).collect()) }
|
||||
}
|
||||
|
||||
impl<A: ToJson> ToJson for TreeMap<string::String, A> {
|
||||
impl<A: ToJson> ToJson for BTreeMap<string::String, A> {
|
||||
fn to_json(&self) -> Json {
|
||||
let mut d = TreeMap::new();
|
||||
let mut d = BTreeMap::new();
|
||||
for (key, value) in self.iter() {
|
||||
d.insert((*key).clone(), value.to_json());
|
||||
}
|
||||
@ -2403,7 +2403,7 @@ impl<A: ToJson> ToJson for TreeMap<string::String, A> {
|
||||
|
||||
impl<A: ToJson> ToJson for HashMap<string::String, A> {
|
||||
fn to_json(&self) -> Json {
|
||||
let mut d = TreeMap::new();
|
||||
let mut d = BTreeMap::new();
|
||||
for (key, value) in self.iter() {
|
||||
d.insert((*key).clone(), value.to_json());
|
||||
}
|
||||
@ -2451,7 +2451,7 @@ mod tests {
|
||||
use super::{PrettyEncoder, Json, from_str, DecodeResult, DecoderError, JsonEvent, Parser,
|
||||
StackElement, Stack, Encoder, Decoder};
|
||||
use std::{i64, u64, f32, f64, io};
|
||||
use std::collections::TreeMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::num::Float;
|
||||
use std::string;
|
||||
|
||||
@ -2501,7 +2501,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn mk_object(items: &[(string::String, Json)]) -> Json {
|
||||
let mut d = TreeMap::new();
|
||||
let mut d = BTreeMap::new();
|
||||
|
||||
for item in items.iter() {
|
||||
match *item {
|
||||
@ -3075,7 +3075,7 @@ mod tests {
|
||||
fn test_decode_map() {
|
||||
let s = "{\"a\": \"Dog\", \"b\": {\"variant\":\"Frog\",\
|
||||
\"fields\":[\"Henry\", 349]}}";
|
||||
let mut map: TreeMap<string::String, Animal> = super::decode(s).unwrap();
|
||||
let mut map: BTreeMap<string::String, Animal> = super::decode(s).unwrap();
|
||||
|
||||
assert_eq!(map.remove(&"a".into_string()), Some(Dog));
|
||||
assert_eq!(map.remove(&"b".into_string()), Some(Frog("Henry".into_string(), 349)));
|
||||
@ -3350,9 +3350,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_prettyencoder_indent_level_param() {
|
||||
use std::str::from_utf8;
|
||||
use std::collections::TreeMap;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
let mut tree = TreeMap::new();
|
||||
let mut tree = BTreeMap::new();
|
||||
|
||||
tree.insert("hello".into_string(), String("guten tag".into_string()));
|
||||
tree.insert("goodbye".into_string(), String("sayonara".into_string()));
|
||||
@ -3719,13 +3719,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_to_json() {
|
||||
use std::collections::{HashMap,TreeMap};
|
||||
use std::collections::{HashMap,BTreeMap};
|
||||
use super::ToJson;
|
||||
|
||||
let array2 = Array(vec!(U64(1), U64(2)));
|
||||
let array3 = Array(vec!(U64(1), U64(2), U64(3)));
|
||||
let object = {
|
||||
let mut tree_map = TreeMap::new();
|
||||
let mut tree_map = BTreeMap::new();
|
||||
tree_map.insert("a".into_string(), U64(1));
|
||||
tree_map.insert("b".into_string(), U64(2));
|
||||
Object(tree_map)
|
||||
@ -3758,7 +3758,7 @@ mod tests {
|
||||
assert_eq!((&[1u, 2, 3]).to_json(), array3);
|
||||
assert_eq!((vec![1u, 2]).to_json(), array2);
|
||||
assert_eq!(vec!(1u, 2, 3).to_json(), array3);
|
||||
let mut tree_map = TreeMap::new();
|
||||
let mut tree_map = BTreeMap::new();
|
||||
tree_map.insert("a".into_string(), 1u);
|
||||
tree_map.insert("b".into_string(), 2);
|
||||
assert_eq!(tree_map.to_json(), object);
|
||||
|
@ -251,7 +251,7 @@ pub enum MetricChange {
|
||||
|
||||
impl Copy for MetricChange {}
|
||||
|
||||
pub type MetricDiff = TreeMap<String,MetricChange>;
|
||||
pub type MetricDiff = BTreeMap<String,MetricChange>;
|
||||
|
||||
// The default console test runner. It accepts the command line
|
||||
// arguments and a vector of test_descs.
|
||||
@ -1227,7 +1227,7 @@ impl MetricMap {
|
||||
/// map.
|
||||
pub fn compare_to_old(&self, old: &MetricMap,
|
||||
noise_pct: Option<f64>) -> MetricDiff {
|
||||
let mut diff : MetricDiff = TreeMap::new();
|
||||
let mut diff : MetricDiff = BTreeMap::new();
|
||||
let MetricMap(ref selfmap) = *self;
|
||||
let MetricMap(ref old) = *old;
|
||||
for (k, vold) in old.iter() {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
use std::collections::{TrieMap, TreeMap, HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::os;
|
||||
use std::rand::{Rng, IsaacRng, SeedableRng};
|
||||
use std::time::Duration;
|
||||
@ -26,7 +26,7 @@ trait MutableMap {
|
||||
fn find(&self, k: &uint) -> Option<&uint>;
|
||||
}
|
||||
|
||||
impl MutableMap for TreeMap<uint, uint> {
|
||||
impl MutableMap for BTreeMap<uint, uint> {
|
||||
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
|
||||
@ -36,11 +36,6 @@ impl MutableMap for HashMap<uint, uint> {
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
|
||||
}
|
||||
impl MutableMap for TrieMap<uint> {
|
||||
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
|
||||
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
|
||||
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
|
||||
}
|
||||
|
||||
fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) {
|
||||
println!(" Ascending integers:");
|
||||
@ -134,21 +129,21 @@ fn main() {
|
||||
println!("{} keys", n_keys);
|
||||
|
||||
// FIXME: #9970
|
||||
println!("{}", "\nTreeMap:");
|
||||
println!("{}", "\nBTreeMap:");
|
||||
|
||||
{
|
||||
let mut map: TreeMap<uint,uint> = TreeMap::new();
|
||||
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
|
||||
ascending(&mut map, n_keys);
|
||||
}
|
||||
|
||||
{
|
||||
let mut map: TreeMap<uint,uint> = TreeMap::new();
|
||||
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
|
||||
descending(&mut map, n_keys);
|
||||
}
|
||||
|
||||
{
|
||||
println!(" Random integers:");
|
||||
let mut map: TreeMap<uint,uint> = TreeMap::new();
|
||||
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
|
||||
vector(&mut map, n_keys, rand.as_slice());
|
||||
}
|
||||
|
||||
@ -170,23 +165,4 @@ fn main() {
|
||||
let mut map: HashMap<uint,uint> = HashMap::new();
|
||||
vector(&mut map, n_keys, rand.as_slice());
|
||||
}
|
||||
|
||||
// FIXME: #9970
|
||||
println!("{}", "\nTrieMap:");
|
||||
|
||||
{
|
||||
let mut map: TrieMap<uint> = TrieMap::new();
|
||||
ascending(&mut map, n_keys);
|
||||
}
|
||||
|
||||
{
|
||||
let mut map: TrieMap<uint> = TrieMap::new();
|
||||
descending(&mut map, n_keys);
|
||||
}
|
||||
|
||||
{
|
||||
println!(" Random integers:");
|
||||
let mut map: TrieMap<uint> = TrieMap::new();
|
||||
vector(&mut map, n_keys, rand.as_slice());
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ extern crate rand;
|
||||
|
||||
use std::collections::BitvSet;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::TreeSet;
|
||||
use std::collections::BTreeSet;
|
||||
use std::hash::Hash;
|
||||
use std::os;
|
||||
use std::time::Duration;
|
||||
@ -48,7 +48,7 @@ impl<T: Hash + Eq> MutableSet<T> for HashSet<T> {
|
||||
fn remove(&mut self, k: &T) -> bool { self.remove(k) }
|
||||
fn contains(&self, k: &T) -> bool { self.contains(k) }
|
||||
}
|
||||
impl<T: Ord> MutableSet<T> for TreeSet<T> {
|
||||
impl<T: Ord> MutableSet<T> for BTreeSet<T> {
|
||||
fn insert(&mut self, k: T) { self.insert(k); }
|
||||
fn remove(&mut self, k: &T) -> bool { self.remove(k) }
|
||||
fn contains(&self, k: &T) -> bool { self.contains(k) }
|
||||
@ -207,14 +207,14 @@ fn main() {
|
||||
let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed);
|
||||
let mut results = empty_results();
|
||||
results.bench_int(&mut rng, num_keys, max, || {
|
||||
let s: TreeSet<uint> = TreeSet::new();
|
||||
let s: BTreeSet<uint> = BTreeSet::new();
|
||||
s
|
||||
});
|
||||
results.bench_str(&mut rng, num_keys, || {
|
||||
let s: TreeSet<String> = TreeSet::new();
|
||||
let s: BTreeSet<String> = BTreeSet::new();
|
||||
s
|
||||
});
|
||||
write_results("collections::TreeSet", &results);
|
||||
write_results("collections::BTreeSet", &results);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
// this file has some special \r\n endings (use xxd to see them)
|
||||
|
||||
fn main() {assert_eq!(b"", b"\
|
||||
fn main() {assert_eq!(b"", b"\
|
||||
");
|
||||
assert_eq!(b"\n", b"
|
||||
assert_eq!(b"\n", b"
|
||||
");
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ use std::str::SendStr;
|
||||
use std::string::ToString;
|
||||
|
||||
pub fn main() {
|
||||
let mut map: TreeMap<SendStr, uint> = TreeMap::new();
|
||||
let mut map: BTreeMap<SendStr, uint> = BTreeMap::new();
|
||||
assert!(map.insert("foo".into_cow(), 42).is_none());
|
||||
assert!(map.insert("foo".to_string().into_cow(), 42).is_some());
|
||||
assert!(map.insert("foo".into_cow(), 42).is_some());
|
||||
|
Loading…
Reference in New Issue
Block a user