Bag

trait Bag[A]
Companion:
object
class Object
trait Matchable
class Any
class BagSortedMap[A]

Value members

Abstract methods

def contains(elem: A): Boolean

Check if a bag contains an element

Check if a bag contains an element

def delete(elem: A): Bag[A]

Deletes an element and returns the new bag It doesn't complain if the element doesn't exist

Deletes an element and returns the new bag It doesn't complain if the element doesn't exist

def elems: Iterator[(A, Int)]

Elements of a Bag with their multiplicity

Elements of a Bag with their multiplicity

def insert(elem: A): Bag[A]

Inserts an element in a bag and returns the new bag

Inserts an element in a bag and returns the new bag

def multiplicity(elem: A): Int

Multiplicity of an element in a bag

Multiplicity of an element in a bag

Concrete methods

def add(elem: A, n: Int): Bag[A]

add an element n times to a bag This default implementation is not efficient, it should be overridden

add an element n times to a bag This default implementation is not efficient, it should be overridden

def from(t: Iterable[A]): Bag[A]
def size: Int

Size returns the total number of elements. Notice that if an element appears 4 times, it adds 4 to the counter

Size returns the total number of elements. Notice that if an element appears 4 times, it adds 4 to the counter

def toSeq: Seq[A]
def union(other: Bag[A]): Bag[A]

Union of two bags

Union of two bags