Scala : modify values in a TreeMap -
this scala newbie question.
i'm storing data in treemap
, values keep on modifying. example, in below class there map contains orders being sent market , want keep track of quantity of orders , each price. map change @ each order goes market.
class mydata { // price -> quantity map var orders: treemap[int, int] = treemap.empty }
now, when new order comes @ price of 100, can add map.
var = new mydata; // new order @ price 5 qty 200 a.orders += (5 -> 200)
now, order @ price 5 has been modified 100. how here treemap
?
a.orders ???
well... treemap
found in scala.collection.immutable
package.
notice immutable
thing. treemap
immutable data-structures means... can not modify in-place. no insertions, no updates, no changes @ all. can copy of modifications applied.
so... modify, have reassign a.orders
modified copy.
a.orders = a.orders + ( 5, 100 )