提交 9c8b0c60 编写于 作者: K Kevin Cantu 提交者: Brian Anderson

Demode treemap.rs

上级 100368ab
......@@ -5,6 +5,8 @@
* very naive algorithm, but it will probably be updated to be a
* red-black tree or something else.
*/
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use core::cmp::{Eq, Ord};
use core::option::{Some, None};
......@@ -30,7 +32,7 @@ enum tree_node<K, V> = {
fn treemap<K, V>() -> treemap<K, V> { @mut None }
/// Insert a value into the map
fn insert<K: copy Eq Ord, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
fn insert<K: copy Eq Ord, V: copy>(m: &mut tree_edge<K, V>, +k: K, +v: V) {
match copy *m {
None => {
*m = Some(@tree_node({key: k,
......@@ -52,7 +54,7 @@ fn insert<K: copy Eq Ord, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
}
/// Find a value based on the key
fn find<K: copy Eq Ord, V: copy>(m: &const tree_edge<K, V>, k: K)
fn find<K: copy Eq Ord, V: copy>(m: &const tree_edge<K, V>, +k: K)
-> Option<V> {
match copy *m {
None => None,
......@@ -124,7 +126,7 @@ fn traverse_in_order() {
insert(m, 1, ());
let n = @mut 0;
fn t(n: @mut int, &&k: int, &&_v: ()) {
fn t(n: @mut int, +k: int, +_v: ()) {
assert (*n == k); *n += 1;
}
traverse(m, |x,y| t(n, x, y));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册