Source Code

Library providing general-purpose mutable lists, sets, and maps.

The following interfaces define abstract mutable collection types:

These interfaces define abstract sorted collection types:

In addition, dedicated Stack and Queue interfaces are defined, representing specialized kinds of lists.

These concrete implementations are provided:

  • ArrayList is a MutableList implemented using an Array.
  • LinkedList is a MutableList implemented using a singly-linked list.
  • PriorityQueue is a Queue implemented using an Array where the front of the queue is the smallest element
  • HashSet is a mutable hash set implemented using an Array of singly-linked lists.
  • HashMap is a mutable hash map implemented using an Array of singly-linked lists of Entrys.
  • TreeSet is a mutable SortedSet implemented using a red/black binary tree.
  • TreeMap is a mutable SortedMap implemented using a red/black binary tree.

The functions unmodifiableList(), unmodifiableSet(), and unmodifiableMap() may be used to hide these mutable list, set, and map implementations from clients.

SingletonMap and SingletonSet are immutable collections with exactly one element.

Finally, IdentitySet and IdentityMap are mutable collections based on identity instead of value equality.

By: Stéphane Épardaud
License: Apache Software License
Packages
ceylon.collection
Values
linkedSource Codeshared linked linked
unlinkedSource Codeshared unlinked unlinked
Functions
frequenciesSource Codeshared Map<Element,Integer> frequencies<Element>({Element*} elements)
given Element satisfies Object

Produces a Map mapping elements to frequencies, where each entry maps a distinct member of the given iterable elements to the number of times it occurs among the given elements.

groupSource Codeshared Map<Group,[Element+]> group<Group, Element>({Element*} elements, Group grouping(Element element))
given Group satisfies Object

Produces a Map grouping the given elements into sequences under the group keys provided by the given grouping function.

Parameters:
  • grouping

    A function that returns the group key under which to group the specified element.

naturalOrderTreeMapSource Codeshared TreeMap<Key,Item> naturalOrderTreeMap<Key, Item>({<Key->Item>*} entries)
given Key satisfies Comparable<Key>
given Item satisfies Object

Create a [[TreeMap] with comparable] keys, sorted by the natural ordering of the keys.

naturalOrderTreeSetSource Codeshared TreeSet<Element> naturalOrderTreeSet<Element>({Element*} entries)
given Element satisfies Comparable<Element>

Create a TreeSet with comparable keys, sorted by the natural ordering of the keys.

partitionSource Codeshared [Element[], Element[]] partition<Element>({Element*} elements, Boolean selecting(Element element))

Groups the given elements into two sequences, the first containing elements selected by the given predicate function, and the second containing elements rejected by the given predicate function.

Parameters:
  • selecting

    A predicate function that determines if a specified element should be selected or rejected. Returns true to indicate that the element is selected, or false to indicate that the element is rejected.

unmodifiableListSource Codeshared List<Element> unmodifiableList<Element>(List<Element> list)

Wrap the given List, preventing attempts to narrow the returned List to MutableList.

unmodifiableMapSource Codeshared Map<Key,Item> unmodifiableMap<Key, Item>(Map<Key,Item> map)
given Key satisfies Object
given Item satisfies Object

Wrap the given Map, preventing attempts to narrow the returned Map to MutableMap.

unmodifiableSetSource Codeshared Set<Element> unmodifiableSet<Element>(Set<Element> set)
given Element satisfies Object

Wrap the given Set, preventing attempts to narrow the returned Set to MutableSet.

Interfaces
ListMutatorSource Codeshared ListMutator<in Element>

Protocol for mutation of a MutableList.

MapMutatorSource Codeshared MapMutator<in Key,in Item>
given Key satisfies Object

Protocol for mutation of a MutableMap.

MutableListSource Codeshared MutableList<Element>

A List supporting addition, insertion, removal, and replacement of its elements.

MutableMapSource Codeshared MutableMap<Key,Item>
given Key satisfies Object

A Map supporting addition of new entries and removal of existing entries.

MutableSetSource Codeshared MutableSet<Element>
given Element satisfies Object

A Set supporting addition of new elements and removal of existing elements.

QueueSource Codeshared Queue<Element>

Abstract supertype of datastructures that can be used as FIFO queues.

A Queue has a well-defined Queue.front and Queue.back. Elements may be added to the back of the queue by Queue.offer(), and removed from the front of the queue by Queue.accept().

Note that many Queues are also Lists, but there is no defined relationship between the order of elements in the list and the direction of the queue. In particular, the front of the queue may be first element of the list, or it may be the last element of the list.

SetMutatorSource Codeshared SetMutator<in Element>
given Element satisfies Object

Protocol for mutation of a MutableSet.

SortedMapSource Codeshared SortedMap<Key,out Item>
given Key satisfies Object

A Map that maintains its entries in sorted order.

SortedSetSource Codeshared SortedSet<Element>
given Element satisfies Object

A Set that maintains its entries in sorted order.

StackSource Codeshared Stack<Element>

Abstract supertype of datastructures that can be used as LIFO stacks.

A Stack has a well-defined Stack.top. Elements may be added to the top of the stack by Stack.push(), and removed from the top of the stack by Stack.pop().

Note that many Stacks are also Lists, but there is no defined relationship between the order of elements in the list and the direction of the stack. In particular, the top of the stack may be first element of the list, or it may be the last element of the list.

Classes
ArrayListSource Codeshared ArrayList<Element>

A MutableList implemented using a backing Array. Also:

  • a Stack, where the top of the stack is the last element of the list, and
  • a Queue, where the front of the queue is the first element of the list and the back of the queue is the last element of the list.

The size of the backing Array is called the capacity of the ArrayList. The capacity of a new instance is specified by the given ArrayList.initialCapacity. The capacity is increased when ArrayList.size exceeds the capacity. The new capacity is the product of the current capacity and the given ArrayList.growthFactor.

HashMapSource Codeshared HashMap<Key,Item>
given Key satisfies Object

A MutableMap implemented as a hash map stored in an Array of singly linked lists of Entrys. Each entry is assigned an index of the array according to the hash code of its key. The hash code of a key is defined by Object.hash.

The HashMap.stability of a HashMap controls its iteration order:

  • A linked map has a stable and meaningful order of iteration. The entries of the map form a linked list, where new entries are added to the end of the linked list. Iteration of the map follows this linked list, from least recently added elements to most recently added elements.
  • An unlinked map has an unstable iteration order that may change when the map is modified. The order itself is not meaningful to a client.

The management of the backing array is controlled by the given HashMap.hashtable.

HashSetSource Codeshared HashSet<Element>
given Element satisfies Object

A MutableSet implemented as a hash set stored in an Array of singly linked lists. Each element is assigned an index of the array according to its hash code. The hash code of an element is defined by Object.hash.

The HashSet.stability of a HashSet controls its iteration order:

  • A linked set has a stable and meaningful order of iteration. The elements of the set form a linked list, where new elements are added to the end of the linked list. Iteration of the set follows this linked list, from least recently added elements to most recently added elements.
  • An unlinked set has an unstable iteration order that may change when the set is modified. The order itself is not meaningful to a client.

The management of the backing array is controlled by the given HashSet.hashtable.

HashtableSource Codeshared Hashtable

Performance-related settings for a hashtable based collection like HashMap or HashSet.

The size of the backing Array is called the capacity of the hashtable.

IdentityMapSource Codeshared IdentityMap<Key,Item>
given Key satisfies Identifiable

An identity map implemented as a hash map stored in an Array of singly linked lists of Entrys. The hash code of a key is defined by identityHash(). Note that an IdentitySet is not a Map, since it does not obey the semantics of a Map. In particular, it may contain multiple keys which are equal, as determined by the == operator.

IdentitySetSource Codeshared IdentitySet<Element>
given Element satisfies Identifiable

An identity set implemented as a hash set stored in an Array of singly linked lists. The hash code of an element is defined by identityHash(). Note that an IdentitySet is not a Set, since it does not obey the semantics of a Set. In particular, it may contain multiple elements which are equal, as determined by the == operator.

LinkedListSource Codeshared LinkedList<Element>

A MutableList implemented as a singly linked list. Also:

  • a Stack, where the top of the stack is the first element of the list, and
  • a Queue, where the front of the queue is the first element of the list and the back of the queue is the last element of the list.
PriorityQueueSource Codeshared PriorityQueue<Element>
given Element satisfies Object

A Queue implemented using a backing Array where the front of the queue is the smallest element according to the order relation defined by PriorityQueue.compare() function. Note that this implementation doesn't guarantee the back/last element to be the largest element of the queue.

The size of the backing Array is called the capacity of the PriorityQueue. The capacity of a new instance is specified by the given PriorityQueue.initialCapacity. The capacity is increased when PriorityQueue.size exceeds the capacity. The new capacity is the product of the needed capacity and the given PriorityQueue.growthFactor.

SingletonMapSource Codeshared SingletonMap<Key,Item>
given Key satisfies Object

A Map with exactly one SingletonMap.entry.

SingletonSetSource Codeshared SingletonSet<Element>
given Element satisfies Object

A Set with exactly one SingletonSet.element.

StabilitySource Codeshared abstract Stability
TreeMapSource Codeshared TreeMap<Key,Item>
given Key satisfies Object

A MutableMap implemented using a red/black tree. Entries in the map are maintained in a sorted order, from smallest to largest key, as determined by the given comparator function.

TreeSetSource Codeshared TreeSet<Element>
given Element satisfies Object

A MutableSet implemented using a red/black tree. Elements of the set are maintained in a sorted order, from smallest to largest, as determined by the given comparator function.

linkedSource Codeshared linked
unlinkedSource Codeshared unlinked