summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-10-29 12:45:08 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2017-10-29 12:45:08 -0700
commit59ccaaa286fcc01fce9fd53415c526ef22b97e72 (patch)
treeed774663d55734ec0dd2169e43fd9a3eda1a64a7 /src
parent04a9cac84f0bb6d5f9d573539fbb54c81d689148 (diff)
downloadmill-59ccaaa286fcc01fce9fd53415c526ef22b97e72.tar.gz
mill-59ccaaa286fcc01fce9fd53415c526ef22b97e72.tar.bz2
mill-59ccaaa286fcc01fce9fd53415c526ef22b97e72.zip
Make `OSet` use `LinkedHashSet` instead of a parallel `Vector`
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/forge/Util.scala16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/main/scala/forge/Util.scala b/src/main/scala/forge/Util.scala
index c5f71b6b..9a225f8b 100644
--- a/src/main/scala/forge/Util.scala
+++ b/src/main/scala/forge/Util.scala
@@ -20,6 +20,7 @@ case class PathRef(path: ammonite.ops.Path){
}
}
+
trait MultiBiMap[K, V]{
def containsValue(v: V): Boolean
def lookupKey(k: K): OSet[V]
@@ -59,8 +60,8 @@ class MutableMultiBiMap[K, V]() extends MultiBiMap[K, V]{
/**
* A collection with enforced uniqueness, fast contains and deterministic
- * ordering. When a duplicate happens, it can be configured to either remove
- * it automatically or to throw an exception and fail loudly
+ * ordering. Raises an exception if a duplicate is found; call
+ * `toSeq.distinct` if you explicitly want to make it swallow duplicates
*/
trait OSet[V] extends TraversableOnce[V]{
def contains(v: V): Boolean
@@ -71,8 +72,8 @@ trait OSet[V] extends TraversableOnce[V]{
def collect[T](f: PartialFunction[V, T]): OSet[T]
def zipWithIndex: OSet[(V, Int)]
def reverse: OSet[V]
-
}
+
object OSet{
def apply[V](items: V*) = from(items)
@@ -82,18 +83,19 @@ object OSet{
set
}
}
+
class MutableOSet[V]() extends OSet[V]{
- private[this] val items0 = mutable.ArrayBuffer.empty[V]
- private[this] val set0 = mutable.Set.empty[V]
+
+ private[this] val set0 = mutable.LinkedHashSet.empty[V]
def contains(v: V) = set0.contains(v)
def append(v: V) = if (!contains(v)){
set0.add(v)
- items0.append(v)
+
}else {
throw new Exception("Duplicated item inserted into OrderedSet: " + v)
}
def appendAll(vs: Seq[V]) = vs.foreach(append)
- def items: IndexedSeq[V] = items0
+ def items: IndexedSeq[V] = set0.toIndexedSeq
def set: collection.Set[V] = set0
def map[T](f: V => T): OSet[T] = {