diff options
| author | Paul Stansifer <paul.stansifer@gmail.com> | 2012-07-18 16:18:02 -0700 |
|---|---|---|
| committer | Paul Stansifer <paul.stansifer@gmail.com> | 2012-08-22 14:59:25 -0700 |
| commit | 1153b5dcc86c3567b0a86e441938f05d4f2e295b (patch) | |
| tree | fdcbcea39abecb4ad1ea5145e62e8c013b05e930 /src/libsyntax/util | |
| parent | 7317bf8792ebb3f27768109b7d574ee0806cc5e5 (diff) | |
intern identifiers
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/interner.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 19b27be83e2..5cecd315ac4 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -21,7 +21,7 @@ fn mk<T: const copy>(+hasher: hashfn<T>, +eqer: eqfn<T>) -> interner<T> { fn mk_prefill<T: const copy>(hasher: hashfn<T>, eqer: eqfn<T>, init: ~[T]) -> interner<T> { - let rv = mk(hasher, eqer); + let rv = mk(copy hasher, copy eqer); for init.each() |v| { rv.intern(v); } return rv; } @@ -30,6 +30,7 @@ fn mk_prefill<T: const copy>(hasher: hashfn<T>, eqer: eqfn<T>, /* when traits can extend traits, we should extend index<uint,T> to get [] */ trait interner<T: const copy> { fn intern(T) -> uint; + fn gensym(T) -> uint; pure fn get(uint) -> T; fn len() -> uint; } @@ -46,6 +47,12 @@ impl <T: const copy> hash_interner<T>: interner<T> { } } } + fn gensym(val: T) -> uint { + let new_idx = self.vect.len(); + // leave out of .map to avoid colliding + self.vect.push(val); + return new_idx; + } // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, |
