diff options
| author | 2022-08-13 11:04:44 +0200 | |
|---|---|---|
| committer | 2022-08-13 11:04:44 +0200 | |
| commit | 5b95abb249604e7df9be1d63b1f3dc85b8f5990b (patch) | |
| tree | 5f7065f9bea68e46c925552392541d72dc8de1a6 /src/set.hff | |
| parent | dd4536a8b0dbb770ee1e9e7e492a75157ba0f8e6 (diff) | |
set more
Diffstat (limited to 'src/set.hff')
| -rw-r--r-- | src/set.hff | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/set.hff b/src/set.hff index acff95b..955eac3 100644 --- a/src/set.hff +++ b/src/set.hff @@ -35,12 +35,28 @@ struct Set<T, Traits> { self.buf->push(Traits:dup(x)); return self.set[i] = &self.buf.dat[self.buf.len - 1]; } else if Traits:eq(*self.set[i], x) { - fprintf(stderr, "found %s\n", x); return self.set[i]; } i = (i + 1) & (self.N - 1); } while i != i0; assert(#f, "unreachable"); } + + fn contains(self *Set, x T) bool { + let i0 = Traits:hash(x) & (self.N - 1); + let i int = i0; + do { + if self.set[i] == #null { + return #f; + } else if Traits:eq(*self.set[i], x) { + return #t; + } + i = (i + 1) & (self.N - 1); + } while i != i0; + assert(#f, "unreachable"); + } + fn put(self *Set, x T) void { + self->intern(x); + } } |