Mixin demo: associative array initializers (with support for

Dan murpsoft at hotmail.com
Wed Mar 14 10:09:32 PDT 2007


Walter Bright Wrote:
> This is pretty cool that you were able to figure out a way to do this. 
> My job is to find a way that you can do such things without it looking 
> horrible <g>.

No offense man, 'cause I respect what you've done here.  Associative arrays are royally b0rked right now, and I have the latest version of D.

While I understand that there's probably a few issues with the use of pointers in your hashtable.  I was wondering if it was possible to let us use operator overrides to use associative arrays, much like we can for opArraySlice() and such?

That would let us implement custom hashing/searching functions as appropriate to the situation.

Alternatively, you can use a cascading system based on the length of the array.  Under 4096 items, using a left-median left-mininum binary search array will outperform your hash.

x = [_,3,1,5,0,2,4,6];
y = &x[1];

y <<= 1 // goes left
y <<= 1; y++; // goes right

Rebalancing takes only a few cycles, and extending the array for another depth increases at log(n) instead of n for median-median left-mininum search arrays.

Anyways... best of luck.



More information about the Digitalmars-d mailing list