add section about associative arrays
This commit is contained in:
parent
d15f34a530
commit
bcb11b736b
1 changed files with 16 additions and 2 deletions
|
@ -721,3 +721,17 @@ Slices are the most prominent example of `RandomAccessRange`s in
|
||||||
The D standard library provides a huge arsenal of lazy range algorithm
|
The D standard library provides a huge arsenal of lazy range algorithm
|
||||||
functions. Most of them can be found in in the `std.range` and `std.algorithm`
|
functions. Most of them can be found in in the `std.range` and `std.algorithm`
|
||||||
packages.
|
packages.
|
||||||
|
|
||||||
|
### Associative arrays
|
||||||
|
|
||||||
|
D has builtin hashmaps, which are called _associative arrays_:
|
||||||
|
|
||||||
|
```D
|
||||||
|
int[string] map; // keys of type string, values of type int
|
||||||
|
map["key1"] = 10; // insertion or modification, if the key already exists
|
||||||
|
if ("key1" in map) { // checking if a key is in an associative array
|
||||||
|
writeln("key1 is in map");
|
||||||
|
}
|
||||||
|
assert(map.length == 1); // associative arrays provide a .length property
|
||||||
|
map.remove("key1"); // remove a key from an associative array
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue