3
我正在尋找像不變的東西SortedSet
,除了我想要元素按順序排序,他們被傳遞到構造函數。斯卡拉是否有'唯一列表'類型?
UniqueList(4,2,3,1,1) // Throws exception
UniqueList(4,2,3,1) // Iterator yields: 4,2,3,1
我正在尋找像不變的東西SortedSet
,除了我想要元素按順序排序,他們被傳遞到構造函數。斯卡拉是否有'唯一列表'類型?
UniqueList(4,2,3,1,1) // Throws exception
UniqueList(4,2,3,1) // Iterator yields: 4,2,3,1
嘗試collection.mutable.LinkedHashSet
- 它有獨特的元素,並在添加元素的順序發生遍歷。
還有ListSet,雖然它將按相反順序將值傳遞給構造函數。
scala> import scala.collection.immutable.ListSet
import scala.collection.immutable.ListSet
scala> ListSet(1,2,3,4)
res7: scala.collection.immutable.ListSet[Int] = ListSet(4, 3, 2, 1)
有沒有不可改變的選擇? –
有'immutable.ListMap',但它有'O(n)'查找時間。看到這個答案︰http://stackoverflow.com/questions/9313866/immutable-scala-map-implementation-that-preserves-insertion-order – axel22
原諒我,如果我誤解斯卡拉地圖,但他們不是一個關鍵 - >價值收集?我只對價值感興趣...... –