Creates a new immutable SortedSet containing the values of the provided
collection-like. The values will be sorted by the provided comparator.
The comparator is a function that takes two arguments (a, b) and
returns 0 if a and b are equal, returns positive number when a > b
and returns negative number if a < b.
If comparator is undefined, the defaultComparator will be applied.
This comparator is different than the default comparator used by Collection.sort
because more stringent comparison rules have to be applied to support all the types
and marginal values like NaN or Infinity.
The defaultComparator first determines equality by calling Immutable.is,
then compares the types of both values. If both values are of the same type,
then it compares the values by using the javascript comparison operators > and <,
but before that the objects, functions, and symbols are converted to string.
The internal data structures will be created according to the given options. If options
are undefined then defaultOptions will be applied.
The default options are:
{type: 'btree', btreeOrder: 33}
Currently the only type implemented is btree. It is a classic B-Tree
structure with keys and values not only in leaves but also in internal nodes.
The option btreeOrder is defined as the maximum number of children that any internal nodes can have
and also implies maximum number of entries (key/value pairs) in any node which is (btreeOrder - 1).
The btreeOrder option can be changed in a constructor and can be any integer greater or equal 3.
There are many ways to quickly and conveniently create a SortedSet by calling a constructor.
Below are some examples.
Creates a new immutable
SortedSet
containing the values of the provided collection-like. The values will be sorted by the provided comparator.The comparator is a function that takes two arguments (a, b) and returns 0 if a and b are equal, returns positive number when a > b and returns negative number if a < b.
If comparator is undefined, the
defaultComparator
will be applied. This comparator is different than the default comparator used byCollection.sort
because more stringent comparison rules have to be applied to support all the types and marginal values like NaN or Infinity.The
defaultComparator
first determines equality by callingImmutable.is
, then compares the types of both values. If both values are of the same type, then it compares the values by using the javascript comparison operators > and <, but before that the objects, functions, and symbols are converted to string.The internal data structures will be created according to the given options. If options are undefined then
defaultOptions
will be applied.The default options are:
Currently the only type implemented is
btree
. It is a classic B-Tree structure with keys and values not only in leaves but also in internal nodes. The optionbtreeOrder
is defined as the maximum number of children that any internal nodes can have and also implies maximum number of entries (key/value pairs) in any node which is (btreeOrder
- 1). ThebtreeOrder
option can be changed in a constructor and can be any integer greater or equal 3.There are many ways to quickly and conveniently create a
SortedSet
by calling a constructor. Below are some examples.Create a
SortedSet
from any array:From a sequence of values:
From a string:
From other collections (List, Range, Set, Map):
Use a custom comparator (reverse order):
Change the
btreeOrder
option:You can also conveniently create a
SortedSet
within a chain of sequence operations: