Associative array key order
bearophile
bearophileHUGS at lycos.com
Wed Jul 31 08:18:25 PDT 2013
> 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 MV[TK] data;
...
}
it's a wrapper to a built-in associative array. Each value is a
struct that beside the original value contains a pointer to the
precedent and successive MV, in a doubly linked list.
The member functions of OrderedAA that add or remove items from
the associative array manage the linked list of values. The
iteration is a range that follows the linked list. But this way
you only scan the values... To also scan keys or key-val pairs
you have to find the pointer to the key.
Maybe it's worth adding in Bugzilla an ehnancement request for a
portable way to find that pointer... to implement a hash-based
ordered associative array in library code.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list