Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Rename Growable.add to addOne #337

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ArrayBufferBenchmark {
var ys = xs
var i = 0L
while (i < 1000) {
ys.add(i)
ys.addOne(i)
i += 1
}
bh.consume(ys)
Expand All @@ -80,7 +80,7 @@ class ArrayBufferBenchmark {
var ys = xs
var i = 0L
while (i < 1000) {
ys.add(i)
ys.addOne(i)
i += 1
ys = ys.init
}
Expand All @@ -93,7 +93,7 @@ class ArrayBufferBenchmark {
val ys = xs
var i = 0L
while (i < 1000) {
if ((i & 1) == 1) ys.add(i)
if ((i & 1) == 1) ys.addOne(i)
else ys.insert(0, i)
i += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ListBufferBenchmark {
var ys = xs
var i = 0L
while (i < 1000) {
ys.add(i)
ys.addOne(i)
i += 1
}
bh.consume(ys)
Expand All @@ -80,7 +80,7 @@ class ListBufferBenchmark {
var ys = xs
var i = 0L
while (i < 1000) {
ys.add(i)
ys.addOne(i)
i += 1
ys = ys.init
}
Expand All @@ -93,7 +93,7 @@ class ListBufferBenchmark {
val ys = xs
var i = 0L
while (i < 1000) {
if ((i & 1) == 1) ys.add(i)
if ((i & 1) == 1) ys.addOne(i)
else ys.insert(0, i)
i += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
inserthc(k, hc, v)
}

def add(kv: (K, V)) = {
def addOne(kv: (K, V)) = {
update(kv._1, kv._2)
this
}
Expand All @@ -876,7 +876,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
removehc(k, null.asInstanceOf[V], hc)
}

def subtract(k: K) = {
def subtractOne(k: K) = {
remove(k)
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private[collection] trait Wrappers {
def apply(i: Int) = underlying.get(i)
def update(i: Int, elem: A) = underlying.set(i, elem)
def prepend(elem: A) = { underlying.subList(0, 0) add elem; this }
def add(elem: A): this.type = { underlying add elem; this }
def addOne(elem: A): this.type = { underlying add elem; this }
def insert(idx: Int,elem: A): Unit = underlying.subList(0, idx).add(elem)
def insertAll(i: Int, elems: IterableOnce[A]) = {
val ins = underlying.subList(0, i)
Expand Down Expand Up @@ -135,7 +135,7 @@ private[collection] trait Wrappers {
protected[this] def fromSpecificIterable(coll: Iterable[A]) = mutable.ArrayBuffer.from(coll)
def iterableFactory = mutable.ArrayBuffer
protected[this] def newSpecificBuilder() = mutable.ArrayBuffer.newBuilder()
def subtract(elem: A): this.type = { underlying.remove(elem.asInstanceOf[AnyRef]); this }
def subtractOne(elem: A): this.type = { underlying.remove(elem.asInstanceOf[AnyRef]); this }
}

@SerialVersionUID(1L)
Expand Down Expand Up @@ -187,8 +187,8 @@ private[collection] trait Wrappers {

def contains(elem: A): Boolean = underlying.contains(elem)

def add(elem: A): this.type = { underlying add elem; this }
def subtract(elem: A): this.type = { underlying remove elem; this }
def addOne(elem: A): this.type = { underlying add elem; this }
def subtractOne(elem: A): this.type = { underlying remove elem; this }

//TODO Should Set.remove return the canonical element? There is no efficient way to support this for wrapped Java Sets
override def remove(elem: A): Option[A] = if(underlying remove elem) Some(elem) else None
Expand Down Expand Up @@ -306,8 +306,8 @@ private[collection] trait Wrappers {
None
}

def add(kv: (K, V)): this.type = { underlying.put(kv._1, kv._2); this }
def subtract(key: K): this.type = { underlying remove key; this }
def addOne(kv: (K, V)): this.type = { underlying.put(kv._1, kv._2); this }
def subtractOne(key: K): this.type = { underlying remove key; this }

override def put(k: K, v: V): Option[V] = Option(underlying.put(k, v))

Expand Down Expand Up @@ -415,8 +415,8 @@ private[collection] trait Wrappers {

def get(k: A) = Option(underlying get k)

def add(kv: (A, B)): this.type = { underlying.put(kv._1, kv._2); this }
def subtract(key: A): this.type = { underlying remove key; this }
def addOne(kv: (A, B)): this.type = { underlying.put(kv._1, kv._2); this }
def subtractOne(key: A): this.type = { underlying remove key; this }

override def put(k: A, v: B): Option[B] = Option(underlying.put(k, v))

Expand Down Expand Up @@ -445,8 +445,8 @@ private[collection] trait Wrappers {
if (v != null) Some(v.asInstanceOf[String]) else None
}

def add(kv: (String, String)): this.type = { underlying.put(kv._1, kv._2); this }
def subtract(key: String): this.type = { underlying remove key; this }
def addOne(kv: (String, String)): this.type = { underlying.put(kv._1, kv._2); this }
def subtractOne(key: String): this.type = { underlying remove key; this }

override def put(k: String, v: String): Option[String] = {
val r = underlying.put(k, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ object HashMap extends MapFactory[HashMap] {

def newBuilder[K, V](): Builder[(K, V), HashMap[K, V]] =
new ImmutableBuilder[(K, V), HashMap[K, V]](empty) {
def add(elem: (K, V)): this.type = { elems = elems + elem; this }
def addOne(elem: (K, V)): this.type = { elems = elems + elem; this }
}

private[collection] abstract class Merger[A, B] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object HashSet extends IterableFactory[HashSet] {

def newBuilder[A](): Builder[A, HashSet[A]] =
new ImmutableBuilder[A, HashSet[A]](empty) {
def add(elem: A): this.type = { elems = elems + elem; this }
def addOne(elem: A): this.type = { elems = elems + elem; this }
}

private object EmptyHashSet extends HashSet[Any] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object IntMap {

def newBuilder[V](): Builder[(Int, V), IntMap[V]] =
new ImmutableBuilder[(Int, V), IntMap[V]](empty) {
def add(elem: (Int, V)): this.type = { elems = elems + elem; this }
def addOne(elem: (Int, V)): this.type = { elems = elems + elem; this }
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ sealed abstract class IntMap[+T] extends Map[Int, T]
def iterableFactory: IterableFactoryLike[Iterable] = Iterable
protected[this] def newSpecificBuilder(): Builder[(Int, T), IntMap[T]] =
new ImmutableBuilder[(Int, T), IntMap[T]](empty) {
def add(elem: (Int, T)): this.type = { elems = elems + elem; this }
def addOne(elem: (Int, T)): this.type = { elems = elems + elem; this }
}
def mapFactory: MapFactory[Map] = Map
protected[this] def mapFromIterable[K2, V2](it: strawman.collection.Iterable[(K2, V2)]): Map[K2,V2] = mapFactory.from(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object ListMap extends MapFactory[ListMap] {

def newBuilder[K, V](): Builder[(K, V), ListMap[K, V]] =
new ImmutableBuilder[(K, V), ListMap[K, V]](empty) {
def add(elem: (K, V)): this.type = { elems = elems + elem; this }
def addOne(elem: (K, V)): this.type = { elems = elems + elem; this }
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ object ListSet extends IterableFactory[ListSet] {

def newBuilder[A](): Builder[A, ListSet[A]] =
new ImmutableBuilder[A, ListSet[A]](empty) {
def add(elem: A): this.type = { elems = elems + elem; this }
def addOne(elem: A): this.type = { elems = elems + elem; this }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ sealed abstract class LongMap[+T] extends Map[Long, T]
def iterableFactory: IterableFactory[Iterable] = Iterable
protected[this] def newSpecificBuilder(): Builder[(Long, T), LongMap[T]] =
new ImmutableBuilder[(Long, T), LongMap[T]](empty) {
def add(elem: (Long, T)): this.type = { elems = elems + elem; this }
def addOne(elem: (Long, T)): this.type = { elems = elems + elem; this }
}
def mapFactory: MapFactory[Map] = Map
protected[this] def mapFromIterable[K2, V2](it: strawman.collection.Iterable[(K2, V2)]): Map[K2,V2] = mapFactory.from(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ object TreeMap extends SortedMapFactory[TreeMap] {

def newBuilder[K : Ordering, V](): Builder[(K, V), TreeMap[K, V]] =
new ImmutableBuilder[(K, V), TreeMap[K, V]](empty) {
def add(elem: (K, V)): this.type = { elems = elems + elem; this }
def addOne(elem: (K, V)): this.type = { elems = elems + elem; this }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ object TreeSet extends SortedIterableFactory[TreeSet] {

def newBuilder[A : Ordering](): Builder[A, TreeSet[A]] =
new ImmutableBuilder[A, TreeSet[A]](empty) {
def add(elem: A): this.type = { elems = elems + elem; this }
def addOne(elem: A): this.type = { elems = elems + elem; this }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ final class VectorBuilder[A]() extends ReusableBuilder[A, Vector[A]] with Vector
private var blockIndex = 0
private var lo = 0

def add(elem: A): this.type = {
def addOne(elem: A): this.type = {
if (lo >= display0.length) {
val newBlockIndex = blockIndex + 32
gotoNextBlockStartWritable(newBlockIndex, blockIndex ^ newBlockIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K => V, initi
}

/** Adds a new key/value pair to this map and returns the map. */
def add(key: K, value: V): this.type = { update(key, value); this }
def addOne(key: K, value: V): this.type = { update(key, value); this }

def add(kv: (K, V)): this.type = { update(kv._1, kv._2); this }
def addOne(kv: (K, V)): this.type = { update(kv._1, kv._2); this }

def subtract(key: K): this.type = {
def subtractOne(key: K): this.type = {
val i = seekEntry(hashOf(key), key)
if (i >= 0) {
_size -= 1
Expand Down Expand Up @@ -441,7 +441,7 @@ object AnyRefMap {
*/
final class AnyRefMapBuilder[K <: AnyRef, V] extends ReusableBuilder[(K, V), AnyRefMap[K, V]] {
private[collection] var elems: AnyRefMap[K, V] = new AnyRefMap[K, V]
def add(entry: (K, V)): this.type = {
def addOne(entry: (K, V)): this.type = {
elems += entry
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class ArrayBuffer[A] private (initElems: Array[AnyRef], initLength: Int)
def clear(): Unit =
end = 0

def add(elem: A): this.type = {
def addOne(elem: A): this.type = {
ensureSize(end + 1)
this(end) = elem
end += 1
this
}

def subtract(elem: A): this.type = {
def subtractOne(elem: A): this.type = {
val i = indexOf(elem)
if (i != -1) remove(i)
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: T): this.type = {
def addOne(elem: T): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -129,7 +129,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Byte): this.type = {
def addOne(elem: Byte): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -178,7 +178,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Short): this.type = {
def addOne(elem: Short): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -227,7 +227,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Char): this.type = {
def addOne(elem: Char): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -276,7 +276,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Int): this.type = {
def addOne(elem: Int): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -325,7 +325,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Long): this.type = {
def addOne(elem: Long): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -374,7 +374,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Float): this.type = {
def addOne(elem: Float): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -423,7 +423,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Double): this.type = {
def addOne(elem: Double): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -472,7 +472,7 @@ object ArrayBuilder {
capacity = size
}

def add(elem: Boolean): this.type = {
def addOne(elem: Boolean): this.type = {
ensureSize(size + 1)
elems(size) = elem
size += 1
Expand Down Expand Up @@ -508,7 +508,7 @@ object ArrayBuilder {
/** A class for array builders for arrays of `Unit` type. It can be reused. */
final class ofUnit extends ArrayBuilder[Unit] {

def add(elem: Unit): this.type = {
def addOne(elem: Unit): this.type = {
size += 1
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BitSet(protected[collection] final var elems: Array[Long])

protected[collection] def fromBitMaskNoCopy(elems: Array[Long]): BitSet = new BitSet(elems)

def add(elem: Int): this.type = {
def addOne(elem: Int): this.type = {
require(elem >= 0)
if (!contains(elem)) {
val idx = elem >> LogWL
Expand All @@ -64,7 +64,7 @@ class BitSet(protected[collection] final var elems: Array[Long])
this
}

def subtract(elem: Int): this.type = {
def subtractOne(elem: Int): this.type = {
require(elem >= 0)
if (contains(elem)) {
val idx = elem >> LogWL
Expand Down
Loading