New hash
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Mar 23 18:49:22 PDT 2012
On Sat, Mar 24, 2012 at 02:39:35AM +0100, Andrej Mitrovic wrote:
> I thought I'd open this topic for discussion of issues with the new
> hash implementation.
Thanks for taking the time to test the code!
> Anyways, this doesn't seem to work:
>
> AA!(string,int[]) hash;
>
> D:\dev\projects\New-AA-implementation>rdmd
> -ID:\DMD\dmd2\src\druntime\src newAATest.d
> newAA.d(581): Error: template
> newAA.AA!(string,int[]).AssociativeArray.Slot.__ctor(K) if
> (keyCompat!(K)) cannot deduce template function from argument types
> !()(const(uint),const(immutable(char)[]),const(int[]),Slot*)
> newAA.d(581): Error: no constructor for Slot
> newAATest.d(33): Error: template instance newAA.AA!(string,int[])
> error instantiating
> Failed: "dmd" "-ID:\DMD\dmd2\src\druntime\src" "-v" "-o-" "newAATest.d" "-I."
> >Exit code: 1
Argh. Looks like it's caused by more const madness. :-( Try this diff:
diff --git a/newAA.d b/newAA.d
index a513b31..ac91e0c 100644
--- a/newAA.d
+++ b/newAA.d
@@ -576,7 +576,7 @@ public:
return this;
}
- @property auto dup() const @safe
+ @property auto dup() @safe
{
AssociativeArray!(Key,Value) result;
if (impl !is null)
@@ -584,7 +584,7 @@ public:
result.impl = new Impl();
result.impl.slots = alloc(findAllocSize(impl.nodes));
- foreach (const(Slot)* slot; impl.slots)
+ foreach (Slot* slot; impl.slots)
{
while (slot)
{
@@ -946,6 +946,11 @@ unittest {
assert(aa[key1] == 123);
}
+// Bug found by Andrej Mitrovic: can't instantiate AA!(string,int[]).
+unittest {
+ AA!(string,int[]) aa;
+}
+
// Issues 7512 & 7704
unittest {
AA!(dstring,int) aa;
---snip---
This is just a rough hack that removes the const from dup(). I need to
look at it more carefully to figure out how to copy stuff over without
violating constness. :-(
T
--
English has the lovely word "defenestrate", meaning "to execute by throwing someone out a window", or more recently "to remove Windows from a computer and replace it with something useful". :-) -- John Cowan
More information about the Digitalmars-d
mailing list