February 17, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | While it was 2/17/04 4:37 PM throughout the UK, Sean Kelly sprinkled little black dots on a white screen, and they fell thus: > Stewart Gordon wrote: <snip> >> Why, exactly? Do you implement it as a hash table of binary trees? Surely associative arrays shouldn't be restricted to classes that have an ordering? > > The Dinkumware STL implements hash sets as a hash wrapper around an ordered deque. I suppose this is one possibility. <snip> Ah, I never imagined that the associative array implementation in DMD was a wrapper around a third-party library that isn't fully compatible with the objective. If that's the case, I suppose this fact is the problem that needs fixing. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
February 17, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
>
> Ah, I never imagined that the associative array implementation in DMD was a wrapper around a third-party library that isn't fully compatible with the objective. If that's the case, I suppose this fact is the problem that needs fixing.
I don't think it is. I was merely pointing out that some hash set implementation may use compare operations rather than equality.
Sean
|
February 18, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> The associative array code for class objects uses toHash() and opCmp(). See
> std\typeinfo\ti_C.d. You'll need to overload opCmp() for your example.
Simply instrumenting the calls to `toHash', etc. shows that `opCmp' is not called, maybe because a null-pointer is compared:
toHash c
starting the requests
toHash c
toHash c
4
toHash c
No such element
toHash C
No such element
It is not clear, why `toHash' is called twice for the evaluation, that an element indeed is in the associative array.
So long.
|
February 18, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | While it was 2/17/04 8:30 PM throughout the UK, Sean Kelly sprinkled little black dots on a white screen, and they fell thus: > Stewart Gordon wrote: > > >> Ah, I never imagined that the associative array implementation in DMD was a wrapper around a third-party library that isn't fully compatible with the objective. If that's the case, I suppose this fact is the problem that needs fixing. > > I don't think it is. I was merely pointing out that some hash set implementation may use compare operations rather than equality. Exactly - *some* hash set implementation. Repeatedly citing third-party examples says nothing about the DMD implementation, and even less about its rationale. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
February 18, 2004 [Workaround] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | While we're still pondering over the issue, I've just written an associative array implementation that works on classes. http://smjg.port5.com/pr/d/hashmap.d http://smjg.port5.com/pr/d/hashmaptest.d Hopefully it's self-explanatory. I haven't yet tested it on a struct. Of course, the sooner this workaround becomes unnecessary, the better for the D programming community as a whole. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
February 21, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | "Ivan Senji" <ivan.senji@public.srce.hr> wrote in message news:c0l1ij$2p85$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:c0kf1m$1psq$3@digitaldaemon.com... > > The associative array code for class objects uses toHash() and opCmp(). > See > > std\typeinfo\ti_C.d. You'll need to overload opCmp() for your example. > > > > i tried: > > class ABC > { > this(int x,int y, int z) > { > a = x; > b = y; > c = z; > } > override uint toHash() > { > return a+b+c; > } > int opCmp ( ABC x) > { > return this.toHash() - x.toHash(); > } > int a,b,c; > } > > ... an leter: > > int[ABC] AA; > > ABC a111 = new ABC(1,1,1); > ABC b222 = new ABC(2,2,2); > ABC c111 = new ABC(1,1,1); > > assert(a111<b222); > assert(!(a111<c111)); > > AA[a111] = 111; > AA[b222] = 222; > > assert(AA.length == 2); > > AA[c111] = 111; > > assert(AA.length == 2); // this asser fails because there are 3 elements in > associative > //array but there should be only 2! > > Am i doing something wrong? There are 3 because the objects are distinct. |
February 21, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | "Manfred Nowak" <svv1999@hotmail.com> wrote in message news:c0uct3$2glo$1@digitaldaemon.com... > Walter wrote: > > > The associative array code for class objects uses toHash() and opCmp(). See > > std\typeinfo\ti_C.d. You'll need to overload opCmp() for your example. > > Simply instrumenting the calls to `toHash', etc. shows that `opCmp' is not called, maybe because a null-pointer is compared: > > toHash c > starting the requests > toHash c > toHash c > 4 > toHash c > No such element > toHash C > No such element > > It is not clear, why `toHash' is called twice for the evaluation, that an element indeed is in the associative array. opCmp is only called if two objects hash to the same value. |
February 21, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
>
> There are 3 because the objects are distinct.
So assuming two objects hash to the same value and compare as equivalent, then object addresses are compared? Or does this comparison occur earlier. I'm wondering if I will have to keep the original key object around to retrieve stored values or if I can somehow pass an equivalent one as a key.
Sean
|
February 22, 2004 Re: [Bug?] Associative array with class key doesn't work | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> opCmp is only called if two objects hash to the same value.
Because multiple objects can hash to the same value how does the algorithm find out without comparing, that an object found is indeed the object searched for?
So long.
|
Copyright © 1999-2021 by the D Language Foundation