digitalmars.D - Multi-associative array
- Etienne Cimon (5/5) Feb 22 2014 Would it eventually be in the making for D to have associative arrays
- Max Klyga (4/11) Feb 22 2014 Wanted to recomend using tuples, but it seems TypeInfo.compare is not
- H. S. Teoh (14/19) Feb 22 2014 [...]
- Etienne Cimon (11/13) Feb 22 2014 I thought of that but it's not immediately obvious how I could achieve
- Vladimir Panteleev (8/13) Feb 23 2014 You can't sort an AA, as AAs are unordered. Did you mean to sort
- Andrei Alexandrescu (8/21) Feb 23 2014 The way multiple binary tree (or rb-tree) indexes are achieved is by
Would it eventually be in the making for D to have associative arrays like string[string, int, Item]? If it hasn't been planned, I'd say it would be great to have an API that allows it to carry functionality of Boost Multi Index Thoughts?
Feb 22 2014
On 2014-02-23 03:10:23 +0000, Etienne Cimon said:Would it eventually be in the making for D to have associative arrays like string[string, int, Item]? If it hasn't been planned, I'd say it would be great to have an API that allows it to carry functionality of Boost Multi Index Thoughts?Wanted to recomend using tuples, but it seems TypeInfo.compare is not implemented for tuples. Not sure it its a bug or is it fixed in current compiler versions.
Feb 22 2014
On Sat, Feb 22, 2014 at 10:10:23PM -0500, Etienne Cimon wrote:Would it eventually be in the making for D to have associative arrays like string[string, int, Item]? If it hasn't been planned, I'd say it would be great to have an API that allows it to carry functionality of Boost Multi Index[...] You can just use a struct or tuple as the AA key to achieve the same thing. struct Key { string x; int y; Item z; } string[Key] aa; aa[Key("a", 1, Item(...))] = "b"; T -- Some days you win; most days you lose.
Feb 22 2014
On 2014-02-23 01:27, H. S. Teoh wrote:You can just use a struct or tuple as the AA key to achieve the same thing.I thought of that but it's not immediately obvious how I could achieve sorting or filtering by a certain field e.g. auto sorted = aa.sort!(Key.y => { a < b }) auto filtered = aa.filter! .... foreach(x, y, z ; aa){ .... } I don't see a very simple way of doing this right now. I'm sure someone thought of a library for this?
Feb 22 2014
On Sunday, 23 February 2014 at 07:10:32 UTC, Etienne Cimon wrote:auto sorted = aa.sort!(Key.y => { a < b })You can't sort an AA, as AAs are unordered. Did you mean to sort the keys? auto sorted = aa.keys.sort!((a, b) => a.y < b.y)();auto filtered = aa.filter! ....auto filtered = aa.keys.filter!(k => k.y > 2).array;foreach(x, y, z ; aa){ .... }foreach (key, value; aa) with(key) { ... use x, y, z ... }
Feb 23 2014
On 2/22/14, 11:10 PM, Etienne Cimon wrote:On 2014-02-23 01:27, H. S. Teoh wrote:The way multiple binary tree (or rb-tree) indexes are achieved is by storing multiple pointers with the same value. That way really multiple threes are threaded using the same value nodes. There's no trivial way to do this. It would be very valuable to generalize RBTree to accept multiple predicates and build such multiple indexes. AndreiYou can just use a struct or tuple as the AA key to achieve the same thing.I thought of that but it's not immediately obvious how I could achieve sorting or filtering by a certain field e.g. auto sorted = aa.sort!(Key.y => { a < b }) auto filtered = aa.filter! .... foreach(x, y, z ; aa){ .... } I don't see a very simple way of doing this right now. I'm sure someone thought of a library for this?
Feb 23 2014