When working with vectors and dictionaries, you can build simple or complex structures. For example, you can build vectors of vectors, or vectors of dictionaries, or any other mix.
dictionary(string, vector(money)) previousPrices; integer addPrice(string symbol, money price) { vector(money) prices := previousPrices[symbol]; if (isnull(prices)) { prices := new vector(money); previousPrices[symbol] := prices; } push_back(prices, price); }
vector(money) prices := previousPrices[symbol];Because it is a reference, the value inserted by push_back is in the vector the next time it is read from the dictionary.
dictionary(integer, integer) d0 := new dictionary(integer, integer); dictionary(integer, integer) d1 := d0; d1[0] := 1; if (d0[0] = 1) print('aliased!');