diff --git a/dev/accumulators/index.html b/dev/accumulators/index.html index e4afa1cf1..ca162707b 100644 --- a/dev/accumulators/index.html +++ b/dev/accumulators/index.html @@ -44,4 +44,4 @@ intersect(a1, a2) # multiset intersection (sometimes called infimum or greatest common divisor) # returns a new multiset with the counts being the lowest of those in `a1` or `a2`. # Note that this means things not occurring in both with be removed (count zero). - # `min(a1[v], a2[v])` over all `v` in the universe + # `min(a1[v], a2[v])` over all `v` in the universe diff --git a/dev/avl_tree/index.html b/dev/avl_tree/index.html index 6e71e5442..93bf281da 100644 --- a/dev/avl_tree/index.html +++ b/dev/avl_tree/index.html @@ -1,6 +1,6 @@ AVL Tree · DataStructures.jl

AVL Tree

The AVL Tree is a self-balancing binary search tree in which balancing operations take place based on the difference of height between the left and right subtrees. Such operations may occur during the insertion and deletion of keys performing recursive rotate operations to ensue that the difference between the heights of the left and right substrees is restricted to $[-1, 1]$.

Example of AVL Tree with balance factors shown in green.

AVL Trees are often compared with Red–Black Trees because both take $O(\log n)$ time for the basic operations. However, for lookup-intensive applications, AVL Trees are faster than Red–Black Trees because they are more strictly balanced. Similar to Red–Black Trees, AVL Trees are height-balanced.

Complexity

Computational complexity for common operations using an AVL Tree

OperationAverage CaseWorst Case
Space$\Theta(n)$$O(n)$
Search$\Theta(\log n)$$O(\log n)$
Insertion$\Theta(\log n)$$O(\log n)$
Deletion$\Theta(\log n)$$O(\log n)$

Constructors

DataStructures.AVLTreeType
AVLTree{T}

Construct new AVLTree with keys of type T.

Example

julia> tree = AVLTree{Int64}()
-AVLTree{Int64}(nothing, 0)
source

Usage

The AVLTree type implements the following methods:


Base.delete!Method
delete!(tree::AVLTree{K}, k::K) where K

Delete key k from tree AVL tree.

source
Base.getindexMethod
getindex(tree::AVLTree{K}, ind::Integer) where K

Considering the elements of tree sorted, returns the ind-th element in tree. Search operation is performed in $O(\log n)$ time complexity.

Examples

julia> tree = AVLTree{Int}()
+AVLTree{Int64}(nothing, 0)
source

Usage

The AVLTree type implements the following methods:


Base.delete!Method
delete!(tree::AVLTree{K}, k::K) where K

Delete key k from tree AVL tree.

source
Base.getindexMethod
getindex(tree::AVLTree{K}, ind::Integer) where K

Considering the elements of tree sorted, returns the ind-th element in tree. Search operation is performed in $O(\log n)$ time complexity.

Examples

julia> tree = AVLTree{Int}()
 AVLTree{Int64}(nothing, 0)
 
 julia> for k in 1:2:20
@@ -11,11 +11,11 @@
 7
 
 julia> tree[8]
-15
source
Base.lengthMethod
length(tree::AVLTree)

Return number of elements in AVL tree tree.

source
Base.push!Method
push!(tree::AVLTree{K}, key) where K

Insert key in AVL tree tree.

source
DataStructures.left_rotateMethod
left_rotate(node_x::AVLTreeNode)

Performs a left-rotation on node_x, updates height of the nodes, and returns the rotated node.

source
DataStructures.right_rotateMethod
right_rotate(node_x::AVLTreeNode)

Performs a right-rotation on node_x, updates height of the nodes, and returns the rotated node.

source
DataStructures.sorted_rankMethod
sorted_rank(tree::AVLTree{K}, key::K) where K

Returns the rank of key present in the tree, if it present. A KeyError is thrown if key is not present.

Examples

julia> tree = AVLTree{Int}();
+15
source
Base.lengthMethod
length(tree::AVLTree)

Return number of elements in AVL tree tree.

source
Base.push!Method
push!(tree::AVLTree{K}, key) where K

Insert key in AVL tree tree.

source
DataStructures.left_rotateMethod
left_rotate(node_x::AVLTreeNode)

Performs a left-rotation on node_x, updates height of the nodes, and returns the rotated node.

source
DataStructures.right_rotateMethod
right_rotate(node_x::AVLTreeNode)

Performs a right-rotation on node_x, updates height of the nodes, and returns the rotated node.

source
DataStructures.sorted_rankMethod
sorted_rank(tree::AVLTree{K}, key::K) where K

Returns the rank of key present in the tree, if it present. A KeyError is thrown if key is not present.

Examples

julia> tree = AVLTree{Int}();
 
 julia> for k in 1:2:20
            push!(tree, k)
        end
 
 julia> sorted_rank(tree, 17)
-9
source
+9source diff --git a/dev/circ_buffer/index.html b/dev/circ_buffer/index.html index 4579b14c1..e582c4c77 100644 --- a/dev/circ_buffer/index.html +++ b/dev/circ_buffer/index.html @@ -15,4 +15,4 @@ eltype(cb) # return type of items cb[1] # get the element at the front cb[end] # get the element at the back -fill!(cb, data) # grows the buffer up-to capacity, and fills it entirely, preserving existing elements. +fill!(cb, data) # grows the buffer up-to capacity, and fills it entirely, preserving existing elements. diff --git a/dev/circ_deque/index.html b/dev/circ_deque/index.html index c0241244b..4b1a4c0c2 100644 --- a/dev/circ_deque/index.html +++ b/dev/circ_deque/index.html @@ -10,4 +10,4 @@ popfirst!(a) # remove an element from the front first(a) # get the element at the front last(a) # get the element at the back -eltype(a) # return type of items

Note: Julia's Vector type also provides this interface, and thus can be used as a deque. However, the CircularDeque type in this package is implemented as a circular buffer, and thus avoids copying elements when modifications are made to the front of the vector.

Benchmarks show that the performance of CircularDeque is several times faster than Deque.

+eltype(a) # return type of items

Note: Julia's Vector type also provides this interface, and thus can be used as a deque. However, the CircularDeque type in this package is implemented as a circular buffer, and thus avoids copying elements when modifications are made to the front of the vector.

Benchmarks show that the performance of CircularDeque is several times faster than Deque.

diff --git a/dev/default_dict/index.html b/dev/default_dict/index.html index e7643e16b..8901d5c21 100644 --- a/dev/default_dict/index.html +++ b/dev/default_dict/index.html @@ -22,4 +22,4 @@ sleep(len) return len endDefaultDict{AbstractString, Int64, Main.var"#9#10"}()
julia> dd["hi"] # slow2
julia> dd["ho"] # slow2
julia> dd["hi"] # fast2

Note that in the second-last example, we need to use a function to create each new DefaultDict. If we forget, we will end up using the sameDefaultDict for all default values:

julia> dd = DefaultDict{AbstractString, DefaultDict}(DefaultDict{AbstractString,Int}(0));
julia> dd["a"]DefaultDict{AbstractString, Int64, Int64}()
julia> dd["b"]["a"] = 11
julia> dd["a"]DefaultDict{AbstractString, Int64, Int64} with 1 entry: - "a" => 1

To create a DefaultDict which recursively calls itself you can write:

julia> rdict(args...) = DefaultDict(rdict, Dict{Any,Any}(args...))rdict (generic function with 1 method)
julia> dd = rdict()ERROR: UndefVarError: `DefaultDict` not defined
julia> dd["a"]["b"]["c"]ERROR: UndefVarError: `dd` not defined

It's also possible to create a recursive DefaultDict where the key is restricted:

julia> rdict(args...) = DefaultDict{String,Any,typeof(rdict)}(rdict, Dict{String,Any}(args...))rdict (generic function with 1 method)
julia> dd = rdict()ERROR: UndefVarError: `DefaultDict` not defined
julia> dd["a"]["b"]["c"]ERROR: UndefVarError: `dd` not defined
+ "a" => 1

To create a DefaultDict which recursively calls itself you can write:

julia> rdict(args...) = DefaultDict(rdict, Dict{Any,Any}(args...))rdict (generic function with 1 method)
julia> dd = rdict()ERROR: UndefVarError: `DefaultDict` not defined
julia> dd["a"]["b"]["c"]ERROR: UndefVarError: `dd` not defined

It's also possible to create a recursive DefaultDict where the key is restricted:

julia> rdict(args...) = DefaultDict{String,Any,typeof(rdict)}(rdict, Dict{String,Any}(args...))rdict (generic function with 1 method)
julia> dd = rdict()ERROR: UndefVarError: `DefaultDict` not defined
julia> dd["a"]["b"]["c"]ERROR: UndefVarError: `dd` not defined
diff --git a/dev/deque/index.html b/dev/deque/index.html index 16f99f55e..d5a0d3b92 100644 --- a/dev/deque/index.html +++ b/dev/deque/index.html @@ -1,3 +1,3 @@ Deque · DataStructures.jl

Deque

A Deque (short for Double-ended Queue) is an abstract data type that generalizes a Queue for which elements can be added to or removed from both the front (head) and the back (tail) in $O(1)$ time complexity.

The type Deque implements the Double-ended Queue as a list of fixed-size blocks using an unrolled linked list.

Note

Julia's Vector type also provides this interface, and thus can be used as a deque. However, the Deque type in DataStructures.jl is implemented as a list of contiguous blocks (default size = 1 kilo-byte). As a Deque grows, new blocks are created and linked to existing blocks. This approach prevents copying operations that take place when growing a Vector.

Benchmark shows that the performance of Deque is comparable to Vector on push!, but is noticeably faster on pushfirst! (by about 30% to 40%).

Constructors

DataStructures.DequeType
Deque{T}
-Deque{T}(blksize::Int) where T

Constructs Deque object for elements of type T.

Parameters

T::Type Deque element data type.

blksize::Int Deque block size (in bytes). Default = 1024.

source

Usage

The Deque implements the following methods:


Base.:==Method
==(x::Deque, y::Deque)

Verify if the deques x and y are equal in terms of their contents.

source
Base.firstMethod
first(d::Deque)

Returns the first element of the deque d.

source
Base.lastMethod
last(d::Deque)

Returns the last element of the deque d.

source
Base.lengthMethod
length(d::Deque)

Returns the number of elements in deque d.

source
Base.pop!Method
pop!(d::Deque{T}) where T

Remove the element at the back of deque d.

source
Base.popfirst!Method
popfirst!(d::Deque{T}) where T

Remove the element at the front of deque d.

source
Base.push!Method
push!(d::Deque{T}, x) where T

Add an element to the back of deque d.

source
Base.pushfirst!Method
pushfirst!(d::Deque{T}, x) where T

Add an element to the front of deque d.

source
+Deque{T}(blksize::Int) where T

Constructs Deque object for elements of type T.

Parameters

T::Type Deque element data type.

blksize::Int Deque block size (in bytes). Default = 1024.

source

Usage

The Deque implements the following methods:


Base.:==Method
==(x::Deque, y::Deque)

Verify if the deques x and y are equal in terms of their contents.

source
Base.empty!Method
empty!(d::Deque{T}) where T

Reset the deque d.

source
Base.firstMethod
first(d::Deque)

Returns the first element of the deque d.

source
Base.isemptyMethod
isempty(d::Deque)

Verifies if deque d is empty.

source
Base.lastMethod
last(d::Deque)

Returns the last element of the deque d.

source
Base.lengthMethod
length(d::Deque)

Returns the number of elements in deque d.

source
Base.pop!Method
pop!(d::Deque{T}) where T

Remove the element at the back of deque d.

source
Base.popfirst!Method
popfirst!(d::Deque{T}) where T

Remove the element at the front of deque d.

source
Base.push!Method
push!(d::Deque{T}, x) where T

Add an element to the back of deque d.

source
Base.pushfirst!Method
pushfirst!(d::Deque{T}, x) where T

Add an element to the front of deque d.

source
diff --git a/dev/dibit_vector/index.html b/dev/dibit_vector/index.html index a416fb61d..11024692c 100644 --- a/dev/dibit_vector/index.html +++ b/dev/dibit_vector/index.html @@ -29,4 +29,4 @@ 0x02 julia> length(v) -3 +3 diff --git a/dev/disjoint_sets/index.html b/dev/disjoint_sets/index.html index 4fed979ec..0294afec2 100644 --- a/dev/disjoint_sets/index.html +++ b/dev/disjoint_sets/index.html @@ -9,4 +9,4 @@ num_groups(a) # returns the number of sets

One may also use other element types:

a = DisjointSets{AbstractString}(["a", "b", "c", "d"])
 union!(a, "a", "b")
 in_same_set(a, "c", "d")
-push!(a, "f")

Note that the internal implementation of IntDisjointSets is based on vectors, and is very efficient. DisjointSets{T} is a wrapper of IntDisjointSets, which uses a dictionary to map input elements to an internal index. Note for DisjointSets, union!, root_union! and find_root! return the index of the root.

+push!(a, "f")

Note that the internal implementation of IntDisjointSets is based on vectors, and is very efficient. DisjointSets{T} is a wrapper of IntDisjointSets, which uses a dictionary to map input elements to an internal index. Note for DisjointSets, union!, root_union! and find_root! return the index of the root.

diff --git a/dev/fenwick/index.html b/dev/fenwick/index.html index ee26eaa74..6326f298f 100644 --- a/dev/fenwick/index.html +++ b/dev/fenwick/index.html @@ -9,4 +9,4 @@ julia> prefixsum(f, 1) 0 julia> prefixsum(f, 3) - 5 + 5 diff --git a/dev/heaps/index.html b/dev/heaps/index.html index 157452cc8..6dc3cd05a 100644 --- a/dev/heaps/index.html +++ b/dev/heaps/index.html @@ -63,4 +63,4 @@ h = MutableBinaryHeap{Float64, DataStructures.FasterReverse}() # faster mutable max heap DataStructures.nextreme(DataStructures.FasterReverse(), n, a) # faster nlargest(n, a) -DataStructures.nextreme(DataStructures.FasterForward(), n, a) # faster nsmallest(n, a) +DataStructures.nextreme(DataStructures.FasterForward(), n, a) # faster nsmallest(n, a) diff --git a/dev/index.html b/dev/index.html index d5ed98809..fbab1ff9e 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -DataStructures.jl · DataStructures.jl

DataStructures.jl

This package implements a variety of data structures, including

  • Deque (implemented with an unrolled linked list)
  • CircularBuffer
  • CircularDeque (based on a circular buffer)
  • Stack
  • Queue
  • Priority Queue
  • Fenwick Tree
  • Accumulators and Counters (i.e. Multisets / Bags)
  • Disjoint Sets
  • Binary Heap
  • Mutable Binary Heap
  • Ordered Dicts and Sets
  • RobinDict and OrderedRobinDict (implemented with Robin Hood Hashing)
  • SwissDict (inspired from SwissTables)
  • Dictionaries with Defaults
  • Trie
  • Linked List and Mutable Linked List
  • Sorted Dict, Sorted Multi-Dict and Sorted Set
  • DataStructures.IntSet
  • SparseIntSet
  • DiBitVector
  • Red Black Tree
  • AVL Tree
  • Splay Tree

Contents

+DataStructures.jl · DataStructures.jl

DataStructures.jl

This package implements a variety of data structures, including

  • Deque (implemented with an unrolled linked list)
  • CircularBuffer
  • CircularDeque (based on a circular buffer)
  • Stack
  • Queue
  • Priority Queue
  • Fenwick Tree
  • Accumulators and Counters (i.e. Multisets / Bags)
  • Disjoint Sets
  • Binary Heap
  • Mutable Binary Heap
  • Ordered Dicts and Sets
  • RobinDict and OrderedRobinDict (implemented with Robin Hood Hashing)
  • SwissDict (inspired from SwissTables)
  • Dictionaries with Defaults
  • Trie
  • Linked List and Mutable Linked List
  • Sorted Dict, Sorted Multi-Dict and Sorted Set
  • DataStructures.IntSet
  • SparseIntSet
  • DiBitVector
  • Red Black Tree
  • AVL Tree
  • Splay Tree

Contents

diff --git a/dev/intset/index.html b/dev/intset/index.html index 85e37f913..e903c76f5 100644 --- a/dev/intset/index.html +++ b/dev/intset/index.html @@ -1,2 +1,2 @@ -DataStructures.IntSet · DataStructures.jl

DataStructures.IntSet

DataStructures.IntSet is a drop-in replacement for the Base BitSet type. It efficiently stores dense collections of small non-negative Ints as a sorted set. The constructor IntSet([itr]) constructs a sorted set of the integers generated by the given iterable object, or an empty set if no argument is given. If the set will be sparse (for example holding a few very large integers), use Set or SortedSet instead.

A complement IntSet may be constructed with complement or complement!. The complement of an empty IntSet contains typemax(Int) elements from 0 to typemax(Int)-1.

+DataStructures.IntSet · DataStructures.jl

DataStructures.IntSet

DataStructures.IntSet is a drop-in replacement for the Base BitSet type. It efficiently stores dense collections of small non-negative Ints as a sorted set. The constructor IntSet([itr]) constructs a sorted set of the integers generated by the given iterable object, or an empty set if no argument is given. If the set will be sparse (for example holding a few very large integers), use Set or SortedSet instead.

A complement IntSet may be constructed with complement or complement!. The complement of an empty IntSet contains typemax(Int) elements from 0 to typemax(Int)-1.

diff --git a/dev/linked_list/index.html b/dev/linked_list/index.html index 161699973..2b1c34efe 100644 --- a/dev/linked_list/index.html +++ b/dev/linked_list/index.html @@ -15,4 +15,4 @@ list(2, 4, 6) julia> for i in l5; print(i); end -246 +246 diff --git a/dev/mutable_linked_list/index.html b/dev/mutable_linked_list/index.html index 0e75f7047..acbae1f58 100644 --- a/dev/mutable_linked_list/index.html +++ b/dev/mutable_linked_list/index.html @@ -22,4 +22,4 @@ push!(l, data) # add element to end of list pushfirst!(l, data) # add element to beginning of list pop!(l) # remove element from end of list -popfirst!(l) # remove element from beginning of list

MutableLinkedList implements the Iterator interface, iterating over the list from first to last.

+popfirst!(l) # remove element from beginning of list

MutableLinkedList implements the Iterator interface, iterating over the list from first to last.

diff --git a/dev/ordered_containers/index.html b/dev/ordered_containers/index.html index c3e9bdafb..89bd1cb7c 100644 --- a/dev/ordered_containers/index.html +++ b/dev/ordered_containers/index.html @@ -11,4 +11,4 @@ # γ = 0.5772156649015..., # catalan = 0.9159655941772..., # φ = 1.6180339887498...]

All standard Dict functions are available for OrderedDicts, and all Set operations are available for OrderedSets.

Note that to create an OrderedSet of a particular type, you must specify the type in curly-braces:

# create an OrderedSet of Strings
-strs = OrderedSet{AbstractString}()
+strs = OrderedSet{AbstractString}() diff --git a/dev/priority-queue/index.html b/dev/priority-queue/index.html index 498fa912b..8986abf31 100644 --- a/dev/priority-queue/index.html +++ b/dev/priority-queue/index.html @@ -3,7 +3,7 @@ PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 3 entries: "c" => 1 "a" => 2 - "b" => 3source

Usage

The PriorityQueue type implements the following methods:

Note

PriorityQueue also behaves similarly to a Dict in that keys can be inserted and priorities accessed or changed using indexing notation.

Examples:

julia> pq = PriorityQueue();
+  "b" => 3
source

Usage

The PriorityQueue type implements the following methods:

Note

PriorityQueue also behaves similarly to a Dict in that keys can be inserted and priorities accessed or changed using indexing notation.

Examples:

julia> pq = PriorityQueue();
 
 julia> # Insert keys with associated priorities
        pq["a"] = 10; pq["b"] = 5; pq["c"] = 15; pq
@@ -50,7 +50,7 @@
 julia> delete!(q, "b")
 PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 2 entries:
   "c" => 1
-  "a" => 2
source
Base.firstMethod
first(pq::PriorityQueue)

Return the lowest priority pair (k, v) from pq without removing it from the priority queue.

source
Base.haskeyMethod
haskey(pq::PriorityQueue, key)

Verify if priority queue pq has key in its keys.

Example

julia> pq = PriorityQueue("a" => 1, "b" => 2, "c" => 3)
+  "a" => 2
source
Base.firstMethod
first(pq::PriorityQueue)

Return the lowest priority pair (k, v) from pq without removing it from the priority queue.

source
Base.haskeyMethod
haskey(pq::PriorityQueue, key)

Verify if priority queue pq has key in its keys.

Example

julia> pq = PriorityQueue("a" => 1, "b" => 2, "c" => 3)
 PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 3 entries:
   "a" => 1
   "b" => 2
@@ -60,7 +60,7 @@
 true
 
 julia> haskey(pq, "e")
-false
source
Base.isemptyMethod
isempty(pq::PriorityQueue)

Verify if priority queue pq is empty.

source
Base.lengthMethod
length(pq::PriorityQueue)

Return the number of pairs (k, v) in the priority queue pq.

source
Base.popfirst!Method
popfirst!(pq::PriorityQueue)

Remove and return the lowest priority key and value from a priority queue pq as a pair.

Examples

julia> a = PriorityQueue(Base.Order.Forward, "a" => 2, "b" => 3, "c" => 1)
+false
source
Base.isemptyMethod
isempty(pq::PriorityQueue)

Verify if priority queue pq is empty.

source
Base.lengthMethod
length(pq::PriorityQueue)

Return the number of pairs (k, v) in the priority queue pq.

source
Base.popfirst!Method
popfirst!(pq::PriorityQueue)

Remove and return the lowest priority key and value from a priority queue pq as a pair.

Examples

julia> a = PriorityQueue(Base.Order.Forward, "a" => 2, "b" => 3, "c" => 1)
 PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 3 entries:
   "c" => 1
   "a" => 2
@@ -72,7 +72,7 @@
 julia> a
 PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 2 entries:
   "a" => 2
-  "b" => 3
source
Base.push!Method
push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}

Insert the a key k into a priority queue pq with priority v.

Examples

julia> a = PriorityQueue("a" => 1, "b" => 2, "c" => 3, "e" => 5)
+  "b" => 3
source
Base.push!Method
push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}

Insert the a key k into a priority queue pq with priority v.

Examples

julia> a = PriorityQueue("a" => 1, "b" => 2, "c" => 3, "e" => 5)
 PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 4 entries:
   "a" => 1
   "b" => 2
@@ -85,4 +85,4 @@
   "b" => 2
   "c" => 3
   "d" => 4
-  "e" => 5
source
+ "e" => 5source diff --git a/dev/queue/index.html b/dev/queue/index.html index bc801e83e..1839d8486 100644 --- a/dev/queue/index.html +++ b/dev/queue/index.html @@ -4,4 +4,4 @@ Queue{Int64}(Deque [Int64[]]) julia> q_float = Queue{Float64}() # create a queue with float elements -Queue{Float64}(Deque [Float64[]])source

Usage

The Queue type implements the following methods:


Base.:==Method
==(x::Queue, y::Queue)

Verify if queues x and y are equivalent in their contents.

source
Base.eltypeMethod
eltype(::Type{Queue{T}}) where {T}

Return the type of the elements in the queue.

source
Base.empty!Method
empty!(q::Queue)

Removes all elements from queue q.

source
Base.firstMethod
first(q::Queue)

Get the first item from queue q.

source
Base.isemptyMethod
isempty(q::Queue)

Check if queue q is empty.

source
Base.lastMethod
last(q::Queue)

Get the last element in queue q.

source
Base.lengthMethod
length(q::Queue)

Return the number of elements in queue q.

source
Base.popfirst!Method
popfirst!(q::Queue)

Removes an element from the front of the queue q and returns it.

source
Base.push!Method
push!(q::Queue, x)

Inserts the value x to the end of the queue q.

source
+Queue{Float64}(Deque [Float64[]])source

Usage

The Queue type implements the following methods:


Base.:==Method
==(x::Queue, y::Queue)

Verify if queues x and y are equivalent in their contents.

source
Base.eltypeMethod
eltype(::Type{Queue{T}}) where {T}

Return the type of the elements in the queue.

source
Base.empty!Method
empty!(q::Queue)

Removes all elements from queue q.

source
Base.firstMethod
first(q::Queue)

Get the first item from queue q.

source
Base.isemptyMethod
isempty(q::Queue)

Check if queue q is empty.

source
Base.lastMethod
last(q::Queue)

Get the last element in queue q.

source
Base.lengthMethod
length(q::Queue)

Return the number of elements in queue q.

source
Base.popfirst!Method
popfirst!(q::Queue)

Removes an element from the front of the queue q and returns it.

source
Base.push!Method
push!(q::Queue, x)

Inserts the value x to the end of the queue q.

source
diff --git a/dev/red_black_tree/index.html b/dev/red_black_tree/index.html index ded9be153..c98252347 100644 --- a/dev/red_black_tree/index.html +++ b/dev/red_black_tree/index.html @@ -16,4 +16,4 @@ end julia> haskey(tree, 5) -false +false diff --git a/dev/robin_dict/index.html b/dev/robin_dict/index.html index 5149d1623..9399ba3db 100644 --- a/dev/robin_dict/index.html +++ b/dev/robin_dict/index.html @@ -23,4 +23,4 @@ 1 => 'a' julia> pop!(d) -3 => 'c' +3 => 'c' diff --git a/dev/search/index.html b/dev/search/index.html index fb12bded7..90fb7c64a 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · DataStructures.jl

Loading search...

    +Search · DataStructures.jl

    Loading search...

      diff --git a/dev/sorted_containers/index.html b/dev/sorted_containers/index.html index d157f8ab1..dcab0d545 100644 --- a/dev/sorted_containers/index.html +++ b/dev/sorted_containers/index.html @@ -1,40 +1,40 @@ Sorted Containers · DataStructures.jl

      Sorted Containers

      Three sorted containers are provided: SortedDict, SortedMultiDict and SortedSet. SortedDict is similar to the built-in Julia type Dict with the additional feature that the keys are stored in sorted order and can be efficiently iterated in this order. SortedDict is a subtype of AbstractDict. It is generally slower than Dict because looking up a key requires an O(log n) tree search rather than an expected O(1) hash-table lookup time of Dict. SortedDict is a parameterized type with three parameters, the key type K, the value type V, and the ordering type O. SortedSet has only keys; it is an alternative to the built-in Set container and is a subtype of AbstractSet. Internally, SortedSet is implemented as a SortedDict in which the value type is Nothing. Finally, SortedMultiDict is similar to SortedDict except that each key can be associated with multiple values. The key=>value pairs in a SortedMultiDict are stored according to the sorted order for keys, and key=>value pairs with the same key are stored in order of insertion.

      The containers internally use a 2-3 tree, which is a kind of balanced tree and is described in data structure textbooks. Internally, one Vector is used to store key/data pairs (the leaves of the tree) while a second holds the tree structure.

      The containers require two functions to compare keys: a less-than and equals function. With the default ordering argument, the comparison functions are isless(key1,key2) (true when key1 < key2) and isequal(key1,key2) (true when key1 == key2) where key1 and key2 are keys. More details are provided below.

      Tokens for Sorted Containers

      The sorted containers support an object for indexing called a token defined as a two-entry tuple and aliased as SortedDictToken, SortedMultiDictToken, or SortedSetToken. A token is the address of a single data item in the container and can be dereferenced in time O(1).

      The first entry of a token tuple is the container as a whole, and the second refers to the particular item. The second part is called a semitoken. The type of the semitoken is IntSemiToken.

      A restriction for the sorted containers is that IntSemiToken cannot used as the key-type. This is because ambiguity would result between the two subscripting calls sc[k] and sc[st] described below. In the rare scenario that a sorted container whose key-type is IntSemiToken is required, a workaround is to wrap the key inside another immutable structure.

      The notion of token is similar to the concept of iterators used by C++ standard containers. Tokens can be explicitly advanced or regressed through the data in the sorted order; they are implicitly advanced or regressed via iteration defined below.

      A token may take two special values: the before-start value and the past-end value. These values act as lower and upper bounds on the actual data. The before-start token can be advanced, while the past-end token can be regressed. A dereferencing operation on either leads to an error.

      In the current implementation, semitokens are internally stored as integers. Users should regard these integers as opaque since future versions of the package may change the internal indexing scheme. In certain situations it may be more costly to operate on tokens than semitokens because the first entry of a token (i.e., the container) is not a bits-type. If code profiling indicates that statements using tokens are allocating memory, then it may be advisable to rewrite the application code using semitokens rather than tokens.

      Complexity of Sorted Containers

      In the list of functions below, the running time of the various operations is provided. In these running times, n denotes the number of items in the container, and c denotes the time needed to compare two keys.

      Constructors for Sorted Containers

      SortedDict constructors

      DataStructures.SortedDictMethod
      SortedDict{K,V,Ord}(o::Ord=Forward) where {K, V, Ord <: Ordering}
      -SortedDict{K,V,Ord}(o::Ord, kv) where {K, V, Ord <: Ordering}

      Construct a SortedDict with key type K and value type V with o ordering from an iterable kv. The iterable should generate either Pair{K,V} or Tuple{K,V}. If omitted, then the SortedDict is initially empty. Time: O(cn log n) where n is the length of the iterable.

      source
      DataStructures.SortedDictMethod
      SortedDict(o::Ord=Forward) where {Ord <: Ordering}
      -SortedDict{K,V}(o::Ord=Forward) where {K,V,Ord<:Ordering}

      Construct an empty SortedDict with key type K and value type V with o ordering (default to forward ordering). If K and V are not specified as in the first form, then they are assumed to both be Any. Time: O(1)

      Note that a key type of Any or any other abstract type will lead to slow performance, as the values are stored boxed (i.e., as pointers), and insertion will require a run-time lookup of the appropriate comparison function. It is recommended to always specify a concrete key type, or to use one of the constructors in which the key type is inferred.

      source
      DataStructures.SortedDictMethod
      SortedDict(iter, o::Ord=Forward) where {Ord <: Ordering}
      +SortedDict{K,V,Ord}(o::Ord, kv) where {K, V, Ord <: Ordering}

      Construct a SortedDict with key type K and value type V with o ordering from an iterable kv. The iterable should generate either Pair{K,V} or Tuple{K,V}. If omitted, then the SortedDict is initially empty. Time: O(cn log n) where n is the length of the iterable.

      source
      DataStructures.SortedDictMethod
      SortedDict(o::Ord=Forward) where {Ord <: Ordering}
      +SortedDict{K,V}(o::Ord=Forward) where {K,V,Ord<:Ordering}

      Construct an empty SortedDict with key type K and value type V with o ordering (default to forward ordering). If K and V are not specified as in the first form, then they are assumed to both be Any. Time: O(1)

      Note that a key type of Any or any other abstract type will lead to slow performance, as the values are stored boxed (i.e., as pointers), and insertion will require a run-time lookup of the appropriate comparison function. It is recommended to always specify a concrete key type, or to use one of the constructors in which the key type is inferred.

      source
      DataStructures.SortedDictMethod
      SortedDict(iter, o::Ord=Forward) where {Ord <: Ordering}
       SortedDict(o::Ordering, iter)
       SortedDict{K,V}(iter, o::Ordering=Forward) where {K,V}
      -SortedDict{K,V}(o::Ordering, iter) where {K,V}

      Construct a SortedDict from an arbitrary iterable object of key=>value pairs or (key,value) tuples with order object o. The key type and value type are inferred from the given iterable in the first two forms. The first two forms copy the data three times, so it is more efficient to explicitly specify K and V as in the second two forms. Time: O(cn log n)

      source
      DataStructures.SortedDictMethod
      SortedDict(ps::Pair...)
      +SortedDict{K,V}(o::Ordering, iter) where {K,V}

      Construct a SortedDict from an arbitrary iterable object of key=>value pairs or (key,value) tuples with order object o. The key type and value type are inferred from the given iterable in the first two forms. The first two forms copy the data three times, so it is more efficient to explicitly specify K and V as in the second two forms. Time: O(cn log n)

      source
      DataStructures.SortedDictMethod
      SortedDict(ps::Pair...)
       SortedDict(o::Ordering, ps::Pair...)
       SortedDict{K,V}(ps::Pair...)
      -SortedDict{K,V}(o::Ordering, ps::Pair...) where {K,V}

      Construct a SortedDict from the given key-value pairs. The key type and value type are inferred from the given key-value pairs in the first two forms. The ordering is assumed to be Forward ordering in the first and third form. The first two forms (where K and V are not specified but inferred) involves copying the data three times and so is less efficient than the second two forms. Time: O(cn log n)

      source
      DataStructures.SortedDictMethod
      SortedDict{K,V}(::Val{true}, iterable) where {K, V}
      -SortedDict{K,V}(::Val{true}, iterable, ord::Ordering) where {K,V}

      Construct a SortedDict from an iterable whose eltype is Tuple{K,V} or Pair{K,V} and that is already in sorted ordered. The first form assumes Forward ordering. No duplicate keys allowed. Time: O(cn).

      source

      SortedMultiDict constructors

      DataStructures.SortedMultiDictMethod
      SortedMultiDict{K,V,Ord}(o::Ord=Forward) where {K, V, Ord <: Ordering}
      -SortedMultiDict{K,V,Ord}(o::Ord, iterable) where {K, V, Ord <: Ordering}

      Construct a sorted multidict in which type parameters are explicitly listed; ordering object is explicitly specified. Time: O(cn log n)

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict(o::Ord=Forward) where {Ord <: Ordering}
      -SortedMultiDict{K,V}(o::Ordering=Forward) where {K,V}

      Construct an empty SortedMultiDict with key type K and value type V with o ordering (default to Forward ordering). If K and V are not specified as in the first form, then they are assumed to both be Any. Time: O(1).

      Note that a key type of Any or any other abstract type will lead to slow performance, as the values are stored boxed (i.e., as pointers), and insertion will require a run-time lookup of the appropriate comparison function. It is recommended to always specify a concrete key type, or to use one of the constructors in which the key type is inferred.

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict(ps::Pair...)
      +SortedDict{K,V}(o::Ordering, ps::Pair...) where {K,V}

      Construct a SortedDict from the given key-value pairs. The key type and value type are inferred from the given key-value pairs in the first two forms. The ordering is assumed to be Forward ordering in the first and third form. The first two forms (where K and V are not specified but inferred) involves copying the data three times and so is less efficient than the second two forms. Time: O(cn log n)

      source
      DataStructures.SortedDictMethod
      SortedDict{K,V}(::Val{true}, iterable) where {K, V}
      +SortedDict{K,V}(::Val{true}, iterable, ord::Ordering) where {K,V}

      Construct a SortedDict from an iterable whose eltype is Tuple{K,V} or Pair{K,V} and that is already in sorted ordered. The first form assumes Forward ordering. No duplicate keys allowed. Time: O(cn).

      source

      SortedMultiDict constructors

      DataStructures.SortedMultiDictMethod
      SortedMultiDict{K,V,Ord}(o::Ord=Forward) where {K, V, Ord <: Ordering}
      +SortedMultiDict{K,V,Ord}(o::Ord, iterable) where {K, V, Ord <: Ordering}

      Construct a sorted multidict in which type parameters are explicitly listed; ordering object is explicitly specified. Time: O(cn log n)

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict(o::Ord=Forward) where {Ord <: Ordering}
      +SortedMultiDict{K,V}(o::Ordering=Forward) where {K,V}

      Construct an empty SortedMultiDict with key type K and value type V with o ordering (default to Forward ordering). If K and V are not specified as in the first form, then they are assumed to both be Any. Time: O(1).

      Note that a key type of Any or any other abstract type will lead to slow performance, as the values are stored boxed (i.e., as pointers), and insertion will require a run-time lookup of the appropriate comparison function. It is recommended to always specify a concrete key type, or to use one of the constructors in which the key type is inferred.

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict(ps::Pair...)
       SortedMultiDict(o, ps::Pair...)
       SortedMultiDict{K,V}(ps::Pair...)
      -SortedMultiDict{K,V}(o, ps::Pair...)

      Construct a SortedMultiDict from the given key-value pairs. The key type and value type are inferred from the given key-value pairs in the first two form. The ordering is assumed to be Forward ordering in the first and third forms. The first two forms involve copying the data three times to infer the types and so are less efficient than the third and fourth form where {K,V} are specified explicitly. Time: O(cn log n)

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict(iter, o::Ord=Forward) where {Ord <: Ordering}
      +SortedMultiDict{K,V}(o, ps::Pair...)

      Construct a SortedMultiDict from the given key-value pairs. The key type and value type are inferred from the given key-value pairs in the first two form. The ordering is assumed to be Forward ordering in the first and third forms. The first two forms involve copying the data three times to infer the types and so are less efficient than the third and fourth form where {K,V} are specified explicitly. Time: O(cn log n)

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict(iter, o::Ord=Forward) where {Ord <: Ordering}
       SortedMultiDict(o::Ordering, iter)
       SortedMultiDict{K,V}(iter, o::Ordering=Forward) where {K, V}
      -SortedMultiDict{K,V}(o::Ordering, iter) where {K, V}

      Construct a SortedMultiDict from an arbitrary iterable object of key=>value pairs or (key,value) tuples with order object o. The key type and value type are inferred from the given iterable in the first two forms. The first two forms copy the data three times, so it is more efficient to explicitly specify K and V as in the second two forms. Time: O(cn log n)

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict{K,V}(::Val{true}, iterable) where {K,V}
      -SortedMultiDict{K,V}(::Val{true}, iterable, ord::Ord) where {K,V,Ord<:Ordering}

      Construct a SortedMultiDict from an iterable whose eltype is Tuple{K,V} or Pair{K,V} and that is already in sorted ordered. The first form assumes Forward ordering. Duplicate keys allowed. Time: O(cn).

      source

      SortedSet constructors

      DataStructures.SortedSetMethod
      SortedSet{K,Ord}(o::Ord=Forward) where {K, Ord<:Ordering}
      -SortedSet{K,Ord}(o::Ord, iter) where {K, Ord<:Ordering}

      Construct a SortedSet of eltype Kusing from elements produced by iterable iter (e.g., an array) and ordering object o. Running time: O(cn log n) where n is the length of iterable.

      source
      DataStructures.SortedSetMethod
      SortedSet(o::Ord=Forward) where {Ord <: Ordering}
      -SortedSet{K}(o::Ord=Forward) where {K, Ord<:Ordering}

      Construct an empty SortedSet with Forward ordering. The first form assumes element type of Any. Time: O(1).

      Note that an element type of Any or any other abstract type will lead to slow performance.

      source
      DataStructures.SortedSetMethod
      SortedSet(o::Ordering, iter)
      +SortedMultiDict{K,V}(o::Ordering, iter) where {K, V}

      Construct a SortedMultiDict from an arbitrary iterable object of key=>value pairs or (key,value) tuples with order object o. The key type and value type are inferred from the given iterable in the first two forms. The first two forms copy the data three times, so it is more efficient to explicitly specify K and V as in the second two forms. Time: O(cn log n)

      source
      DataStructures.SortedMultiDictMethod
      SortedMultiDict{K,V}(::Val{true}, iterable) where {K,V}
      +SortedMultiDict{K,V}(::Val{true}, iterable, ord::Ord) where {K,V,Ord<:Ordering}

      Construct a SortedMultiDict from an iterable whose eltype is Tuple{K,V} or Pair{K,V} and that is already in sorted ordered. The first form assumes Forward ordering. Duplicate keys allowed. Time: O(cn).

      source

      SortedSet constructors

      DataStructures.SortedSetMethod
      SortedSet{K,Ord}(o::Ord=Forward) where {K, Ord<:Ordering}
      +SortedSet{K,Ord}(o::Ord, iter) where {K, Ord<:Ordering}

      Construct a SortedSet of eltype Kusing from elements produced by iterable iter (e.g., an array) and ordering object o. Running time: O(cn log n) where n is the length of iterable.

      source
      DataStructures.SortedSetMethod
      SortedSet(o::Ord=Forward) where {Ord <: Ordering}
      +SortedSet{K}(o::Ord=Forward) where {K, Ord<:Ordering}

      Construct an empty SortedSet with Forward ordering. The first form assumes element type of Any. Time: O(1).

      Note that an element type of Any or any other abstract type will lead to slow performance.

      source
      DataStructures.SortedSetMethod
      SortedSet(o::Ordering, iter)
       SortedSet(iter, o::Ordering=Forward)
       SortedSet{K}(o::Ordering, iter)
      -SortedSet{K}(iter, o::Ordering=Forward)

      Construct a sorted set from an iterable iter using order o. In the first two forms, the element type is inferred from the iterable, which requires copying the data twice. Therefore, the second two forms (specifying K explicitly) are more efficient. Time: O(cn log n)

      source
      DataStructures.SortedSetMethod
      SortedSet{K}(::Val{true}, iterable) where {K}
      -SortedSet{K}(::Val{true}, iterable, ord::Ord) where {K, Ord <: Ordering}

      Construct a SortedSet from an iterable whose entries have type K and that is already in sorted ordered. No duplicates allowed. The first form assumes Forward ordering. Time: O(cn).

      source
      Base.getindexMethod
      Base.getindex(m::SortedDict, st::IntSemiToken)
      -Base.getindex(m::SortedMultiDict, st::IntSemiToken)

      Retrieve value portion of item from SortedDict or SortedMultiDict m indexed by st, a semitoken. Notation m[st] appearing in an expression is equivalent to deref_value(token::Token) where token=(m,st). It is a BoundsError if the token is invalid. Prepending with @inbounds may elide the correctness check and results in undefined behavior if the token is invalid. Time: O(1)

      source
      Base.setindex!Method
      Base.setindex!(m::SortedDict, newvalue, st::IntSemiToken)
      -Base.setindex!(m::SortedMultiDict, newvalue, st::IntSemiToken)

      Set the value portion of item from SortedDict or SortedMultiDict m indexed by st, a semitoken to newvalue. A BoundsError is thrown if the token is invalid. Prepending with @inbounds may elide the correctness check and results in undefined behavior if the token is invalid. Time: O(1)

      source
      Base.setindex!Method
      Base.setindex!(sd::SortedDict, newvalue, k)

      Assign or reassign the value associated with the key k to newvalue. Note that the key is also overwritten; this is not necessarily a no-op since the equivalence in the sort-order does not imply equality. See also push_return_semitoken!(sd::SortedDict, p::Pair). Time: O(c log n)

      source
      DataStructures.derefMethod
      deref(token::Token)
      -deref((m,st))

      Return the data item indexed by the token. If the container is a SortedSet, then this is a key in the set. If the container is a SortedDict or SortedMultiDict, then this is a key=>value pair. It is a BoundsError if the token is invalid or is the before-start or past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start or past-end token. The second form creates the token in-place as a tuple of a sorted container m and a semitoken st. Time: O(1)

      source
      DataStructures.deref_keyMethod
      deref_key(token::Token)
      -deref_key((m,st))

      Return the key portion of a data item (a key=>value pair) in a SortedDict or SortedMultiDict indexed by the token. It is a BoundsError if the token is invalid or is the before-start or past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start or past-end token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(1)

      source
      DataStructures.deref_valueMethod
      deref_value(token::Token)
      -deref_value((m,st))

      Returns the value portion of a data item (a key=>value pair) in a SortedDict or SortedMultiDict indexed by the token. It is a BoundsError if the token is invalid or is the before-start or past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start or past-end token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(1)

      source
      Base.firstindexMethod
      Base.firstindex(m::SortedContainer)

      Return the semitoken of the first entry of the container m, or the past-end semitoken if the container is empty. This function was called startof (now deprecated) in previous versions of the package. Time: O(log n)

      source
      Base.lastindexMethod
      Base.lastindex(m::SortedContainer)

      Return the semitoken of the last entry of the sorted container m, or the before-start semitoken if the container is empty. This function was called endof (now deprecated) in previous versions of the package. Time: O(log n)

      source
      DataStructures.token_firstindexMethod
      token_firstindex(m::SortedContainer)

      Return the token of the first entry of the sorted container m, or the past-end token if the container is empty. Time: O(log n)

      source
      DataStructures.token_lastindexMethod
      token_lastindex(m::SortedContainer)

      Return the token of the last entry of the sorted container m, or the before-start semitoken if the container is empty. Time: O(log n)

      source
      Base.firstMethod
      Base.first(sc::SortedContainer)

      Return the first item (a k=>v pair for SortedDict and SortedMultiDict or an element for SortedSet) in sc according to the sorted order in the container. It is a BoundsError to call this function on an empty container. Equivalent to deref(token_startindex(sc)). Time: O(log n)

      source
      Base.lastMethod
      Base.last(sc::SortedContainer)

      Return the last item (a k=>v pair for SortedDict and SortedMultiDict or a key for SortedSet) in sc according to the sorted order in the container. It is a BoundsError to call this function on an empty container. Equivalent to deref(token_lastindex(sc)). Time: O(log n)

      source
      DataStructures.pastendtokenMethod
      pastendtoken(m::SortedContainer)

      Return the token of the entry that is one past the end of the sorted container m. Time: O(1)

      source
      DataStructures.advanceMethod
      advance(token::Token)
      -advance((m,st))

      Return the semitoken of the item in a sorted container one after the given token. A BoundsError is thrown if the token is the past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the past-end token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(log n)

      source
      DataStructures.regressMethod
      regress(token::Token)
      -regress((m,st))

      Return the semitoken of the item in a sorted container one before the given token. A BoundsError is thrown if the token is the before-start token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(log n)

      source
      Base.:+Method
      Base.+(t::Token, j::Integer)
      -Base.-(t::Token, j::Integer)

      Return the token that is j positions ahead (if +) or behind (if -) of t. Here, t is a token for a sorted container and j is an integer. If j is negative, then + regresses while - advances. If the operation t+j or t-j reaches the before-start or past-end positions in the container, then the before-start/past-end tokens are returned (and there is no error). Time: O(j+log n), so this function is not optimized for long jumps.

      source
      Base.Sort.searchsortedfirstMethod
      Base.searchsortedfirst(m::SortedContainer, k)

      Return the semitoken of the first item in the sorted container m that is greater than or equal to k in the sort order. If there is no such item, then the past-end semitoken is returned. Time: O(c log n)

      source
      Base.Sort.searchsortedlastMethod
      Base.searchsortedlast(m::SortedContainer, k)

      Return the semitoken of the last item in the container that is less than or equal to k in sort order. If there is no such item, then the before-start semitoken is returned. Time: O(c log n)

      source
      DataStructures.searchsortedafterMethod
      searchsortedafter(m::SortedContainer, k)

      Return the semitoken of the first item in the container that is greater than k in the sort order. If there is no such item, then the past-end semitoken is returned. Time: O(c log n)

      source
      DataStructures.searchequalrangeMethod
      DataStructures.searchequalrange(smd::SortedMultiDict, k)

      Return two semitokens that correspond to the first and last items in the SortedMultiDict that have key exactly equal to k. If k is not found, then it returns (pastendsemitoken(smd), beforestartsemitoken(smd)). Time: O(c log n)

      source
      DataStructures.findkeyMethod
      findkey(m::SortedSet, k)

      Return the semitoken of the element k in sorted set m. If the element is not present in m, then the past-end semitoken is returned. Time: O(c log n)

      source

      Inserting & Deleting in Sorted Containers

      Base.push!Method
      Base.push!(ss::SortedSet, k)

      Insert the element k into the sorted set ss. If the k is already present, this overwrites the old value. (This is not necessarily a no-op; see remarks about the customizing the sort order.) See also push_return_semitoken!(ss::SortedSet, k). The return value is ss. Time: O(c log n)

      source
      Base.push!Method
      Base.push!(sd::SortedDict, p::Pair)

      Insert key-value pair p, i.e., a k=>v pair, into sd. If the key k is already present, this overwrites the old value. The key is also overwritten (not necessarily a no-op, since sort-order equivalence may differ from equality). The return value is sd. See also push_return_semitoken!(sd::SortedDict, p::Pair). Time: O(c log n)

      source
      DataStructures.push_return_semitoken!Method
      DataStructures.push_return_semitoken!(ss::SortedSet, k)

      Insert the element k into the SortedSet sc. If k is already present, this overwrites the old value. (This is not necessarily a no-op; see remarks about the customizing the sort order.) Unlike push!, the return value is a pair whose first entry is boolean and indicates whether the insertion was new (i.e., the key was not previously present) and the second entry is the semitoken of the new entry. This function replaces the deprecated insert!. Time: O(c log n)

      source
      DataStructures.push_return_semitoken!Method
      DataStructures.push_return_semitoken!(sd::SortedDict, p::Pair)

      Insert pair p of the form k=>v into sd. If the key is already present in sd, this overwrites the old value. Note that the key is also overwritten, which is not necessarily a no-op because equivalence in the sort order does not necessarily imply equality. Unlike push!, the return value is a 2-tuple whose first entry is boolean and indicates whether the insertion was new (i.e., the key was not previously present) and whose second entry is the semitoken of the new entry. This function replaces the deprecated insert!(sd,k,v). Time: O(c log n)

      source
      DataStructures.push_return_semitoken!Method
      DataStructures.push_return_semitoken!(smd::SortedMultiDict, pr::Pair)

      Insert the key-value pair pr, i.e., k=>v, into smd. If k already appears as a key in smd, then k=>v is inserted in the rightmost position after existing items with key k. Unlike push!, the return value is a 2-tuple whose first entry is boolean always equal to true and whose second entry is the semitoken of the new entry. (The reason for returning a bool whose value is always true is for consistency with push_return_semitoken! for SortedDict and SortedSet.) This function replaces the deprecated insert!. Time: O(c log n)

      source
      Base.delete!Method
      Base.delete!(token::Token)

      Delete the item indexed by the token from a sorted container. A BoundsError is thrown if the token is invalid. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid. Time: O(log n).

      source
      Base.delete!Method
      Base.delete!(ss::SortedSet, k)

      Delete element k from sc. After this operation is complete, a token addressing the deleted item is invalid. Returns sc. if k is not present, this operation is a no-op. Time: O(c log n)

      source
      Base.delete!Method
      Base.delete!(sd::SortedDict, k)

      Delete the item whose key is k in sd. After this operation is complete, any token addressing the deleted item is invalid. Returns sc. This is a no-op if k is not present in sd. Time: O(c log n)

      source
      Base.pop!Method
      Base.pop!(ss::SortedSet, k)
      -Base.pop!(ss::SortedSet, k, default)

      Delete the item with key k in ss and return the item that compares equal to k according to the sort order (which is not necessarily k, since equality in the sort-order does not necessarily imply hash-equality). If k is not found, return default, or throw a KeyError if default is not specified. Time: O(c log n)

      source
      Base.pop!Method
      Base.pop!(sd::SortedDict, k)
      -Base.pop!(sd::SortedDict, k, default)

      Delete the item with key k in sd and return the value that was associated with k. If k is not in sd return default, or throw a KeyError if default is not specified. Time: O(c log n)

      source
      Base.popfirst!Method
      Base.popfirst!(ss::SortedSet)

      Delete the item with first key in SortedSet ss and returns the key. This function was named pop! in a previous version of the package. A BoundsError results if ss is empty. Time: O(log n)

      source
      DataStructures.poplast!Method
      poplast!(ss::SortedSet)

      Delete the item with last key in SortedSet ss and returns the key. A BoundsError results if ss is empty. This function will be renamed Base.pop! in a future version of the package. Time: O(log n)

      source

      Iteration and Token Manipulation

      DataStructures.compareMethod
      compare(m::SortedContainer, s::IntSemiToken, t::IntSemiToken)

      Determine the relative position according to the sort order of the data items indexed by tokens (m,s) and (m,t). Return:

      • -1if(m,s) precedes (m,t),
      • 0 if s == t
      • 1 if (m,s)succeeds (m,t).

      The relative positions are determined from the tree topology without any key comparisons. Time: O(log n)

      source
      DataStructures.statusMethod
      status(token::Token) 
      -status((m, st))

      Determine the status of a token. Return values are:

      • 0 = invalid token
      • 1 = valid and points to live data
      • 2 = before-start token
      • 3 = past-end token

      The second form creates the token in-place as a tuple of a sorted container m and a semitoken st. Time: O(1)

      source
      Base.iterateMethod
      Base.iterate(iter::SortedContainerIterable)

      with the following helper functions to construct a SortedContainerIterable:

      inclusive(m::SortedContainer, st1, st2)
      +SortedSet{K}(iter, o::Ordering=Forward)

      Construct a sorted set from an iterable iter using order o. In the first two forms, the element type is inferred from the iterable, which requires copying the data twice. Therefore, the second two forms (specifying K explicitly) are more efficient. Time: O(cn log n)

      source
      DataStructures.SortedSetMethod
      SortedSet{K}(::Val{true}, iterable) where {K}
      +SortedSet{K}(::Val{true}, iterable, ord::Ord) where {K, Ord <: Ordering}

      Construct a SortedSet from an iterable whose entries have type K and that is already in sorted ordered. No duplicates allowed. The first form assumes Forward ordering. Time: O(cn).

      source
      Base.getindexMethod
      Base.getindex(m::SortedDict, st::IntSemiToken)
      +Base.getindex(m::SortedMultiDict, st::IntSemiToken)

      Retrieve value portion of item from SortedDict or SortedMultiDict m indexed by st, a semitoken. Notation m[st] appearing in an expression is equivalent to deref_value(token::Token) where token=(m,st). It is a BoundsError if the token is invalid. Prepending with @inbounds may elide the correctness check and results in undefined behavior if the token is invalid. Time: O(1)

      source
      Base.setindex!Method
      Base.setindex!(m::SortedDict, newvalue, st::IntSemiToken)
      +Base.setindex!(m::SortedMultiDict, newvalue, st::IntSemiToken)

      Set the value portion of item from SortedDict or SortedMultiDict m indexed by st, a semitoken to newvalue. A BoundsError is thrown if the token is invalid. Prepending with @inbounds may elide the correctness check and results in undefined behavior if the token is invalid. Time: O(1)

      source
      Base.setindex!Method
      Base.setindex!(sd::SortedDict, newvalue, k)

      Assign or reassign the value associated with the key k to newvalue. Note that the key is also overwritten; this is not necessarily a no-op since the equivalence in the sort-order does not imply equality. See also push_return_semitoken!(sd::SortedDict, p::Pair). Time: O(c log n)

      source
      DataStructures.derefMethod
      deref(token::Token)
      +deref((m,st))

      Return the data item indexed by the token. If the container is a SortedSet, then this is a key in the set. If the container is a SortedDict or SortedMultiDict, then this is a key=>value pair. It is a BoundsError if the token is invalid or is the before-start or past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start or past-end token. The second form creates the token in-place as a tuple of a sorted container m and a semitoken st. Time: O(1)

      source
      DataStructures.deref_keyMethod
      deref_key(token::Token)
      +deref_key((m,st))

      Return the key portion of a data item (a key=>value pair) in a SortedDict or SortedMultiDict indexed by the token. It is a BoundsError if the token is invalid or is the before-start or past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start or past-end token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(1)

      source
      DataStructures.deref_valueMethod
      deref_value(token::Token)
      +deref_value((m,st))

      Returns the value portion of a data item (a key=>value pair) in a SortedDict or SortedMultiDict indexed by the token. It is a BoundsError if the token is invalid or is the before-start or past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start or past-end token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(1)

      source
      Base.firstindexMethod
      Base.firstindex(m::SortedContainer)

      Return the semitoken of the first entry of the container m, or the past-end semitoken if the container is empty. This function was called startof (now deprecated) in previous versions of the package. Time: O(log n)

      source
      Base.lastindexMethod
      Base.lastindex(m::SortedContainer)

      Return the semitoken of the last entry of the sorted container m, or the before-start semitoken if the container is empty. This function was called endof (now deprecated) in previous versions of the package. Time: O(log n)

      source
      DataStructures.token_firstindexMethod
      token_firstindex(m::SortedContainer)

      Return the token of the first entry of the sorted container m, or the past-end token if the container is empty. Time: O(log n)

      source
      DataStructures.token_lastindexMethod
      token_lastindex(m::SortedContainer)

      Return the token of the last entry of the sorted container m, or the before-start semitoken if the container is empty. Time: O(log n)

      source
      Base.firstMethod
      Base.first(sc::SortedContainer)

      Return the first item (a k=>v pair for SortedDict and SortedMultiDict or an element for SortedSet) in sc according to the sorted order in the container. It is a BoundsError to call this function on an empty container. Equivalent to deref(token_startindex(sc)). Time: O(log n)

      source
      Base.lastMethod
      Base.last(sc::SortedContainer)

      Return the last item (a k=>v pair for SortedDict and SortedMultiDict or a key for SortedSet) in sc according to the sorted order in the container. It is a BoundsError to call this function on an empty container. Equivalent to deref(token_lastindex(sc)). Time: O(log n)

      source
      DataStructures.pastendtokenMethod
      pastendtoken(m::SortedContainer)

      Return the token of the entry that is one past the end of the sorted container m. Time: O(1)

      source
      DataStructures.advanceMethod
      advance(token::Token)
      +advance((m,st))

      Return the semitoken of the item in a sorted container one after the given token. A BoundsError is thrown if the token is the past-end token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the past-end token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(log n)

      source
      DataStructures.regressMethod
      regress(token::Token)
      +regress((m,st))

      Return the semitoken of the item in a sorted container one before the given token. A BoundsError is thrown if the token is the before-start token. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid or points to the before-start token. The second form creates the token in-place as a tuple of a container m and a semitoken st. Time: O(log n)

      source
      Base.:+Method
      Base.+(t::Token, j::Integer)
      +Base.-(t::Token, j::Integer)

      Return the token that is j positions ahead (if +) or behind (if -) of t. Here, t is a token for a sorted container and j is an integer. If j is negative, then + regresses while - advances. If the operation t+j or t-j reaches the before-start or past-end positions in the container, then the before-start/past-end tokens are returned (and there is no error). Time: O(j+log n), so this function is not optimized for long jumps.

      source
      Base.Sort.searchsortedfirstMethod
      Base.searchsortedfirst(m::SortedContainer, k)

      Return the semitoken of the first item in the sorted container m that is greater than or equal to k in the sort order. If there is no such item, then the past-end semitoken is returned. Time: O(c log n)

      source
      Base.Sort.searchsortedlastMethod
      Base.searchsortedlast(m::SortedContainer, k)

      Return the semitoken of the last item in the container that is less than or equal to k in sort order. If there is no such item, then the before-start semitoken is returned. Time: O(c log n)

      source
      DataStructures.searchsortedafterMethod
      searchsortedafter(m::SortedContainer, k)

      Return the semitoken of the first item in the container that is greater than k in the sort order. If there is no such item, then the past-end semitoken is returned. Time: O(c log n)

      source
      DataStructures.searchequalrangeMethod
      DataStructures.searchequalrange(smd::SortedMultiDict, k)

      Return two semitokens that correspond to the first and last items in the SortedMultiDict that have key exactly equal to k. If k is not found, then it returns (pastendsemitoken(smd), beforestartsemitoken(smd)). Time: O(c log n)

      source
      DataStructures.findkeyMethod
      findkey(m::SortedSet, k)

      Return the semitoken of the element k in sorted set m. If the element is not present in m, then the past-end semitoken is returned. Time: O(c log n)

      source

      Inserting & Deleting in Sorted Containers

      Base.push!Method
      Base.push!(ss::SortedSet, k)

      Insert the element k into the sorted set ss. If the k is already present, this overwrites the old value. (This is not necessarily a no-op; see remarks about the customizing the sort order.) See also push_return_semitoken!(ss::SortedSet, k). The return value is ss. Time: O(c log n)

      source
      Base.push!Method
      Base.push!(sd::SortedDict, p::Pair)

      Insert key-value pair p, i.e., a k=>v pair, into sd. If the key k is already present, this overwrites the old value. The key is also overwritten (not necessarily a no-op, since sort-order equivalence may differ from equality). The return value is sd. See also push_return_semitoken!(sd::SortedDict, p::Pair). Time: O(c log n)

      source
      DataStructures.push_return_semitoken!Method
      DataStructures.push_return_semitoken!(ss::SortedSet, k)

      Insert the element k into the SortedSet sc. If k is already present, this overwrites the old value. (This is not necessarily a no-op; see remarks about the customizing the sort order.) Unlike push!, the return value is a pair whose first entry is boolean and indicates whether the insertion was new (i.e., the key was not previously present) and the second entry is the semitoken of the new entry. This function replaces the deprecated insert!. Time: O(c log n)

      source
      DataStructures.push_return_semitoken!Method
      DataStructures.push_return_semitoken!(sd::SortedDict, p::Pair)

      Insert pair p of the form k=>v into sd. If the key is already present in sd, this overwrites the old value. Note that the key is also overwritten, which is not necessarily a no-op because equivalence in the sort order does not necessarily imply equality. Unlike push!, the return value is a 2-tuple whose first entry is boolean and indicates whether the insertion was new (i.e., the key was not previously present) and whose second entry is the semitoken of the new entry. This function replaces the deprecated insert!(sd,k,v). Time: O(c log n)

      source
      DataStructures.push_return_semitoken!Method
      DataStructures.push_return_semitoken!(smd::SortedMultiDict, pr::Pair)

      Insert the key-value pair pr, i.e., k=>v, into smd. If k already appears as a key in smd, then k=>v is inserted in the rightmost position after existing items with key k. Unlike push!, the return value is a 2-tuple whose first entry is boolean always equal to true and whose second entry is the semitoken of the new entry. (The reason for returning a bool whose value is always true is for consistency with push_return_semitoken! for SortedDict and SortedSet.) This function replaces the deprecated insert!. Time: O(c log n)

      source
      Base.delete!Method
      Base.delete!(token::Token)

      Delete the item indexed by the token from a sorted container. A BoundsError is thrown if the token is invalid. Prepending with @inbounds may elide the correctness check and will result in undefined behavior if the token is invalid. Time: O(log n).

      source
      Base.delete!Method
      Base.delete!(ss::SortedSet, k)

      Delete element k from sc. After this operation is complete, a token addressing the deleted item is invalid. Returns sc. if k is not present, this operation is a no-op. Time: O(c log n)

      source
      Base.delete!Method
      Base.delete!(sd::SortedDict, k)

      Delete the item whose key is k in sd. After this operation is complete, any token addressing the deleted item is invalid. Returns sc. This is a no-op if k is not present in sd. Time: O(c log n)

      source
      Base.pop!Method
      Base.pop!(ss::SortedSet, k)
      +Base.pop!(ss::SortedSet, k, default)

      Delete the item with key k in ss and return the item that compares equal to k according to the sort order (which is not necessarily k, since equality in the sort-order does not necessarily imply hash-equality). If k is not found, return default, or throw a KeyError if default is not specified. Time: O(c log n)

      source
      Base.pop!Method
      Base.pop!(sd::SortedDict, k)
      +Base.pop!(sd::SortedDict, k, default)

      Delete the item with key k in sd and return the value that was associated with k. If k is not in sd return default, or throw a KeyError if default is not specified. Time: O(c log n)

      source
      Base.popfirst!Method
      Base.popfirst!(ss::SortedSet)

      Delete the item with first key in SortedSet ss and returns the key. This function was named pop! in a previous version of the package. A BoundsError results if ss is empty. Time: O(log n)

      source
      DataStructures.poplast!Method
      poplast!(ss::SortedSet)

      Delete the item with last key in SortedSet ss and returns the key. A BoundsError results if ss is empty. This function will be renamed Base.pop! in a future version of the package. Time: O(log n)

      source

      Iteration and Token Manipulation

      DataStructures.compareMethod
      compare(m::SortedContainer, s::IntSemiToken, t::IntSemiToken)

      Determine the relative position according to the sort order of the data items indexed by tokens (m,s) and (m,t). Return:

      • -1if(m,s) precedes (m,t),
      • 0 if s == t
      • 1 if (m,s)succeeds (m,t).

      The relative positions are determined from the tree topology without any key comparisons. Time: O(log n)

      source
      DataStructures.statusMethod
      status(token::Token) 
      +status((m, st))

      Determine the status of a token. Return values are:

      • 0 = invalid token
      • 1 = valid and points to live data
      • 2 = before-start token
      • 3 = past-end token

      The second form creates the token in-place as a tuple of a sorted container m and a semitoken st. Time: O(1)

      source
      Base.iterateMethod
      Base.iterate(iter::SortedContainerIterable)

      with the following helper functions to construct a SortedContainerIterable:

      inclusive(m::SortedContainer, st1, st2)
       inclusive(m::SortedContainer, (st1, st2))
       inclusive_key(m::SortedContainer, key1, key2)
       inclusive_key(m::SortedContainer, (key1, key2))
      @@ -63,7 +63,7 @@
           map!(x -> x*2, values(s))

      The workaround is an explicit loop:

          s = SortedDict(3=>4)
           for t in onlysemitokens(s)
               s[t] *= 2
      -    end

      Running time for all iterations: O(c(s + log n)), where s is the number of steps from start to end of the iteration.

      source
      Base.inMethod
      Base.in(k,m::SortedSet)

      Return true iff element k is in sorted set m is a sorted set. Unlike the in function for Set, this routine will thrown an error if k is not convertible to eltype(m). Time: O(c log n)

      source
      Base.inMethod
      Base.in(p::Pair, sd::SortedDict)

      Return true if p is in sd. Here, p is a key=>value pair. Time: O(c log n + d) where d stands for the time to compare two values.

      source
      Base.inMethod
      Base.in(p::Pair, smd::SortedMultiDict)

      Return true if p is in smd. Here, p is a key=>value pair. In the The time is is O(c log n + dl) where d is the time to compare two values and l stands for the number of entries that have the key of the given pair. (So therefore this call is inefficient if the same key addresses a large number of values, and an alternative should be considered.)

      source
      Base.inMethod
      Base.in(x, iter::SortedContainerIterable)

      Returns true if x is in iter, where iter refers to any of the iterable objects described under Base.iterate(iter::SortedContainerIterable), and x is of the appropriate type. For all of the iterables except the five listed below, the algorithm used is a linear-time search. For example, the call:

      (k=>v) in exclusive(sd, st1, st2)

      where sd is a SortedDict, st1 and st2 are semitokens, k is a key, and v is a value, will loop over all entries in the dictionary between the two tokens and a compare for equality using isequal between the indexed item and k=>v.

      The five exceptions are:

      (k=>v) in sd
      +    end

      Running time for all iterations: O(c(s + log n)), where s is the number of steps from start to end of the iteration.

      source
      Base.inMethod
      Base.in(k,m::SortedSet)

      Return true iff element k is in sorted set m is a sorted set. Unlike the in function for Set, this routine will thrown an error if k is not convertible to eltype(m). Time: O(c log n)

      source
      Base.inMethod
      Base.in(p::Pair, sd::SortedDict)

      Return true if p is in sd. Here, p is a key=>value pair. Time: O(c log n + d) where d stands for the time to compare two values.

      source
      Base.inMethod
      Base.in(p::Pair, smd::SortedMultiDict)

      Return true if p is in smd. Here, p is a key=>value pair. In the The time is is O(c log n + dl) where d is the time to compare two values and l stands for the number of entries that have the key of the given pair. (So therefore this call is inefficient if the same key addresses a large number of values, and an alternative should be considered.)

      source
      Base.inMethod
      Base.in(x, iter::SortedContainerIterable)

      Returns true if x is in iter, where iter refers to any of the iterable objects described under Base.iterate(iter::SortedContainerIterable), and x is of the appropriate type. For all of the iterables except the five listed below, the algorithm used is a linear-time search. For example, the call:

      (k=>v) in exclusive(sd, st1, st2)

      where sd is a SortedDict, st1 and st2 are semitokens, k is a key, and v is a value, will loop over all entries in the dictionary between the two tokens and a compare for equality using isequal between the indexed item and k=>v.

      The five exceptions are:

      (k=>v) in sd
       (k=>v) in smd
       k in ss
       k in keys(sd)
      @@ -71,7 +71,7 @@
       (k=>v) in collect(smd)
       k in collect(ss)
       k in collect(keys(sd))
      -k in collect(keys(smd))
      source

      Misc. Functions

      Base.isempty(m::SortedContainer)
      +k in collect(keys(smd))
      source

      Misc. Functions

      Base.isempty(m::SortedContainer)
       Base.empty!(m::SortedContainer)
       Base.empty(m::SortedContainer)
       Base.length(m::SortedContainer)
      @@ -82,22 +82,22 @@
       Base.keytype(m::SortedContainerIteration)
       Base.valtype(m::SortedContainerIteration)

      These functions from Base are all applicable to sorted containers with the obvious meaning. The eltype, keytype, and valtype functions may be applied either to the object m or its type. Note that keytype and valtype are applicable only to SortedDict and SortedMultiDict, or to pairs iterations over SortedDict or SortedMultiDict. Time: O(1)

      DataStructures.ordtypeMethod
      ordtype(sc::SortedSet)
       ordtype(sc::SortedDict)
      -ordtype(sc::SortedMultiDict)

      Return the order type for a sorted container. This function may also be applied to the type itself. Time: O(1)

      source
      DataStructures.orderobjectMethod
      orderobject(sc::SortedContainer)

      Return the order object used to construct the container. Time: O(1)

      source
      Base.haskeyMethod
      haskey(sc::SortedContainer, k)

      Return true iff key k is present in sc. Equivalent to in(k,sc) for a SortedSet, or to in(k,keys(sc)) for a SortedDict or SortedMultiDict. Time: O(c log n)

      source
      Base.getMethod
      Base.get(sd::SortedDict,k,default)
      -Base.get(default_f::Union{Function,Type}, sd::SortedDict, k)

      Return the value associated with key k where sd is a SortedDict, or else returns default if k is not in sd. The second form obtains default as the return argument of the function/type-constructor default_f (with no arguments) when the key is not present. Time: O(c log n)

      source
      Base.get!Method
      Base.get!(sd::SortedDict,k,default)
      -Base.get!(default_f::Union{Function,Type}, sd::SortedDict, k)

      Return the value associated with key k where sd is a SortedDict, or else return default if k is not in sd, and in the latter case, inserts (k,default) into sd. The second form computes a default value by calling the function default_f (with no arguments) or the constructor of type default_f when the key is not present. Time: O(c log n)

      source
      Base.getkeyMethod
      Base.getkey(sd::SortedDict,k,defaultk)

      Return the key k where sd is a SortedDict, if k is in sd else it returns defaultk. If the container uses in its ordering an eq method different from isequal (e.g., case-insensitive ASCII strings illustrated below), then the return value is the actual key stored in the SortedDict that is equivalent to k according to the eq method, which might not be equal to k. Similarly, if the user performs an implicit conversion as part of the call (e.g., the container has keys that are floats, but the k argument to getkey is an Int), then the returned key is the actual stored key rather than k. Time: O(c log n)

      source
      Base.isequalMethod
      Base.isequal(ss1::SortedSet{K,Ord}, ss2::SortedSet{K,Ord}) where {K,Ord <: Ordering}
      -Base.issetequal(ss1::SortedSet{K,Ord}, ss2::SortedSet{K,Ord}) where {K,Ord <: Ordering}

      Check if two sorted sets are equal in the sense that they contain the same items. Note that isequal in this sense does not imply correspondence between semitokens for items in sc1 with those for sc2. Time: O(cn) where n is the size of the smaller container. If the two sorted sets have K, different Ord, or different order objects, then a fallback routine isequal(::AbstractSet, ::AbstractSet) is invoked.

      source
      Base.isequalMethod
      Base.isequal(sd1::SortedDict{K,V,Ord}, sd2::SortedDict{K,V,Ord}) where {K, V, Ord <: Ordering}

      Check if two SortedDicts are equal in the sense that they contain the same items; the keys are compared using the eq method, while the values are compared with the isequal function. Note that isequal in this sense does not imply correspondence between semitokens for items in sd1 with those for sd2. Time: O(cn). Note that if K, V, Ord, or the order objects of sd1 and sd2 are different, then a fallback routine Base.isequal(::AbstractDict, ::AbstractDict) is invoked. Time: O(cn)

      source
      Base.isequalMethod
      Base.isequal(smd1::SortedMultiDict{K,V,Ord}, smd2::SortedMultiDict{K,V,Ord}) where {K, V, Ord <: Ordering}

      Check if two SortedMultiDicts are equal in the sense that they contain the same items in the same order (that is, the same insertion order). They must have the same order object, else they compare unequal. The keys are compared using the eq method, while the values are compared with the isequal function. Note that isequal in this sense does not imply any correspondence between semitokens for items in smd1 with those for smd2. Time: O(cn)

      source
      DataStructures.packcopyMethod
      copy(sc::SortedSet)
      +ordtype(sc::SortedMultiDict)

      Return the order type for a sorted container. This function may also be applied to the type itself. Time: O(1)

      source
      DataStructures.orderobjectMethod
      orderobject(sc::SortedContainer)

      Return the order object used to construct the container. Time: O(1)

      source
      Base.haskeyMethod
      haskey(sc::SortedContainer, k)

      Return true iff key k is present in sc. Equivalent to in(k,sc) for a SortedSet, or to in(k,keys(sc)) for a SortedDict or SortedMultiDict. Time: O(c log n)

      source
      Base.getMethod
      Base.get(sd::SortedDict,k,default)
      +Base.get(default_f::Union{Function,Type}, sd::SortedDict, k)

      Return the value associated with key k where sd is a SortedDict, or else returns default if k is not in sd. The second form obtains default as the return argument of the function/type-constructor default_f (with no arguments) when the key is not present. Time: O(c log n)

      source
      Base.get!Method
      Base.get!(sd::SortedDict,k,default)
      +Base.get!(default_f::Union{Function,Type}, sd::SortedDict, k)

      Return the value associated with key k where sd is a SortedDict, or else return default if k is not in sd, and in the latter case, inserts (k,default) into sd. The second form computes a default value by calling the function default_f (with no arguments) or the constructor of type default_f when the key is not present. Time: O(c log n)

      source
      Base.getkeyMethod
      Base.getkey(sd::SortedDict,k,defaultk)

      Return the key k where sd is a SortedDict, if k is in sd else it returns defaultk. If the container uses in its ordering an eq method different from isequal (e.g., case-insensitive ASCII strings illustrated below), then the return value is the actual key stored in the SortedDict that is equivalent to k according to the eq method, which might not be equal to k. Similarly, if the user performs an implicit conversion as part of the call (e.g., the container has keys that are floats, but the k argument to getkey is an Int), then the returned key is the actual stored key rather than k. Time: O(c log n)

      source
      Base.isequalMethod
      Base.isequal(ss1::SortedSet{K,Ord}, ss2::SortedSet{K,Ord}) where {K,Ord <: Ordering}
      +Base.issetequal(ss1::SortedSet{K,Ord}, ss2::SortedSet{K,Ord}) where {K,Ord <: Ordering}

      Check if two sorted sets are equal in the sense that they contain the same items. Note that isequal in this sense does not imply correspondence between semitokens for items in sc1 with those for sc2. Time: O(cn) where n is the size of the smaller container. If the two sorted sets have K, different Ord, or different order objects, then a fallback routine isequal(::AbstractSet, ::AbstractSet) is invoked.

      source
      Base.isequalMethod
      Base.isequal(sd1::SortedDict{K,V,Ord}, sd2::SortedDict{K,V,Ord}) where {K, V, Ord <: Ordering}

      Check if two SortedDicts are equal in the sense that they contain the same items; the keys are compared using the eq method, while the values are compared with the isequal function. Note that isequal in this sense does not imply correspondence between semitokens for items in sd1 with those for sd2. Time: O(cn). Note that if K, V, Ord, or the order objects of sd1 and sd2 are different, then a fallback routine Base.isequal(::AbstractDict, ::AbstractDict) is invoked. Time: O(cn)

      source
      Base.isequalMethod
      Base.isequal(smd1::SortedMultiDict{K,V,Ord}, smd2::SortedMultiDict{K,V,Ord}) where {K, V, Ord <: Ordering}

      Check if two SortedMultiDicts are equal in the sense that they contain the same items in the same order (that is, the same insertion order). They must have the same order object, else they compare unequal. The keys are compared using the eq method, while the values are compared with the isequal function. Note that isequal in this sense does not imply any correspondence between semitokens for items in smd1 with those for smd2. Time: O(cn)

      source
      DataStructures.packcopyMethod
      copy(sc::SortedSet)
       copy(sc::SortedDict)
       copy(sc::SortedMultiDict)
       packcopy(sc::SortedSet)
       packcopy(sc::SortedDict)
      -packcopy(sc::SortedMultiDict)

      Return a copy of sc, where sc is a sorted container, in which the data is packed. When deletions take place, the previously allocated memory is not returned. This function can be used to reclaim memory after many deletions. Time: O(cn)

      Note that the semitokens valid for the original container are no longer valid for the copy because the indexing structure is rebuilt by these copies. If an exact copy is needed in which semitokens remain valid, use Base.deepcopy.

      source
      DataStructures.packdeepcopyMethod
      packdeepcopy(sc::SortedSet)
      +packcopy(sc::SortedMultiDict)

      Return a copy of sc, where sc is a sorted container, in which the data is packed. When deletions take place, the previously allocated memory is not returned. This function can be used to reclaim memory after many deletions. Time: O(cn)

      Note that the semitokens valid for the original container are no longer valid for the copy because the indexing structure is rebuilt by these copies. If an exact copy is needed in which semitokens remain valid, use Base.deepcopy.

      source
      DataStructures.packdeepcopyMethod
      packdeepcopy(sc::SortedSet)
       packdeepcopy(sc::SortedDict)
      -packdeepcopy(sc::SorteMultiDict)

      Return a packed copy of sc, where sc is a sorted container in which the keys and values are deep-copied. This function can be used to reclaim memory after many deletions. Time: O(cn)

      source
      Base.mergeMethod
      Base.merge(sd::SortedDict{K,V,Ord}, d1::AbstractDict{K,V}...) where {K,V,Ord <: Ordering}

      Merge one or more dicts into a single SortedDict and return the new SortedDict. Arguments d1 etc. must have the same key-value type as sd. In the case of keys duplicated among the arguments, the rightmost argument that owns the key gets its value stored. Time: O(cN log N), where N is the total size of all the arguments. If all the arguments are SortedDicts with the same key, value, and order object, then the time is O(cN).

      source
      Base.merge!Method
      Base.merge!(sd::SortedDict{K,V,Ord}, d1::AbstractDict{K,V}...) where {K,V,Ord<:Ordering}

      Merge one or more dicts d1, etc. into sd. These must all must have the same key-value types. In the case of keys duplicated among the arguments, the rightmost argument that owns the key gets its value stored. Time: O(cN log N), where N is the total size of all the arguments.

      source
      Base.mergeMethod
      Base.merge(smd::SortedMultiDict, iter...)

      Merge smd and one or more iterables and return the resulting new SortedMultiDict. The iterables must have the same key-value type as smd. Items with equal keys are stored with left-to-right ordering. Time: O(cN log N), where N is the total size of all the arguments. If all the arguments are SortedMultiDicts with the same key, value, and order object, then the time is O(cN).

      source
      Base.merge!Method
      Base.merge!(smd::SortedMultiDict, iter...)

      Merge one or more iterables iter, etc. into smd. These must all must have the same key-value types. Items with equal keys are stored with left-to-right ordering. Time: O(cN log N), where N is the total size of all the arguments.

      source

      Set operations

      The SortedSet container supports the following set operations. Note that in the case of intersect, symdiff and setdiff, the two SortedSets should have the same key and ordering object. If they have different key or ordering types, no error message is produced; instead, the built-in default versions of these functions (that can be applied to Any iterables and that return arrays) are invoked.

      Base.union!Method
      Base.union!(ss::SortedSet, iterable...)

      Insert each item among the second and following arguments (which must be iterable) into the SortedSet ss. The items must be convertible to the key-type of ss. Time: O(cN log N) where N is the total number of items in the iterable arguments.

      source
      Base.unionMethod
      Base.union(ss::SortedSet, iterable...)

      Compute and return the union of a sorted set and one or more iterables. They must have the same keytype. If they are all sorted sets with the same order object, then the required time is O(cn), where n is the total size. If not, then the fallback routine requires time O(cn log n).

      source
      Base.intersectMethod
      Base.intersect(ss::SortedSet, others...)

      Intersect SortedSets with other SortedSets or other iterables and return the intersection as a new SortedSet. Time: O(cn), where n is the total number of items in all the arguments if all the arguments are SortedSets of the same type and same order object. Otherwise, the time is O(cn log n)

      source
      Base.symdiffMethod
      Base.symdiff(ss1::SortedSet, iterable)

      Compute and return the symmetric difference of ss1 and iterable, i.e., a sorted set containing entries that are in one of ss1 or iterable but not both. Time: O(cn), where n is the total size of the two containers if both are sorted sets with the same key and order objects. Otherwise, the time is O(cn log n)

      source
      Base.setdiffMethod
      Base.setdiff(ss1::SortedSet{K,Ord}, ss2::SortedSet{K,Ord}) where {K, Ord<:Ordering}
      -Base.setdiff(ss1::SortedSet, others...)

      Return the set difference, i.e., a sorted set containing entries in ss1 but not in ss2 or successive arguments. Time for the first form: O(cn) where n is the total size of both sets provided that they are both sorted sets of the same type and order object. The second form computes the set difference between ss1 and all the others, which are all iterables. The second form requires O(cn log n) time.

      source
      Base.setdiff!Method
      Base.setdiff!(ss::SortedSet, iterable..)

      Delete items in ss that appear in any of the iterables. The arguments after the first must be iterables each of whose entries must convertible to the key type of m1. Time: O(cm log n), where n is the size of ss and m is the total number of items in iterable.

      source
      Base.issubsetMethod
      Base.issubset(iterable, ss::SortedSet)

      Check whether each item of the first argument is an element of ss. The entries must be convertible to the key-type of ss. Time: O(cm log n), where n is the size of ss and m is the number of items in iterable. If both are sorted sets of the same keytype and order object and if m > n / log n, then an algorithm whose running time is O(c(m+n)) is used.

      source

      Ordering of keys

      As mentioned earlier, the default ordering of keys uses isless and isequal functions. If the default ordering is used, it is a requirement of the container that isequal(a,b) is true if and only if !isless(a,b) and !isless(b,a) are both true. This relationship between isequal and isless holds for common built-in types, but it may not hold for all types, especially user-defined types. If it does not hold for a certain type, then a custom ordering argument must be defined as discussed in the next few paragraphs.

      The name for the default ordering (i.e., using isless and isequal) is Forward. Note: this is the name of the ordering object; its type is ForwardOrdering. Another possible ordering object is Reverse, which reverses the usual sorted order. This name must be imported import Base.Reverse if it is used.

      As an example of a custom ordering, suppose the keys are of type String, and the user wishes to order the keys ignoring case: APPLE, berry and Cherry would appear in that order, and APPLE and aPPlE would be indistinguishable in this ordering.

      The simplest approach is to define an ordering object of the form Lt(my_isless), where Lt is a built-in type (see ordering.jl) and my_isless is the user's comparison function. In the above example, the ordering object would be:

      Lt((x,y) -> isless(lowercase(x),lowercase(y)))

      The ordering object is indicated in the above list of constructors in the o position (see above for constructor syntax).

      This approach may suffer from a performance hit because higher performance may be possible if an equality method is also available as well as a less-than method. A more complicated but higher-performance method to implement a custom ordering is as follows. First, the user creates a singleton type that is a subtype of Ordering as follows:

      struct CaseInsensitive <: Ordering
      +packdeepcopy(sc::SorteMultiDict)

      Return a packed copy of sc, where sc is a sorted container in which the keys and values are deep-copied. This function can be used to reclaim memory after many deletions. Time: O(cn)

      source
      Base.mergeMethod
      Base.merge(sd::SortedDict{K,V,Ord}, d1::AbstractDict{K,V}...) where {K,V,Ord <: Ordering}

      Merge one or more dicts into a single SortedDict and return the new SortedDict. Arguments d1 etc. must have the same key-value type as sd. In the case of keys duplicated among the arguments, the rightmost argument that owns the key gets its value stored. Time: O(cN log N), where N is the total size of all the arguments. If all the arguments are SortedDicts with the same key, value, and order object, then the time is O(cN).

      source
      Base.merge!Method
      Base.merge!(sd::SortedDict{K,V,Ord}, d1::AbstractDict{K,V}...) where {K,V,Ord<:Ordering}

      Merge one or more dicts d1, etc. into sd. These must all must have the same key-value types. In the case of keys duplicated among the arguments, the rightmost argument that owns the key gets its value stored. Time: O(cN log N), where N is the total size of all the arguments.

      source
      Base.mergeMethod
      Base.merge(smd::SortedMultiDict, iter...)

      Merge smd and one or more iterables and return the resulting new SortedMultiDict. The iterables must have the same key-value type as smd. Items with equal keys are stored with left-to-right ordering. Time: O(cN log N), where N is the total size of all the arguments. If all the arguments are SortedMultiDicts with the same key, value, and order object, then the time is O(cN).

      source
      Base.merge!Method
      Base.merge!(smd::SortedMultiDict, iter...)

      Merge one or more iterables iter, etc. into smd. These must all must have the same key-value types. Items with equal keys are stored with left-to-right ordering. Time: O(cN log N), where N is the total size of all the arguments.

      source

      Set operations

      The SortedSet container supports the following set operations. Note that in the case of intersect, symdiff and setdiff, the two SortedSets should have the same key and ordering object. If they have different key or ordering types, no error message is produced; instead, the built-in default versions of these functions (that can be applied to Any iterables and that return arrays) are invoked.

      Base.union!Method
      Base.union!(ss::SortedSet, iterable...)

      Insert each item among the second and following arguments (which must be iterable) into the SortedSet ss. The items must be convertible to the key-type of ss. Time: O(cN log N) where N is the total number of items in the iterable arguments.

      source
      Base.unionMethod
      Base.union(ss::SortedSet, iterable...)

      Compute and return the union of a sorted set and one or more iterables. They must have the same keytype. If they are all sorted sets with the same order object, then the required time is O(cn), where n is the total size. If not, then the fallback routine requires time O(cn log n).

      source
      Base.intersectMethod
      Base.intersect(ss::SortedSet, others...)

      Intersect SortedSets with other SortedSets or other iterables and return the intersection as a new SortedSet. Time: O(cn), where n is the total number of items in all the arguments if all the arguments are SortedSets of the same type and same order object. Otherwise, the time is O(cn log n)

      source
      Base.symdiffMethod
      Base.symdiff(ss1::SortedSet, iterable)

      Compute and return the symmetric difference of ss1 and iterable, i.e., a sorted set containing entries that are in one of ss1 or iterable but not both. Time: O(cn), where n is the total size of the two containers if both are sorted sets with the same key and order objects. Otherwise, the time is O(cn log n)

      source
      Base.setdiffMethod
      Base.setdiff(ss1::SortedSet{K,Ord}, ss2::SortedSet{K,Ord}) where {K, Ord<:Ordering}
      +Base.setdiff(ss1::SortedSet, others...)

      Return the set difference, i.e., a sorted set containing entries in ss1 but not in ss2 or successive arguments. Time for the first form: O(cn) where n is the total size of both sets provided that they are both sorted sets of the same type and order object. The second form computes the set difference between ss1 and all the others, which are all iterables. The second form requires O(cn log n) time.

      source
      Base.setdiff!Method
      Base.setdiff!(ss::SortedSet, iterable..)

      Delete items in ss that appear in any of the iterables. The arguments after the first must be iterables each of whose entries must convertible to the key type of m1. Time: O(cm log n), where n is the size of ss and m is the total number of items in iterable.

      source
      Base.issubsetMethod
      Base.issubset(iterable, ss::SortedSet)

      Check whether each item of the first argument is an element of ss. The entries must be convertible to the key-type of ss. Time: O(cm log n), where n is the size of ss and m is the number of items in iterable. If both are sorted sets of the same keytype and order object and if m > n / log n, then an algorithm whose running time is O(c(m+n)) is used.

      source

      Ordering of keys

      As mentioned earlier, the default ordering of keys uses isless and isequal functions. If the default ordering is used, it is a requirement of the container that isequal(a,b) is true if and only if !isless(a,b) and !isless(b,a) are both true. This relationship between isequal and isless holds for common built-in types, but it may not hold for all types, especially user-defined types. If it does not hold for a certain type, then a custom ordering argument must be defined as discussed in the next few paragraphs.

      The name for the default ordering (i.e., using isless and isequal) is Forward. Note: this is the name of the ordering object; its type is ForwardOrdering. Another possible ordering object is Reverse, which reverses the usual sorted order. This name must be imported import Base.Reverse if it is used.

      As an example of a custom ordering, suppose the keys are of type String, and the user wishes to order the keys ignoring case: APPLE, berry and Cherry would appear in that order, and APPLE and aPPlE would be indistinguishable in this ordering.

      The simplest approach is to define an ordering object of the form Lt(my_isless), where Lt is a built-in type (see ordering.jl) and my_isless is the user's comparison function. In the above example, the ordering object would be:

      Lt((x,y) -> isless(lowercase(x),lowercase(y)))

      The ordering object is indicated in the above list of constructors in the o position (see above for constructor syntax).

      This approach may suffer from a performance hit because higher performance may be possible if an equality method is also available as well as a less-than method. A more complicated but higher-performance method to implement a custom ordering is as follows. First, the user creates a singleton type that is a subtype of Ordering as follows:

      struct CaseInsensitive <: Ordering
       end

      Next, the user defines a method named lt for less-than in this ordering:

      lt(::CaseInsensitive, a, b) = isless(lowercase(a), lowercase(b))

      The first argument to lt is an object of the CaseInsensitive type (there is only one such object since it is a singleton type). The container also needs an equal-to function; the default is:

      eq(o::Ordering, a, b) = !lt(o, a, b) && !lt(o, b, a)

      The user can also customize this function with a more efficient implementation. In the above example, an appropriate customization would be:

      eq(::CaseInsensitive, a, b) = isequal(lowercase(a), lowercase(b))

      Note: the user-defined eq and lt functions must be compatible in the sense that !lt(o, a, b) && !lt(o, b, a) if and only if eq(o, a, b).

      Finally, the user specifies the unique element of CaseInsensitive, namely the object CaseInsensitive(), as the ordering object to the SortedDict, SortedMultiDict or SortedSet constructor.

      For the above code to work, the module must make the following declarations, typically near the beginning:

      import Base.Ordering
       import Base.lt
       import DataStructures.eq

      Cautionary note on mutable keys

      As with ordinary Dicts, keys for the sorted containers can be either mutable or immutable. In the case of mutable keys, it is important that the keys not be mutated once they are in the container else the indexing structure will be corrupted. (The same restriction applies to Dict.) For example, the following sequence of statements leaves sd in a corrupted state:

      sd = SortedDict{Vector{Int},Int}()
       k = [1,2,3]
       sd[k] = 19
       sd[[6,4]] = 12
      -k[1] = 7

      Performance of Sorted Containers

      The sorted containers are currently not optimized for cache performance.

      +k[1] = 7

      Performance of Sorted Containers

      The sorted containers are currently not optimized for cache performance.

      diff --git a/dev/sparse_int_set/index.html b/dev/sparse_int_set/index.html index 41ec7658d..f717ff19a 100644 --- a/dev/sparse_int_set/index.html +++ b/dev/sparse_int_set/index.html @@ -1,2 +1,2 @@ -DataStructures.SparseIntSet · DataStructures.jl

      DataStructures.SparseIntSet

      Implementation of a Sparse Integer Set, for background see Sparse Sets. Only positive non-zero Ints are allowed inside the set. The idea is to have one packed Vector storing all the Ints contained in the set as to allow for fast iteration, and a sparse, paged reverse Vector with the position of a particular Int inside the packed Vector. This allows for very fast iteration, insertion and deletion of indices. Most behavior is similar to a normal IntSet, however collect, first and last are with respected to the packed vector, in which the ordering is not guaranteed. The reverse Vector is paged, meaning that it is a Vector{Vector{Int}} where each of the Vector{Int}s has the length of one memory page of Ints. Every time an index that was not yet in the range of the already present pages, a new one will be created and added to the reverse, allowing for dynamical growth. Popping the last Int of a particular page will automatically clean up the memory of that page.

      +DataStructures.SparseIntSet · DataStructures.jl

      DataStructures.SparseIntSet

      Implementation of a Sparse Integer Set, for background see Sparse Sets. Only positive non-zero Ints are allowed inside the set. The idea is to have one packed Vector storing all the Ints contained in the set as to allow for fast iteration, and a sparse, paged reverse Vector with the position of a particular Int inside the packed Vector. This allows for very fast iteration, insertion and deletion of indices. Most behavior is similar to a normal IntSet, however collect, first and last are with respected to the packed vector, in which the ordering is not guaranteed. The reverse Vector is paged, meaning that it is a Vector{Vector{Int}} where each of the Vector{Int}s has the length of one memory page of Ints. Every time an index that was not yet in the range of the already present pages, a new one will be created and added to the reverse, allowing for dynamical growth. Popping the last Int of a particular page will automatically clean up the memory of that page.

      diff --git a/dev/splay_tree/index.html b/dev/splay_tree/index.html index 9ec28c4a2..d36993464 100644 --- a/dev/splay_tree/index.html +++ b/dev/splay_tree/index.html @@ -16,4 +16,4 @@ end julia> haskey(tree, 5) -false +false diff --git a/dev/stack/index.html b/dev/stack/index.html index fe6a276d4..0fe32eb6b 100644 --- a/dev/stack/index.html +++ b/dev/stack/index.html @@ -25,7 +25,7 @@ Stack{Int64}(Deque [Int64[]]) julia> s_float = Stack{Float64}() # create a stack with Float64 elements -Stack{Float64}(Deque [Float64[]])source

      Usage

      The Stack type implements the following methods:


      Base.:==Method
      ==(x::Stack, y::Stack)

      Check if stacks x and y are equal in terms of their contents and the order in which they are present in the stack. Internally calls ==() for each of the pairs formed by the elements of x and y in the order they appear in the stack.

      Example

      julia> s1, s2 = Stack{String}(), Stack{String}()
      +Stack{Float64}(Deque [Float64[]])
      source

      Usage

      The Stack type implements the following methods:


      Base.:==Method
      ==(x::Stack, y::Stack)

      Check if stacks x and y are equal in terms of their contents and the order in which they are present in the stack. Internally calls ==() for each of the pairs formed by the elements of x and y in the order they appear in the stack.

      Example

      julia> s1, s2 = Stack{String}(), Stack{String}()
       (Stack{String}(Deque [String[]]), Stack{String}(Deque [String[]]))
       
       julia> for string in ["foo", "bar", "42"]
      @@ -48,7 +48,7 @@
       julia> for num in [1, 2, 4, 3] push!(b, num) end
       
       julia> a == b # same elements but in different order
      -false
      source
      Base.eltypeMethod
      eltype(::Type{Stack{T}}) where {T}

      Return the type of the elements in the stack.

      source
      Base.empty!Method
      empty!(s::Stack)

      Make s empty by inplace-removing all its elements.

      source
      Base.firstMethod
      first(s::Stack)

      Get the first element of s in Last In, First Out order. Since s is a stack, the first element will be the element at the top of s (also known as "peek" of the stack).

      Example

      julia> s = Stack{Float32}()
      +false
      source
      Base.eltypeMethod
      eltype(::Type{Stack{T}}) where {T}

      Return the type of the elements in the stack.

      source
      Base.empty!Method
      empty!(s::Stack)

      Make s empty by inplace-removing all its elements.

      source
      Base.firstMethod
      first(s::Stack)

      Get the first element of s in Last In, First Out order. Since s is a stack, the first element will be the element at the top of s (also known as "peek" of the stack).

      Example

      julia> s = Stack{Float32}()
       Stack{Float32}(Deque [Float32[]])
       
       julia> for i in range(1, 0.2, 5)
      @@ -59,7 +59,7 @@
       Stack{Float32}(Deque [Float32[1.0, 0.8, 0.6, 0.4, 0.2]])
       
       julia> first(s)
      -0.2f0
      source
      Base.isemptyMethod
      isempty(s::Stack)

      Returns true if stack s is empty - i.e. has no elements - or false otherwise.

      source
      Base.lastMethod
      last(s::Stack)

      Get the last element of s in Last In, First Out. Since s is a stack, the last element will be the at bottom of the stack.

      Example

      julia> s = Stack{Float32}()
      +0.2f0
      source
      Base.isemptyMethod
      isempty(s::Stack)

      Returns true if stack s is empty - i.e. has no elements - or false otherwise.

      source
      Base.lastMethod
      last(s::Stack)

      Get the last element of s in Last In, First Out. Since s is a stack, the last element will be the at bottom of the stack.

      Example

      julia> s = Stack{Float32}()
       Stack{Float32}(Deque [Float32[]])
       
       julia> for i in range(1, 0.2, 5)
      @@ -70,4 +70,4 @@
       Stack{Float32}(Deque [Float32[1.0, 0.8, 0.6, 0.4, 0.2]])
       
       julia> last(s)
      -1.0f0
      source
      Base.lengthMethod
      length(s::Stack)

      Return the number of elements in stack s.

      source
      Base.pop!Method
      pop!(s::Stack)

      Remove and return the top element from stack s.

      source
      Base.push!Method
      push!(s::Stack, x)

      Insert new element x in top of stack s.

      source
      +1.0f0source
      Base.lengthMethod
      length(s::Stack)

      Return the number of elements in stack s.

      source
      Base.pop!Method
      pop!(s::Stack)

      Remove and return the top element from stack s.

      source
      Base.push!Method
      push!(s::Stack, x)

      Insert new element x in top of stack s.

      source
      diff --git a/dev/swiss_dict/index.html b/dev/swiss_dict/index.html index 59200cab6..387c1a56e 100644 --- a/dev/swiss_dict/index.html +++ b/dev/swiss_dict/index.html @@ -23,4 +23,4 @@ 3 => 'c' julia> pop!(d) -1 => 'a' +1 => 'a' diff --git a/dev/trie/index.html b/dev/trie/index.html index 1493d63c2..e08b43a77 100644 --- a/dev/trie/index.html +++ b/dev/trie/index.html @@ -40,4 +40,4 @@ 3-element Vector{String}: "A" "ABC" - "ABCD" + "ABCD"