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

fix Issue 14385 - AA should use open addressing hash #1229

Merged
merged 3 commits into from
Apr 24, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/object.di
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading