diff options
author | Paul Phillips <paulp@improving.org> | 2010-04-23 21:20:14 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-04-23 21:20:14 +0000 |
commit | eb1ee924dd922db2e967c8a38ec13410eeb7110f (patch) | |
tree | c47f0b34931797ebf271d41b0e13ec9d42e6032c /src/library/scala/collection/immutable/BitSet.scala | |
parent | db8bd90da4c78e543bad65dea5600febc6fbbd20 (diff) | |
download | scala-eb1ee924dd922db2e967c8a38ec13410eeb7110f.tar.gz scala-eb1ee924dd922db2e967c8a38ec13410eeb7110f.tar.bz2 scala-eb1ee924dd922db2e967c8a38ec13410eeb7110f.zip |
Created Mutable and Immutable SetFactories to d...
Created Mutable and Immutable SetFactories to deal with the spectacular
performance regression which accompanies the use of AddingBuilder on
mutable Sets. Because '+' now creates a new collection even on mutable
sets, AddingBuilder on a 100K element collection will create garbage
sets of size 1,2,3...,99,999 before finishing. Thankfully there is
already GrowingBuilder.
See test/files/run/adding-growing-set.scala for a demonstration.
This patch is not complete: in particular, SortedSet and SetBuilder need
attention. Unfortunately there is a combinatorial jump in the number of
Addable/Growable divisions which arises once one tries to accomodate
both Sorted signatures (taking an Ordering) and unsorted signatures, so
will come back to it after receiving counsel.
Review by odersky.
Diffstat (limited to 'src/library/scala/collection/immutable/BitSet.scala')
-rw-r--r-- | src/library/scala/collection/immutable/BitSet.scala | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/library/scala/collection/immutable/BitSet.scala b/src/library/scala/collection/immutable/BitSet.scala index 9b801f26cb..8fa23c3ddf 100644 --- a/src/library/scala/collection/immutable/BitSet.scala +++ b/src/library/scala/collection/immutable/BitSet.scala @@ -14,6 +14,7 @@ package immutable import generic._ import BitSetLike.{LogWL, updateArray} +import mutable.{ Builder, AddingBuilder } /** A class for immutable bitsets. * $bitsetinfo @@ -60,10 +61,12 @@ abstract class BitSet extends Set[Int] * @define coll immutable bitset */ object BitSet extends BitSetFactory[BitSet] { - /** The empty bitset */ val empty: BitSet = new BitSet1(0L) + /** An adding builder for immutable Sets. */ + def newBuilder: Builder[Int, BitSet] = new AddingBuilder[Int, BitSet](empty) + /** $bitsetCanBuildFrom */ implicit def canBuildFrom: CanBuildFrom[BitSet, Int, BitSet] = bitsetCanBuildFrom |