Accessing contents of associative arrays in an optimal way
phant0m via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jul 9 13:32:38 PDT 2016
Suppose I have AA of structures:
struct Foo {
int value;
string name;
}
Foo[int] records;
As far as I know, AA implemented as a hashtable. So, will there
be two searches performed (one search for each line)?
records[3].value = 10;
records[3].name = "name";
How can I access elements of this AA by a "reference"? In C++ I
can use reference to an element of the map:
Foo& foo = records.find(3).second;
foo.value = 10;
foo.name = "name";
I found that in D I can use a "with" keyword to achieve the same
effect:
with(values[0]) {
value = 10;
name = "name";
}
Is this the only optimal way?
More information about the Digitalmars-d-learn
mailing list