diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-02-29 11:46:23 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-03-02 18:46:13 -0800 |
| commit | 87c14f1e3d85751bffffda0b1920be5e726172c4 (patch) | |
| tree | 371d86e9a7c65b06df5c8f5e6d499cf4730324fc /src/comp/syntax/util | |
| parent | 9228947fe15af96593abf4745d91802b56c205e8 (diff) | |
Move src/comp to src/rustc
Diffstat (limited to 'src/comp/syntax/util')
| -rw-r--r-- | src/comp/syntax/util/interner.rs | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs deleted file mode 100644 index c7f0d7ecb99..00000000000 --- a/src/comp/syntax/util/interner.rs +++ /dev/null @@ -1,39 +0,0 @@ -// An "interner" is a data structure that associates values with uint tags and -// allows bidirectional lookup; i.e. given a value, one can easily find the -// type, and vice versa. -import std::map; -import std::map::{hashmap, hashfn, eqfn}; - -type interner<T> = - {map: hashmap<T, uint>, - mutable vect: [T], - hasher: hashfn<T>, - eqer: eqfn<T>}; - -fn mk<T: copy>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> { - let m = map::mk_hashmap::<T, uint>(hasher, eqer); - ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer}; -} - -fn intern<T: copy>(itr: interner<T>, val: T) -> uint { - alt itr.map.find(val) { - some(idx) { ret idx; } - none { - let new_idx = vec::len::<T>(itr.vect); - itr.map.insert(val, new_idx); - itr.vect += [val]; - ret new_idx; - } - } -} - -// |get| isn't "pure" in the traditional sense, because it can go from -// failing to returning a value as items are interned. But for typestate, -// where we first check a pred and then rely on it, ceasing to fail is ok. -pure fn get<T: copy>(itr: interner<T>, idx: uint) -> T { - unchecked { - itr.vect[idx] - } -} - -fn len<T>(itr: interner<T>) -> uint { ret vec::len(itr.vect); } |
