Import std.collections.sorted
std.collections.sorted
A map and a set that keep their keys in order, in a B-tree.
SortedMap<K, V> and SortedSet<T>: keys in order, in a B-tree. Each node holds from Order - 1
to 2 * Order - 1 keys in order, but the root, which can hold fewer, and a node that isn't a leaf
has a child before, between, and after its keys, which hold the keys between them. Finding,
adding, and removing a key looks at about log(Count) nodes.
std/collections/sorted.fb
Types
SortedMap
class
@DebugEntries Public Class SortedMap<K: Comparable, V> Implements Iterable<(K, V)>, Cloneable, Defaultable
A Map that keeps its keys in order, smallest first, for ranges and the nearest key to another.
Examples
Local grades = SortedMap<Int, String>()
grades.Add(90, "A")
grades.Add(70, "C")
grades.Add(80, "B")
Expect(grades.Keys() == [70, 80, 90])
Expect(grades.Floor(85) == (80, "B"))
Expect(grades.Ceiling(85) == (90, "A"))
Expect(grades.Range(70, 90) == [(70, "C"), (80, "B")])std/collections/sorted.fb, line 58
-
A new, empty SortedMap.
-
How many entries it holds.
-
Adds an entry, or gives an existing
keyits new value, which leaves the tree as it is. A key that isn't equal to itself, like NaN, panics. -
The
key's value, or Null when it isn't there. -
The
key's value, orfallbackwhen it isn't there. -
The key's value. A key that isn't there panics.
-
Gives the key a value, adding it when it isn't there.
-
Whether
keyhas an entry. -
Removes the
key's entry, and tells whether there was one. A key that isn't there leaves the tree as it is. -
Takes every entry out.
-
The smallest key and its value, or Null when there's none.
-
The largest key and its value, or Null when there's none.
-
The largest
keythat isn't abovekey, and its value, or Null when there's none, as for akeythat isn't equal to itself. -
The smallest
keythat isn't belowkey, and its value, or Null when there's none, as for akeythat isn't equal to itself. -
The entries from
lowup tohigh, withouthighitself, in order, in a new array. An end that isn't equal to itself finds none. -
The keys, in order.
-
The values, in their keys' order.
-
A new, empty SortedMap.
-
A new SortedMap with the same entries.
-
Each key and its value, in order, for 'For key, value In map'. Giving a key a new value while going over them is fine, but adding or removing one panics.
SortedMapIterator
struct
Public Struct SortedMapIterator<K: Comparable, V> Implements Iterator<(K, V)>
The entries of a SortedMap, in key order, which a For loop goes over.
std/collections/sorted.fb, line 474
-
The next key and its value, in order, or Null after the largest. Panics when the SortedMap changed since the loop began.
SortedSet
class
@DebugElements Public Class SortedSet<T: Comparable> Implements Iterable<T>, Cloneable, Defaultable, Equatable
Values without repeats, in order, which a SortedMap holds as its keys.
Examples
Local words = SortedSet<String>()
For word In ["pear", "apple", "fig", "apple"]
words.Add(word)
End For
Expect(words.ToArray() == ["apple", "fig", "pear"])
Expect(words.First() == "apple" && words.Ceiling("b") == "fig")std/collections/sorted.fb, line 569
-
A new, empty SortedSet.
-
How many values it holds.
-
Adds the
value, and tells whether it's new. A value that isn't equal to itself, like NaN, panics. -
Removes the
value, and tells whether it was there. -
Whether it holds
value. -
Takes every value out.
-
The smallest value, or Null when there's none.
-
The largest value, or Null when there's none.
-
The largest
valuethat isn't abovevalue, or Null when there's none. -
The smallest
valuethat isn't belowvalue, or Null when there's none. -
The values from
lowup tohigh, withouthighitself, in order, in a new array. -
The values, in order, in a new array.
-
A new, empty SortedSet.
-
A new SortedSet with the same values.
-
Two SortedSets are equal when they have the same values.
-
The values, in order. Adding or removing one while going over them panics.
SortedSetIterator
struct
Public Struct SortedSetIterator<T: Comparable> Implements Iterator<T>
The values of a SortedSet, smallest first, which a For loop goes over.
std/collections/sorted.fb, line 649
-
The next value, in order, or Null after the largest. Panics when the SortedSet changed since the loop began.
Extends
SortedMap
extend
Extend SortedMap<K, V> Implements Equatable
Compares SortedMaps with == and !=, where their values can be compared.
std/collections/sorted.fb, line 525
-
Whether the two have the same keys, each with an equal value.
SortedMap
extend
Extend SortedMap<K, V> Implements Printable
Shows a SortedMap in a string, as its ToString writes it.
std/collections/sorted.fb, line 542
-
Its entries, in order, as "{a: 1, b: 2}".
SortedSet
extend
Extend SortedSet<T> Implements Printable
Shows a SortedSet in a string, as its ToString writes it.
std/collections/sorted.fb, line 664
-
Its values, in order, as "{1, 2, 3}".
Report an issue with this page or with FutureBlitz on GitHub.