On Wednesday, 24 October 2012 at 20:03:44 UTC, H. S. Teoh wrote:
What's wrong with RedBlackTree? You can just do something like:
RedBlackTree!(RedBlackTree!MySet) setOfSets;
The last time I checked two RedBlackTrees for equality, they
seemed to have reference semantics...
[...]
So you can't really write a real program in D, to put it
blunty.
That's a bit harsh.
Sorry, just saying what I experienced :(
It's not hard to write your own hash implementation in D
I beg to differ, see below
given the expressiveness of its templates and compile-time
features. The bugginess of the built-in AA is lamentable,
definitely, but it doesn't *prevent* you from writing your own
data structures.
It does. There's simply no mechanism to hash an arbitrary thing
in D.
(hashOf, which Andrej just mentioned, is an internal thing,
right? aka a hack, which I was not aware of)
All programmers worth their salt should be able to roll their
own where the current implementation is inadequate, anyway. ;-)
Well, there's different issues involved...
- Can I? Yes.
- Will I? No, it takes more time than it's worth
In any case, as they say in the open source community, patches
are always welcome.
Yeah, it's just that I can't figure out even the basics of
hashing in D (above), so I can't really patch something because
then it'll turn out to be working in a different way than I
expect.
It only takes 15 minutes to write your own opEquals() in a
struct that wraps around an AA
I've spent longer than that right now and still haven't been able
to (but I haven't tried the hashOf hack yet).
Maybe you can fill in the blanks?
struct Set(T)
{
int[T] dict;
hash_t toHash() const
{
typeof(return) r = 0;
foreach (item; this.dict.keys)
{
??? // what should be here?
}
return r;
}
}