2012-09-18 17:52:21 -05:00
|
|
|
#[legacy_modes];
|
2012-09-24 19:29:20 -05:00
|
|
|
#[legacy_exports];
|
2012-09-18 17:52:21 -05:00
|
|
|
|
2012-09-05 14:32:05 -05:00
|
|
|
use dvec::DVec;
|
2012-06-04 12:44:19 -05:00
|
|
|
|
|
|
|
type entry<A,B> = {key: A, value: B};
|
2012-08-14 18:54:13 -05:00
|
|
|
type alist<A,B> = { eq_fn: fn@(A,A) -> bool, data: DVec<entry<A,B>> };
|
2012-03-07 17:13:31 -06:00
|
|
|
|
2012-09-07 16:52:28 -05:00
|
|
|
fn alist_add<A: Copy, B: Copy>(lst: alist<A,B>, k: A, v: B) {
|
2012-06-04 12:44:19 -05:00
|
|
|
lst.data.push({key:k, value:v});
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
|
2012-09-07 16:52:28 -05:00
|
|
|
fn alist_get<A: Copy, B: Copy>(lst: alist<A,B>, k: A) -> B {
|
2012-03-07 17:13:31 -06:00
|
|
|
let eq_fn = lst.eq_fn;
|
2012-06-30 18:19:07 -05:00
|
|
|
for lst.data.each |entry| {
|
2012-08-01 19:30:05 -05:00
|
|
|
if eq_fn(entry.key, k) { return entry.value; }
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2012-09-07 16:52:28 -05:00
|
|
|
fn new_int_alist<B: Copy>() -> alist<int, B> {
|
2012-03-07 17:13:31 -06:00
|
|
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
2012-08-27 16:22:25 -05:00
|
|
|
return {eq_fn: eq_int, data: DVec()};
|
2012-03-07 17:13:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2012-09-07 16:52:28 -05:00
|
|
|
fn new_int_alist_2<B: Copy>() -> alist<int, B> {
|
2012-03-07 17:13:31 -06:00
|
|
|
#[inline]
|
|
|
|
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
|
2012-08-27 16:22:25 -05:00
|
|
|
return {eq_fn: eq_int, data: DVec()};
|
2012-09-18 17:52:21 -05:00
|
|
|
}
|