changes to get std passing borrowck
This commit is contained in:
parent
4c2bf8e4a7
commit
58988c3565
@ -406,8 +406,8 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
|
|||||||
let {tag: r_tag, doc: r_doc} =
|
let {tag: r_tag, doc: r_doc} =
|
||||||
ebml::doc_at(self.parent.data, self.pos);
|
ebml::doc_at(self.parent.data, self.pos);
|
||||||
#debug["self.parent=%?-%? self.pos=%? r_tag=%? r_doc=%?-%?",
|
#debug["self.parent=%?-%? self.pos=%? r_tag=%? r_doc=%?-%?",
|
||||||
self.parent.start, self.parent.end, self.pos,
|
copy self.parent.start, copy self.parent.end,
|
||||||
r_tag, r_doc.start, r_doc.end];
|
copy self.pos, r_tag, r_doc.start, r_doc.end];
|
||||||
if r_tag != (exp_tag as uint) {
|
if r_tag != (exp_tag as uint) {
|
||||||
fail #fmt["expected EMBL doc with tag %? but found tag %?",
|
fail #fmt["expected EMBL doc with tag %? but found tag %?",
|
||||||
exp_tag, r_tag];
|
exp_tag, r_tag];
|
||||||
|
@ -102,7 +102,7 @@ mod chained {
|
|||||||
let mut e0 = e_root;
|
let mut e0 = e_root;
|
||||||
let mut comp = 1u; // for logging
|
let mut comp = 1u; // for logging
|
||||||
loop {
|
loop {
|
||||||
alt e0.next {
|
alt copy e0.next {
|
||||||
absent {
|
absent {
|
||||||
#debug("search_tbl: absent, comp %u, hash %u, idx %u",
|
#debug("search_tbl: absent, comp %u, hash %u, idx %u",
|
||||||
comp, h, idx);
|
comp, h, idx);
|
||||||
@ -110,8 +110,7 @@ mod chained {
|
|||||||
}
|
}
|
||||||
present(e1) {
|
present(e1) {
|
||||||
comp += 1u;
|
comp += 1u;
|
||||||
let e1_key = e1.key; // Satisfy alias checker.
|
if e1.hash == h && self.eqer(e1.key, k) {
|
||||||
if e1.hash == h && self.eqer(e1_key, k) {
|
|
||||||
#debug("search_tbl: present, comp %u, \
|
#debug("search_tbl: present, comp %u, \
|
||||||
hash %u, idx %u",
|
hash %u, idx %u",
|
||||||
comp, h, idx);
|
comp, h, idx);
|
||||||
@ -126,15 +125,14 @@ mod chained {
|
|||||||
|
|
||||||
fn search_tbl(k: K, h: uint) -> search_result<K,V> {
|
fn search_tbl(k: K, h: uint) -> search_result<K,V> {
|
||||||
let idx = h % vec::len(self.chains);
|
let idx = h % vec::len(self.chains);
|
||||||
alt self.chains[idx] {
|
alt copy self.chains[idx] {
|
||||||
absent {
|
absent {
|
||||||
#debug("search_tbl: absent, comp %u, hash %u, idx %u",
|
#debug("search_tbl: absent, comp %u, hash %u, idx %u",
|
||||||
0u, h, idx);
|
0u, h, idx);
|
||||||
ret not_found;
|
ret not_found;
|
||||||
}
|
}
|
||||||
present(e) {
|
present(e) {
|
||||||
// FIXME: This copy of the key is not good for perf
|
if e.hash == h && self.eqer(e.key, k) {
|
||||||
if e.hash == h && self.eqer(copy e.key, k) {
|
|
||||||
#debug("search_tbl: present, comp %u, hash %u, idx %u",
|
#debug("search_tbl: present, comp %u, hash %u, idx %u",
|
||||||
1u, h, idx);
|
1u, h, idx);
|
||||||
ret found_first(idx, e);
|
ret found_first(idx, e);
|
||||||
|
@ -9,67 +9,74 @@ red-black tree or something else.
|
|||||||
import core::option::{some, none};
|
import core::option::{some, none};
|
||||||
import option = core::option;
|
import option = core::option;
|
||||||
|
|
||||||
export treemap;
|
|
||||||
export treemap;
|
export treemap;
|
||||||
export insert;
|
export insert;
|
||||||
export find;
|
export find;
|
||||||
export traverse;
|
export traverse;
|
||||||
|
|
||||||
type treemap<K, V> = @mut tree_node<K, V>;
|
type treemap<K, V> = @mut tree_edge<K, V>;
|
||||||
|
|
||||||
enum tree_node<K, V> { empty, node(@K, @V, treemap<K, V>, treemap<K, V>) }
|
type tree_edge<K, V> = option<@tree_node<K, V>>;
|
||||||
|
|
||||||
|
enum tree_node<K, V> = {
|
||||||
|
key: K,
|
||||||
|
mut value: V,
|
||||||
|
mut left: tree_edge<K, V>,
|
||||||
|
mut right: tree_edge<K, V>
|
||||||
|
};
|
||||||
|
|
||||||
#[doc = "Create a treemap"]
|
#[doc = "Create a treemap"]
|
||||||
fn treemap<K, V>() -> treemap<K, V> { @mut empty }
|
fn treemap<K, V>() -> treemap<K, V> { @mut none }
|
||||||
|
|
||||||
#[doc = "Insert a value into the map"]
|
#[doc = "Insert a value into the map"]
|
||||||
fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) {
|
fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
|
||||||
alt m {
|
alt copy *m {
|
||||||
@empty { *m = node(@k, @v, @mut empty, @mut empty); }
|
none {
|
||||||
@node(@kk, _, _, _) {
|
*m = some(@tree_node({key: k,
|
||||||
|
mut value: v,
|
||||||
// We have to name left and right individually, because
|
mut left: none,
|
||||||
// otherwise the alias checker complains.
|
mut right: none}));
|
||||||
if k < kk {
|
ret;
|
||||||
alt check m { @node(_, _, left, _) { insert(left, k, v); } }
|
}
|
||||||
|
some(node) {
|
||||||
|
if k == node.key {
|
||||||
|
node.value = v;
|
||||||
|
} else if k < node.key {
|
||||||
|
insert(&mut node.left, k, v);
|
||||||
} else {
|
} else {
|
||||||
alt check m {
|
insert(&mut node.right, k, v);
|
||||||
@node(_, _, _, right) { insert(right, k, v); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "Find a value based on the key"]
|
#[doc = "Find a value based on the key"]
|
||||||
fn find<K: copy, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
|
fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
|
||||||
alt *m {
|
alt copy *m {
|
||||||
empty { none }
|
none { none }
|
||||||
|
|
||||||
// TODO: was that an optimization?
|
// TODO: was that an optimization?
|
||||||
node(@kk, @v, left, right) {
|
some(node) {
|
||||||
if k == kk {
|
if k == node.key {
|
||||||
some(v)
|
some(node.value)
|
||||||
} else if k < kk {
|
} else if k < node.key {
|
||||||
find(left, k)
|
find(&const node.left, k)
|
||||||
} else { find(right, k) }
|
} else {
|
||||||
|
find(&const node.right, k)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "Visit all pairs in the map in order."]
|
#[doc = "Visit all pairs in the map in order."]
|
||||||
fn traverse<K, V>(m: treemap<K, V>, f: fn(K, V)) {
|
fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) {
|
||||||
alt *m {
|
alt copy *m {
|
||||||
empty { }
|
none { }
|
||||||
/*
|
some(node) {
|
||||||
Previously, this had what looked like redundant
|
traverse(&const node.left, f);
|
||||||
matches to me, so I changed it. but that may be a
|
// copy of value is req'd as f() requires an immutable ptr
|
||||||
de-optimization -- tjc
|
f(node.key, copy node.value);
|
||||||
*/
|
traverse(&const node.right, f);
|
||||||
node(k, v, left, right) {
|
|
||||||
let k1 = k, v1 = v;
|
|
||||||
traverse(left, f);
|
|
||||||
f(*k1, *v1);
|
|
||||||
traverse(right, f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user