digitalmars.D - Doc confusion about AA rehash method
- James Dunne (12/12) Aug 27 2005 rehash: "Reorganizes the associative array in place so that lookups are...
- Manfred Nowak (7/8) Aug 28 2005 [...]
- Ben Hinkle (9/17) Aug 28 2005 Rehash returns the equivalent to "this".
- James Dunne (7/26) Aug 28 2005 So, always use the reference returned by the rehash property then? Is t...
-
Stewart Gordon
(20/23)
Aug 31 2005
- Ben Hinkle (9/24) Aug 31 2005 I'm comfortable with in-place applying only to the specific reference (j...
- Stewart Gordon (23/40) Aug 31 2005 With structs and their having value semantics, it's perfectly possible
rehash: "Reorganizes the associative array in place so that lookups are more efficient. rehash is effective when, for example, the program is done loading up a symbol table and now needs fast lookups in it. Returns a reference to the reorganized array." This says what seem to be (at first) two contradictory things: 1) rehash is an in-place operation. 2) returns a reference to the reorganized array. The abiguity is in the 2nd statement. Is the "reorganized array" the same array reference you called the rehash property on? If it is an in-place operation, then I would assume so. This should be rewritten. Regards, James Dunne
Aug 27 2005
James Dunne wrote in news:deqogk$27c8$1 digitaldaemon.com [...]The abiguity is in the 2nd statement.[...] Not an ambiguity, because .rehash may very well return a superfluous reference to the AA given. But the implementation shows, that .rehash is not a reorganization in place in all cases. -manfred
Aug 28 2005
"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:des8uk$g10$1 digitaldaemon.com...James Dunne wrote in news:deqogk$27c8$1 digitaldaemon.com [...]Rehash returns the equivalent to "this".The abiguity is in the 2nd statement.[...] Not an ambiguity, because .rehash may very well return a superfluous reference to the AA given.But the implementation shows, that .rehash is not a reorganization in place in all cases.I would say rehash is in-place. It allocates memory but that memory is hidden from the user. The original array reference is updated and any user pointers to the key/value pairs are preserved. What rehash does is it takes the given lvalue array reference, rehashes it and assigns the new data (length+pointer) back into the lvalue and returns it.
Aug 28 2005
In article <desdu4$jtc$1 digitaldaemon.com>, Ben Hinkle says..."Manfred Nowak" <svv1999 hotmail.com> wrote in message news:des8uk$g10$1 digitaldaemon.com...So, always use the reference returned by the rehash property then? Is this how the sort property works also? If not, the two should be consistent in their usage patterns. That or the documentation should be clarified to reflect that the two behave the same. Regards, James DunneJames Dunne wrote in news:deqogk$27c8$1 digitaldaemon.com [...]Rehash returns the equivalent to "this".The abiguity is in the 2nd statement.[...] Not an ambiguity, because .rehash may very well return a superfluous reference to the AA given.But the implementation shows, that .rehash is not a reorganization in place in all cases.I would say rehash is in-place. It allocates memory but that memory is hidden from the user. The original array reference is updated and any user pointers to the key/value pairs are preserved. What rehash does is it takes the given lvalue array reference, rehashes it and assigns the new data (length+pointer) back into the lvalue and returns it.
Aug 28 2005
Ben Hinkle wrote: <snip>I would say rehash is in-place. It allocates memory but that memory is hidden from the user. The original array reference is updated and any user pointers to the key/value pairs are preserved.<snip> Rehashing in-place implies that all references to the same AA remain in sync. int[int] qwert; ... int[int] yuiop = qwert; int[int] asdfg = yuiop.rehash; assert (qwert is yuiop); assert (yuiop is asdfg); Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Aug 31 2005
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:df42n3$1cvk$1 digitaldaemon.com...Ben Hinkle wrote: <snip>I'm comfortable with in-place applying only to the specific reference (just as inserting an element into an AA) but since you and other apparently read the phrase "in-place" differently then clearly Walter needs to spell out what he means exactly by in-place. There would be no confusion if he stuck in a sentance that said exactly what it does. ps - what's with the variable names - yuiop, asdfg? Aren't a,b,c or x,y,z enough? :-)I would say rehash is in-place. It allocates memory but that memory is hidden from the user. The original array reference is updated and any user pointers to the key/value pairs are preserved.<snip> Rehashing in-place implies that all references to the same AA remain in sync. int[int] qwert; ... int[int] yuiop = qwert; int[int] asdfg = yuiop.rehash; assert (qwert is yuiop); assert (yuiop is asdfg); Stewart.
Aug 31 2005
Ben Hinkle wrote: <snip>With structs and their having value semantics, it's perfectly possible to have methods that fail the first assert or even both asserts. OTOH a class can't fail the first assert, since it can't change what object yuiop references. But looking at internal/aaA.d, the function signature is aaA*[] _aaRehash(aaA*[]* paa, TypeInfo keyti) which seems to imply that an AA is an aaA*[]. And the code of the function implies that, if there's anything to do, it always reallocates the hashtable. So it seems you're right, and AAs behave the struct way to this level. The documentation needs tidying up a bit indeed.int[int] qwert; ... int[int] yuiop = qwert; int[int] asdfg = yuiop.rehash; assert (qwert is yuiop); assert (yuiop is asdfg); Stewart.I'm comfortable with in-place applying only to the specific reference (just as inserting an element into an AA) but since you and other apparently read the phrase "in-place" differently then clearly Walter needs to spell out what he means exactly by in-place. There would be no confusion if he stuck in a sentance that said exactly what it does.ps - what's with the variable names - yuiop, asdfg? Aren't a,b,c or x,y,z enough? :-)Just my version of the old foo, bar, baz, etc.... http://www.foldoc.org/?metasyntactic+variable Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Aug 31 2005