Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1229 from MartinNowak/open_addressing
Browse files Browse the repository at this point in the history
fix Issue 14385 - AA should use open addressing hash
  • Loading branch information
rainers committed Apr 24, 2015
2 parents 6d6aa3d + 88ee8db commit 6698ee2
Show file tree
Hide file tree
Showing 4 changed files with 737 additions and 873 deletions.
10 changes: 7 additions & 3 deletions src/object.di
Expand Up @@ -411,7 +411,7 @@ extern (C)
// alias _dg2_t = extern(D) int delegate(void*, void*);
// int _aaApply2(void* aa, size_t keysize, _dg2_t dg);

private struct AARange { void* impl, current; }
private struct AARange { void* impl; size_t idx; }
AARange _aaRange(void* aa) pure nothrow @nogc;
bool _aaRangeEmpty(AARange r) pure nothrow @nogc;
void* _aaRangeFrontKey(AARange r) pure nothrow @nogc;
Expand Down Expand Up @@ -542,7 +542,9 @@ auto byValue(T : Value[Key], Value, Key)(T *aa) pure nothrow @nogc
Key[] keys(T : Value[Key], Value, Key)(T aa) @property
{
auto a = cast(void[])_aaKeys(cast(inout(void)*)aa, Key.sizeof, typeid(Key[]));
return *cast(Key[]*)&a;
auto res = *cast(Key[]*)&a;
_doPostblit(res);
return res;
}

Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
Expand All @@ -553,7 +555,9 @@ Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
Value[] values(T : Value[Key], Value, Key)(T aa) @property
{
auto a = cast(void[])_aaValues(cast(inout(void)*)aa, Key.sizeof, Value.sizeof, typeid(Value[]));
return *cast(Value[]*)&a;
auto res = *cast(Value[]*)&a;
_doPostblit(res);
return res;
}

Value[] values(T : Value[Key], Value, Key)(T *aa) @property
Expand Down
37 changes: 34 additions & 3 deletions src/object_.d
Expand Up @@ -2003,7 +2003,7 @@ extern (C)
// alias _dg2_t = extern(D) int delegate(void*, void*);
// int _aaApply2(void* aa, size_t keysize, _dg2_t dg);

private struct AARange { void* impl, current; }
private struct AARange { void* impl; size_t idx; }
AARange _aaRange(void* aa) pure nothrow @nogc;
bool _aaRangeEmpty(AARange r) pure nothrow @nogc;
void* _aaRangeFrontKey(AARange r) pure nothrow @nogc;
Expand Down Expand Up @@ -2139,7 +2139,9 @@ auto byValue(T : Value[Key], Value, Key)(T *aa) pure nothrow @nogc
Key[] keys(T : Value[Key], Value, Key)(T aa) @property
{
auto a = cast(void[])_aaKeys(cast(inout(void)*)aa, Key.sizeof, typeid(Key[]));
return *cast(Key[]*)&a;
auto res = *cast(Key[]*)&a;
_doPostblit(res);
return res;
}

Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
Expand All @@ -2150,14 +2152,43 @@ Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
Value[] values(T : Value[Key], Value, Key)(T aa) @property
{
auto a = cast(void[])_aaValues(cast(inout(void)*)aa, Key.sizeof, Value.sizeof, typeid(Value[]));
return *cast(Value[]*)&a;
auto res = *cast(Value[]*)&a;
_doPostblit(res);
return res;
}

Value[] values(T : Value[Key], Value, Key)(T *aa) @property
{
return (*aa).values;
}

unittest
{
static struct T
{
static size_t count;
this(this) { ++count; }
}
T[int] aa;
T t;
aa[0] = t;
aa[1] = t;
assert(T.count == 2);
auto vals = aa.values;
assert(vals.length == 2);
assert(T.count == 4);

T.count = 0;
int[T] aa2;
aa2[t] = 0;
assert(T.count == 1);
aa2[t] = 1;
assert(T.count == 1);
auto keys = aa2.keys;
assert(keys.length == 1);
assert(T.count == 2);
}

auto byKeyValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc @property
{
static struct Result
Expand Down

0 comments on commit 6698ee2

Please sign in to comment.