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 ) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -