scala - Structure sorted by values instead of keys -


in scala, need create structure contains following:

  • a bitset - represents cells occupied or not
  • an int - last cell occupied
  • an int - cost of occupation

because element uniquely identified combination of bitset representing occupied cells , int representing last cell occupied, tried using following:

var tm = treemap.empty[path, int] 

where path is:

case class path(occupied: bitset, last: int) 

however, issue want sort elements in treemap cost(so value). apparently not possible treemap.

so can have structure sort elements value rather key?

i think sorted-set then:

import scala.collection.immutable.bitset import scala.collection.immutable.sortedset  case class path(occupied: bitset, last: int, cost: int)  implicit val pathord = ordering.by((p: path) => p.cost)  sortedset.empty[path] 

assuming cost field of path. if cost calculated path, define:

case class path(occupied: bitset, last: int) {   def cost: int = ??? } 

Comments