Re: Associative array key order

2013-08-23 Thread H. S. Teoh
On Fri, Aug 23, 2013 at 11:22:47AM -0700, Sean Kelly wrote: > On Jul 31, 2013, at 7:55 AM, Dicebot wrote: > > > On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: > >> is there a way for AA to behave same as PHP? > > > > I doubt it. This snippet suggests that AA's in PHP are not sim

Re: Associative array key order

2013-08-23 Thread Sean Kelly
On Jul 31, 2013, at 7:55 AM, Dicebot wrote: > On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: >> is there a way for AA to behave same as PHP? > > I doubt it. This snippet suggests that AA's in PHP are not simply AA's and do > additionally track insertion order (or use some simil

Re: Associative array key order

2013-08-23 Thread bearophile
H. S. Teoh: ... Your answer was really too much short, so I have asked you a question in that enhancement request :-) Bye, bearophile

Re: Associative array key order

2013-08-23 Thread bearophile
H. S. Teoh: ... On this subject, I added this request to Bugzilla: http://d.puremagic.com/issues/show_bug.cgi?id=10733 Bye, bearophile

Re: Associative array key order

2013-08-23 Thread H. S. Teoh
On Fri, Aug 23, 2013 at 01:54:27PM +0200, Daniel Kozak wrote: > https://github.com/Kozzi11/Trash/blob/master/util/orderedaa.d [...] Neat! Is a doubly-linked list really necessary for the hash buckets? You could save on some memory & improve performance slightly if you use a singly-linked list for

Re: Associative array key order

2013-08-23 Thread Daniel Kozak
When I do some cleanups, I find some bugs and after fixing them, my own OrderedAA implementation does not beat builtin hash anymore :(. But speed is still really near to builtin AA's. On Thursday, 22 August 2013 at 07:59:05 UTC, Daniel Kozak wrote: On Wednesday, 31 July 2013 at 14:55:55 UTC, D

Re: Associative array key order

2013-08-23 Thread Daniel Kozak
https://github.com/Kozzi11/Trash/blob/master/util/orderedaa.d On Thursday, 22 August 2013 at 08:41:13 UTC, monarch_dodra wrote: On Thursday, 22 August 2013 at 07:59:05 UTC, Daniel Kozak wrote: On Wednesday, 31 July 2013 at 14:55:55 UTC, Dicebot wrote: On Wednesday, 31 July 2013 at 14:43:21 UTC,

Re: Associative array key order

2013-08-22 Thread Daniel Kozak
On Thursday, 22 August 2013 at 08:41:13 UTC, monarch_dodra wrote: On Thursday, 22 August 2013 at 07:59:05 UTC, Daniel Kozak wrote: On Wednesday, 31 July 2013 at 14:55:55 UTC, Dicebot wrote: On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: is there a way for AA to behave same as

Re: Associative array key order

2013-08-22 Thread monarch_dodra
On Thursday, 22 August 2013 at 07:59:05 UTC, Daniel Kozak wrote: On Wednesday, 31 July 2013 at 14:55:55 UTC, Dicebot wrote: On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: is there a way for AA to behave same as PHP? I doubt it. This snippet suggests that AA's in PHP are not

Re: Associative array key order

2013-08-22 Thread Daniel Kozak
On Wednesday, 31 July 2013 at 14:55:55 UTC, Dicebot wrote: On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: is there a way for AA to behave same as PHP? I doubt it. This snippet suggests that AA's in PHP are not simply AA's and do additionally track insertion order (or use som

Re: Associative array key order

2013-07-31 Thread Ary Borenszweig
On 7/31/13 12:56 PM, H. S. Teoh wrote: On Wed, Jul 31, 2013 at 12:51:25PM -0300, Ary Borenszweig wrote: On 7/31/13 12:05 PM, bearophile wrote: Daniel Kozak: is there a way for AA to behave same as PHP? D associative arrays are based on hashing, so they do not keep the order of the items. Th

Re: Associative array key order

2013-07-31 Thread bearophile
Ary Borenszweig: However in Ruby 1.9 they are ordered. You only need to store in each bucket entry a pointer to the next bucket. Then traversing the hash is super fast (just follow the links) while preserving insertion order. Accessing by key still uses the buckets and entries (if that's how

Re: Associative array key order

2013-07-31 Thread H. S. Teoh
On Wed, Jul 31, 2013 at 12:51:25PM -0300, Ary Borenszweig wrote: > On 7/31/13 12:05 PM, bearophile wrote: > >Daniel Kozak: > > > >> is there a way for AA to behave same as PHP? > > > >D associative arrays are based on hashing, so they do not keep the > >order of the items. This is true in Python to

Re: Associative array key order

2013-07-31 Thread Ary Borenszweig
On 7/31/13 12:05 PM, bearophile wrote: Daniel Kozak: is there a way for AA to behave same as PHP? D associative arrays are based on hashing, so they do not keep the order of the items. This is true in Python too. The Python standard library has a hash-based ordered dict that keeps the insert

Re: Associative array key order

2013-07-31 Thread bearophile
I remember there is a trick to find the address of a D associative array key given its value address, Perhaps you need a better explanation for that. Let's say your data structure is: final class OrderedAA(TK, TV) { struct MV { TV item; MV* pred, succ; } private M

Re: Associative array key order

2013-07-31 Thread bearophile
Daniel Kozak: is there a way for AA to behave same as PHP? D associative arrays are based on hashing, so they do not keep the order of the items. This is true in Python too. The Python standard library has a hash-based ordered dict that keeps the insertion order of the keys. There is no su

Re: Associative array key order

2013-07-31 Thread Daniel Kozak
On Wednesday, 31 July 2013 at 14:55:55 UTC, Dicebot wrote: On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: is there a way for AA to behave same as PHP? I doubt it. This snippet suggests that AA's in PHP are not simply AA's and do additionally track insertion order (or use som

Re: Associative array key order

2013-07-31 Thread Andrej Mitrovic
On Wednesday, 31 July 2013 at 15:00:34 UTC, Daniel Kozak wrote: Thanks I will use plain array, it is not perfect but better than nothing :) For some reason this (unordered keys) wasn't documented on the website, but it will be soon.

Re: Associative array key order

2013-07-31 Thread Dicebot
On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote: is there a way for AA to behave same as PHP? I doubt it. This snippet suggests that AA's in PHP are not simply AA's and do additionally track insertion order (or use some similar trick). Data in associative arrays is organized i

Re: Associative array key order

2013-07-31 Thread H. S. Teoh
On Wed, Jul 31, 2013 at 04:41:14PM +0200, Daniel Kozak wrote: > > D: > > foreach(key, val; ["query" : 1, "count" : 2]) writeln(key); // print > count query > foreach(key, val; ["count" : 1, "query" : 2]) writeln(key); // print > count query too > > PHP: > foreach(["query" => 1,"count"=>2] as $ke

Re: Associative array key order

2013-07-31 Thread Daniel Kozak
D: foreach(key, val; ["query" : 1, "count" : 2]) writeln(key); // print count query foreach(key, val; ["count" : 1, "query" : 2]) writeln(key); // print count query too PHP: foreach(["query" => 1,"count"=>2] as $key => $val) echo $key; // print query count foreach(["count" => 1,"

Associative array key order

2013-07-31 Thread Daniel Kozak
D: foreach(key, val; ["query" : 1, "count" : 2]) writeln(key); // print count query foreach(key, val; ["count" : 1, "query" : 2]) writeln(key); // print count query too PHP: foreach(["query" => 1,"count"=>2] as $key => $val) echo $key; // print query count foreach(["count" => 1,"query"=>2] a