Re: Map with maintained insertion order

2012-03-26 Thread Richard Webb
I've done that in C++ before using Boost.MultiIndex, and i saw a post about a D port of that recently (I don't have the link to hand though).

Re: Map with maintained insertion order

2012-03-25 Thread Michael Rynn
On Fri, 23 Mar 2012 23:48:51 +0100, Andrej Mitrovic wrote: > Does someone have a map implementation that maintains the insertion > order of the keys? > > E.g.: > > string[string] map; > map["foo"] = "x"; > map["bar"] = "y"; > > When iterating over map keys I want to visit "foo" first, then "bar

Re: Map with maintained insertion order

2012-03-23 Thread Brad Anderson
On Saturday, 24 March 2012 at 01:07:56 UTC, Jonathan M Davis wrote: On Friday, March 23, 2012 23:48:51 Andrej Mitrovic wrote: Does someone have a map implementation that maintains the insertion order of the keys? E.g.: string[string] map; map["foo"] = "x"; map["bar"] = "y"; When iterating ov

Re: Map with maintained insertion order

2012-03-23 Thread Andrej Mitrovic
On 3/24/12, Andrej Mitrovic wrote: > Correction, it's: > template isValue(T) > { > enum bool isValue = is(typeof( { Value v; T t; v = t; } )) > || is(typeof( { BaseElement!Value v; T t; v = t; } )) > || is(BaseElement!Value == T); > } Last check not needed, so: > template isValue(T) >

Re: Map with maintained insertion order

2012-03-23 Thread Andrej Mitrovic
On 3/24/12, Andrej Mitrovic wrote: > static if (isArray!Value) > { > template isValue(T) > { >enum bool isValue = is(typeof( { Value v; T t; v = t; } )) || > is(BaseElement!Value == T); > } > } Correction, it's: template isValue(T) { enum bool isValue = is(typeof( { Value

Re: Map with maintained insertion order

2012-03-23 Thread Andrej Mitrovic
On 3/24/12, Andrej Mitrovic wrote: > On 3/23/12, Andrej Mitrovic wrote: >> Does someone have a map implementation that maintains the insertion >> order of the keys? > > Here's a sloppy implementation: I forgot to make opIndex ref, but also the isValue check fails on structs with alias this, it's

Re: Map with maintained insertion order

2012-03-23 Thread H. S. Teoh
On Fri, Mar 23, 2012 at 06:33:54PM -0700, H. S. Teoh wrote: > On Fri, Mar 23, 2012 at 06:07:42PM -0700, Jonathan M Davis wrote: > > On Friday, March 23, 2012 23:48:51 Andrej Mitrovic wrote: > > > Does someone have a map implementation that maintains the insertion > > > order of the keys? > > > > >

Re: Map with maintained insertion order

2012-03-23 Thread H. S. Teoh
On Fri, Mar 23, 2012 at 06:07:42PM -0700, Jonathan M Davis wrote: > On Friday, March 23, 2012 23:48:51 Andrej Mitrovic wrote: > > Does someone have a map implementation that maintains the insertion > > order of the keys? > > > > E.g.: > > > > string[string] map; > > map["foo"] = "x"; > > map["bar

Re: Map with maintained insertion order

2012-03-23 Thread Andrej Mitrovic
On 3/24/12, Jonathan M Davis wrote: > I can't think of any data structure that does that off the top of my head Java has it and they call it a LinkedHashMap: http://docs.oracle.com/javase/1.4.2/docs/api/java/util/LinkedHashMap.html > That _does_ require having two data structures in one, and the

Re: Map with maintained insertion order

2012-03-23 Thread Andrej Mitrovic
On 3/23/12, Andrej Mitrovic wrote: > Does someone have a map implementation that maintains the insertion > order of the keys? Here's a sloppy implementation: module test; import std.stdio; import std.traits; template KeyType(V : V[K], K) if (isAssociativeArray!(V[K])) { alias K KeyType

Re: Map with maintained insertion order

2012-03-23 Thread Jonathan M Davis
On Friday, March 23, 2012 23:48:51 Andrej Mitrovic wrote: > Does someone have a map implementation that maintains the insertion > order of the keys? > > E.g.: > > string[string] map; > map["foo"] = "x"; > map["bar"] = "y"; > > When iterating over map keys I want to visit "foo" first, then "bar",