Navigation Menu

Skip to content

Commit

Permalink
update iterator protocol for twohash
Browse files Browse the repository at this point in the history
  • Loading branch information
jckarter committed Mar 29, 2012
1 parent fd5c0ae commit 3690381
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
36 changes: 23 additions & 13 deletions lib-clay/twohash/implementation/implementation.clay
Expand Up @@ -242,6 +242,11 @@ record TwoHashEntries[E, F]
entryMask: Int,
);

record TwoHashEntry[E, F]
(
entry: Pointer[E],
);

[E, F]
overload TwoHashEntries[E, F](th: TwoHash[E])
{
Expand All @@ -254,22 +259,27 @@ overload TwoHashEntries[E, F](th: TwoHash[E])
overload iterator(x: TwoHashEntries[E, F]) = x;

[E, F]
overload hasNext?(x: TwoHashEntries[E, F]) = x.entryMask != 0;

[E, F]
overload next(x: TwoHashEntries[E, F])
overload nextValue(x: TwoHashEntries[E, F])
{
var k = lowBit(x.entryMask);
x.entryMask = x.entryMask - bitshl(1, k);
ref e = x.data^.tables[x.i][x.j].entries[k];
if (x.entryMask == 0)
{
nextBucket(x);
refillMask(x);
}
return ..F(e);
if (x.entryMask != 0) {
var k = lowBit(x.entryMask);
x.entryMask = x.entryMask - bitshl(1, k);
ref e = x.data^.tables[x.i][x.j].entries[k];
if (x.entryMask == 0)
{
nextBucket(x);
refillMask(x);
}
return TwoHashEntry[E,F](&e);
} else
return TwoHashEntry[E,F]();
}

[E, F]
overload hasValue?(x: TwoHashEntry[E, F]) = not null?(x.entry);
[E, F]
overload getValue(x: TwoHashEntry[E, F]) = forward ..F(&x.entry);

[E, F]
nextBucket(x: TwoHashEntries[E, F])
{
Expand Down
13 changes: 6 additions & 7 deletions lib-clay/twohash/twohash.clay
Expand Up @@ -317,13 +317,12 @@ private record SetVectorItems[K]
overload iterator(i: SetVectorItems[K]) = i;

[K]
overload hasNext?(i: SetVectorItems[K]) = (i.current^.next != i.sentinel);

[K]
overload next(i: SetVectorItems[K])
{
i.current = i.current^.next;
return ref i.current^.key;
overload nextValue(i: SetVectorItems[K]) {
if (i.current^.next != i.sentinel) {
i.current = i.current^.next;
return &i.current^.key;
} else
return null(Type(i.current^.key));
}

//
Expand Down

0 comments on commit 3690381

Please sign in to comment.