需要高性能 Scala/Java 集合
High performance Scala/Java collection needed
我正在寻找一个 Scala(或 Java/Guava)集合,它支持 O(1) 访问(最好是删除)它的最小元素以及 O(log n) 插入和删除任意元素元素。
想法?
创建您自己的由 ArrayList 支持的集合。它需要附加字段最小元素和最小元素的位置。如果该元素是新的最小值,则在添加元素时更新这些字段。
Implementation note: this implementation provides O(log(n)) time for the enqueuing and dequeuing methods (offer
, poll
, remove()
and add
); linear time for the remove(Object)
and contains(Object)
methods; and constant time for the retrieval methods (peek
, element
, and size
).
This class is a member of the Java Collections Framework.
我正在寻找一个 Scala(或 Java/Guava)集合,它支持 O(1) 访问(最好是删除)它的最小元素以及 O(log n) 插入和删除任意元素元素。
想法?
创建您自己的由 ArrayList 支持的集合。它需要附加字段最小元素和最小元素的位置。如果该元素是新的最小值,则在添加元素时更新这些字段。
Implementation note: this implementation provides O(log(n)) time for the enqueuing and dequeuing methods (
offer
,poll
,remove()
andadd
); linear time for theremove(Object)
andcontains(Object)
methods; and constant time for the retrieval methods (peek
,element
, andsize
).This class is a member of the Java Collections Framework.