Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
February 23, 2014 Multi-associative array | ||||
---|---|---|---|---|
| ||||
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? |
February 23, 2014 Re: Multi-associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | 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.
|
February 23, 2014 Re: Multi-associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | 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. |
February 23, 2014 Re: Multi-associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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?
|
February 23, 2014 Re: Multi-associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | 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 ... } |
February 24, 2014 Re: Multi-associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne Cimon | On 2/22/14, 11:10 PM, Etienne Cimon wrote:
> 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?
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.
Andrei
|
Copyright © 1999-2021 by the D Language Foundation