context_start_lineno int64 1 913 | line_no int64 16 984 | repo stringclasses 5
values | id int64 0 416 | target_function_prompt stringlengths 201 13.6k | function_signature stringlengths 201 13.6k | solution_position listlengths 2 2 | raw_solution stringlengths 201 13.6k | focal_code stringlengths 201 13.6k | function_name stringlengths 2 38 | start_line int64 1 913 | end_line int64 16 984 | file_path stringlengths 10 52 | context stringlengths 4.52k 9.85k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
230 | 241 | DataStructures.jl | 0 | function Base.intersect!(a::Accumulator, b::Accumulator)
for k in union(keys(a), keys(b)) # union not intersection as we want to check both multiplicities
va = a[k]
vb = b[k]
va >= 0 || throw(MultiplicityException(k, va))
vb >= 0 || throw(MultiplicityException(k, vb))
a[k] =... | function Base.intersect!(a::Accumulator, b::Accumulator)
for k in union(keys(a), keys(b)) # union not intersection as we want to check both multiplicities
va = a[k]
vb = b[k]
va >= 0 || throw(MultiplicityException(k, va))
vb >= 0 || throw(MultiplicityException(k, vb))
a[k] =... | [
230,
241
] | function Base.intersect!(a::Accumulator, b::Accumulator)
for k in union(keys(a), keys(b)) # union not intersection as we want to check both multiplicities
va = a[k]
vb = b[k]
va >= 0 || throw(MultiplicityException(k, va))
vb >= 0 || throw(MultiplicityException(k, vb))
a[k] =... | function Base.intersect!(a::Accumulator, b::Accumulator)
for k in union(keys(a), keys(b)) # union not intersection as we want to check both multiplicities
va = a[k]
vb = b[k]
va >= 0 || throw(MultiplicityException(k, va))
vb >= 0 || throw(MultiplicityException(k, vb))
a[k] =... | Base.intersect! | 230 | 241 | src/accumulator.jl | #FILE: DataStructures.jl/src/sparse_int_set.jl
##CHUNK 1
#Is there a more performant way to do this?
Base.intersect!(s1::SparseIntSet, ns) = copy!(s1, intersect(s1, ns))
Base.setdiff(s::SparseIntSet, ns) = setdiff!(copy(s), ns)
function Base.setdiff!(s::SparseIntSet, ns)
for n in ns
pop!(s, n, nothing)
... |
83 | 93 | DataStructures.jl | 1 | function left_rotate(z::AVLTreeNode)
y = z.rightChild
α = y.leftChild
y.leftChild = z
z.rightChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | function left_rotate(z::AVLTreeNode)
y = z.rightChild
α = y.leftChild
y.leftChild = z
z.rightChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | [
83,
93
] | function left_rotate(z::AVLTreeNode)
y = z.rightChild
α = y.leftChild
y.leftChild = z
z.rightChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | function left_rotate(z::AVLTreeNode)
y = z.rightChild
α = y.leftChild
y.leftChild = z
z.rightChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | left_rotate | 83 | 93 | src/avl_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
node_x.parent.rightChild = node_y
end
node_y.leftChild = node_x
node_x.parent = node_y
end
"""
right_rotate!(tree::RBTree, node_x::RBTreeNode)
Performs a right-rotation on `node_x` and updates `tree.root`, if required.
"""
function right... |
100 | 110 | DataStructures.jl | 2 | function right_rotate(z::AVLTreeNode)
y = z.leftChild
α = y.rightChild
y.rightChild = z
z.leftChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | function right_rotate(z::AVLTreeNode)
y = z.leftChild
α = y.rightChild
y.rightChild = z
z.leftChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | [
100,
110
] | function right_rotate(z::AVLTreeNode)
y = z.leftChild
α = y.rightChild
y.rightChild = z
z.leftChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | function right_rotate(z::AVLTreeNode)
y = z.leftChild
α = y.rightChild
y.rightChild = z
z.leftChild = α
z.height = compute_height(z)
y.height = compute_height(y)
z.subsize = compute_subtree_size(z)
y.subsize = compute_subtree_size(y)
return y
end | right_rotate | 100 | 110 | src/avl_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
end
end
node.parent = node_y
if node_y == nothing
tree.root = node
elseif node.data < node_y.data
node_y.leftChild = node
else
node_y.rightChild = node
end
end
"""
left_rotate!(tree::RBTree, node_x::RB... |
124 | 138 | DataStructures.jl | 3 | function search_node(tree::AVLTree{K}, d::K) where K
prev = nothing
node = tree.root
while node != nothing && node.data != nothing && node.data != d
prev = node
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return... | function search_node(tree::AVLTree{K}, d::K) where K
prev = nothing
node = tree.root
while node != nothing && node.data != nothing && node.data != d
prev = node
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return... | [
124,
138
] | function search_node(tree::AVLTree{K}, d::K) where K
prev = nothing
node = tree.root
while node != nothing && node.data != nothing && node.data != d
prev = node
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return... | function search_node(tree::AVLTree{K}, d::K) where K
prev = nothing
node = tree.root
while node != nothing && node.data != nothing && node.data != d
prev = node
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return... | search_node | 124 | 138 | src/avl_tree.jl | #FILE: DataStructures.jl/src/splay_tree.jl
##CHUNK 1
x = maximum_node(s)
splay!(tree, x)
x.rightChild = t
t.parent = x
return x
end
end
function search_node(tree::SplayTree{K}, d::K) where K
node = tree.root
prev = nothing
while node != nothing && node.data != d
... |
162 | 192 | DataStructures.jl | 4 | function insert_node(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = insert_node(node.leftChild, key)
else
node.rightChild = insert_node(node.rightChild, key)
end
node.subsize = compute_subtree_size(node)
node.height = compute_height(node)
balance = get... | function insert_node(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = insert_node(node.leftChild, key)
else
node.rightChild = insert_node(node.rightChild, key)
end
node.subsize = compute_subtree_size(node)
node.height = compute_height(node)
balance = get... | [
162,
192
] | function insert_node(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = insert_node(node.leftChild, key)
else
node.rightChild = insert_node(node.rightChild, key)
end
node.subsize = compute_subtree_size(node)
node.height = compute_height(node)
balance = get... | function insert_node(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = insert_node(node.leftChild, key)
else
node.rightChild = insert_node(node.rightChild, key)
end
node.subsize = compute_subtree_size(node)
node.height = compute_height(node)
balance = get... | insert_node | 162 | 192 | src/avl_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
"""
function right_rotate!(tree::RBTree, node_x::RBTreeNode)
node_y = node_x.leftChild
node_x.leftChild = node_y.rightChild
if node_y.rightChild !== tree.nil
node_y.rightChild.parent = node_x
end
node_y.parent = node_x.parent
if (n... |
212 | 254 | DataStructures.jl | 5 | function delete_node!(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = delete_node!(node.leftChild, key)
elseif key > node.data
node.rightChild = delete_node!(node.rightChild, key)
else
if node.leftChild == nothing
result = node.rightChild
... | function delete_node!(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = delete_node!(node.leftChild, key)
elseif key > node.data
node.rightChild = delete_node!(node.rightChild, key)
else
if node.leftChild == nothing
result = node.rightChild
... | [
212,
254
] | function delete_node!(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = delete_node!(node.leftChild, key)
elseif key > node.data
node.rightChild = delete_node!(node.rightChild, key)
else
if node.leftChild == nothing
result = node.rightChild
... | function delete_node!(node::AVLTreeNode{K}, key::K) where K
if key < node.data
node.leftChild = delete_node!(node.leftChild, key)
elseif key > node.data
node.rightChild = delete_node!(node.rightChild, key)
else
if node.leftChild == nothing
result = node.rightChild
... | delete_node! | 212 | 254 | src/avl_tree.jl | #FILE: DataStructures.jl/src/splay_tree.jl
##CHUNK 1
# double rotation
elseif node_x == parent.leftChild && parent == grand_parent.leftChild
# zig-zig rotation
right_rotate!(tree, grand_parent)
right_rotate!(tree, parent)
elseif node_x == parent.rightChild... |
290 | 304 | DataStructures.jl | 6 | function sorted_rank(tree::AVLTree{K}, key::K) where K
!haskey(tree, key) && throw(KeyError(key))
node = tree.root
rank = 0
while node.data != key
if (node.data < key)
rank += (1 + get_subsize(node.leftChild))
node = node.rightChild
else
node = node.le... | function sorted_rank(tree::AVLTree{K}, key::K) where K
!haskey(tree, key) && throw(KeyError(key))
node = tree.root
rank = 0
while node.data != key
if (node.data < key)
rank += (1 + get_subsize(node.leftChild))
node = node.rightChild
else
node = node.le... | [
290,
304
] | function sorted_rank(tree::AVLTree{K}, key::K) where K
!haskey(tree, key) && throw(KeyError(key))
node = tree.root
rank = 0
while node.data != key
if (node.data < key)
rank += (1 + get_subsize(node.leftChild))
node = node.rightChild
else
node = node.le... | function sorted_rank(tree::AVLTree{K}, key::K) where K
!haskey(tree, key) && throw(KeyError(key))
node = tree.root
rank = 0
while node.data != key
if (node.data < key)
rank += (1 + get_subsize(node.leftChild))
node = node.rightChild
else
node = node.le... | sorted_rank | 290 | 304 | src/avl_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
"""
search_node(tree, key)
function search_node(tree::RBTree{K}, d::K) where K
node = tree.root
while node !== tree.nil && d != node.data
if d < node.data
node = node.leftChild
else
node = node.rightChild
e... |
329 | 345 | DataStructures.jl | 7 | function Base.getindex(tree::AVLTree{K}, ind::Integer) where K
@boundscheck (1 <= ind <= tree.count) || throw(BoundsError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree(node::AVLTreeNode_or_null, idx)
if (node != nothing)
L = get_subsize(node.leftChild)
... | function Base.getindex(tree::AVLTree{K}, ind::Integer) where K
@boundscheck (1 <= ind <= tree.count) || throw(BoundsError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree(node::AVLTreeNode_or_null, idx)
if (node != nothing)
L = get_subsize(node.leftChild)
... | [
329,
345
] | function Base.getindex(tree::AVLTree{K}, ind::Integer) where K
@boundscheck (1 <= ind <= tree.count) || throw(BoundsError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree(node::AVLTreeNode_or_null, idx)
if (node != nothing)
L = get_subsize(node.leftChild)
... | function Base.getindex(tree::AVLTree{K}, ind::Integer) where K
@boundscheck (1 <= ind <= tree.count) || throw(BoundsError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree(node::AVLTreeNode_or_null, idx)
if (node != nothing)
L = get_subsize(node.leftChild)
... | traverse_tree | 329 | 345 | src/avl_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
Base.in(key, tree::RBTree) = haskey(tree, key)
"""
getindex(tree, ind)
Gets the key present at index `ind` of the tree. Indexing is done in increasing order of key.
"""
function Base.getindex(tree::RBTree{K}, ind) where K
@boundscheck (1 <= ind <= tree... |
238 | 250 | DataStructures.jl | 8 | function Base.empty!(t::BalancedTree23)
resize!(t.data,2)
initializeData!(t.data)
resize!(t.tree,1)
initializeTree!(t.tree)
t.depth = 1
t.rootloc = 1
empty!(t.freetreeinds)
empty!(t.freedatainds)
empty!(t.useddatacells)
push!(t.useddatacells, 1, 2)
return nothing
end | function Base.empty!(t::BalancedTree23)
resize!(t.data,2)
initializeData!(t.data)
resize!(t.tree,1)
initializeTree!(t.tree)
t.depth = 1
t.rootloc = 1
empty!(t.freetreeinds)
empty!(t.freedatainds)
empty!(t.useddatacells)
push!(t.useddatacells, 1, 2)
return nothing
end | [
238,
250
] | function Base.empty!(t::BalancedTree23)
resize!(t.data,2)
initializeData!(t.data)
resize!(t.tree,1)
initializeTree!(t.tree)
t.depth = 1
t.rootloc = 1
empty!(t.freetreeinds)
empty!(t.freedatainds)
empty!(t.useddatacells)
push!(t.useddatacells, 1, 2)
return nothing
end | function Base.empty!(t::BalancedTree23)
resize!(t.data,2)
initializeData!(t.data)
resize!(t.tree,1)
initializeTree!(t.tree)
t.depth = 1
t.rootloc = 1
empty!(t.freetreeinds)
empty!(t.freedatainds)
empty!(t.useddatacells)
push!(t.useddatacells, 1, 2)
return nothing
end | Base.empty! | 238 | 250 | src/balanced_tree.jl | #FILE: DataStructures.jl/test/test_sorted_containers.jl
##CHUNK 1
end
remove_spaces(s::String) = replace(s, r"\s+"=>"")
## Function checkcorrectness checks a balanced tree for correctness.
function checkcorrectness(t::DataStructures.BalancedTree23{K,D,Ord},
allowdups=false) where {K,D,O... |
292 | 309 | DataStructures.jl | 9 | function findkeyless(t::BalancedTree23, k)
curnode = t.rootloc
for depthcount = 1 : t.depth - 1
@inbounds thisnode = t.tree[curnode]
cmp = thisnode.child3 == 0 ?
cmp2le_nonleaf(t.ord, thisnode, k) :
cmp3le_nonleaf(t.ord, thisnode, k)
curnode = cmp == 1 ? thi... | function findkeyless(t::BalancedTree23, k)
curnode = t.rootloc
for depthcount = 1 : t.depth - 1
@inbounds thisnode = t.tree[curnode]
cmp = thisnode.child3 == 0 ?
cmp2le_nonleaf(t.ord, thisnode, k) :
cmp3le_nonleaf(t.ord, thisnode, k)
curnode = cmp == 1 ? thi... | [
292,
309
] | function findkeyless(t::BalancedTree23, k)
curnode = t.rootloc
for depthcount = 1 : t.depth - 1
@inbounds thisnode = t.tree[curnode]
cmp = thisnode.child3 == 0 ?
cmp2le_nonleaf(t.ord, thisnode, k) :
cmp3le_nonleaf(t.ord, thisnode, k)
curnode = cmp == 1 ? thi... | function findkeyless(t::BalancedTree23, k)
curnode = t.rootloc
for depthcount = 1 : t.depth - 1
@inbounds thisnode = t.tree[curnode]
cmp = thisnode.child3 == 0 ?
cmp2le_nonleaf(t.ord, thisnode, k) :
cmp3le_nonleaf(t.ord, thisnode, k)
curnode = cmp == 1 ? thi... | findkeyless | 292 | 309 | src/balanced_tree.jl | #FILE: DataStructures.jl/test/test_sorted_containers.jl
##CHUNK 1
mk2 = minkeys[cp]
cp += 1
if t.tree[c2].parent != anc
throw(ErrorException("Parent/child2 links do not match"))
end
c3 = t.tree[anc].child3
my_assert(s == levstart[cu... |
358 | 520 | DataStructures.jl | 10 | function Base.insert!(t::BalancedTree23{K,D,Ord}, k, d, allowdups::Bool) where {K,D,Ord <: Ordering}
## First we find the greatest data node that is <= k.
leafind, exactfound = findkey(t, k)
parent = t.data[leafind].parent
## The following code is necessary because in the case of a
## brand new tr... | function Base.insert!(t::BalancedTree23{K,D,Ord}, k, d, allowdups::Bool) where {K,D,Ord <: Ordering}
## First we find the greatest data node that is <= k.
leafind, exactfound = findkey(t, k)
parent = t.data[leafind].parent
## The following code is necessary because in the case of a
## brand new tr... | [
358,
520
] | function Base.insert!(t::BalancedTree23{K,D,Ord}, k, d, allowdups::Bool) where {K,D,Ord <: Ordering}
## First we find the greatest data node that is <= k.
leafind, exactfound = findkey(t, k)
parent = t.data[leafind].parent
## The following code is necessary because in the case of a
## brand new tr... | function Base.insert!(t::BalancedTree23{K,D,Ord}, k, d, allowdups::Bool) where {K,D,Ord <: Ordering}
## First we find the greatest data node that is <= k.
leafind, exactfound = findkey(t, k)
parent = t.data[leafind].parent
## The following code is necessary because in the case of a
## brand new tr... | size | 358 | 520 | src/balanced_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
function Base.insert!(tree::RBTree{K}, d::K) where K
# if the key exists in the tree, no need to insert
haskey(tree, d) && return tree
# insert, if not present in the tree
node = RBTreeNode{K}(d)
node.leftChild = node.rightChild = tree.nil
... |
655 | 984 | DataStructures.jl | 11 | function Base.delete!(t::BalancedTree23{K,D,Ord}, it::Int) where {K,D,Ord<:Ordering}
## Put the cell indexed by 'it' into the deletion list.
##
## Create the following data items maintained in the
## upcoming loop.
##
## p is a tree-node ancestor of the deleted node
## The children of p are... | function Base.delete!(t::BalancedTree23{K,D,Ord}, it::Int) where {K,D,Ord<:Ordering}
## Put the cell indexed by 'it' into the deletion list.
##
## Create the following data items maintained in the
## upcoming loop.
##
## p is a tree-node ancestor of the deleted node
## The children of p are... | [
655,
984
] | function Base.delete!(t::BalancedTree23{K,D,Ord}, it::Int) where {K,D,Ord<:Ordering}
## Put the cell indexed by 'it' into the deletion list.
##
## Create the following data items maintained in the
## upcoming loop.
##
## p is a tree-node ancestor of the deleted node
## The children of p are... | function Base.delete!(t::BalancedTree23{K,D,Ord}, it::Int) where {K,D,Ord<:Ordering}
## Put the cell indexed by 'it' into the deletion list.
##
## Create the following data items maintained in the
## upcoming loop.
##
## p is a tree-node ancestor of the deleted node
## The children of p are... | Base.delete! | 655 | 984 | src/balanced_tree.jl | #CURRENT FILE: DataStructures.jl/src/balanced_tree.jl
##CHUNK 1
end
@inbounds thisnode = t.tree[curnode]
cmp = thisnode.child3 == 0 ?
cmp2le_leaf(t.ord, thisnode, k) :
cmp3le_leaf(t.ord, thisnode, k)
curnode = cmp == 1 ? thisnode.child1 :
cmp == 2 ? thisnode.child2 ... |
243 | 257 | DataStructures.jl | 12 | function Base.resize!(cb::CircularBuffer, n::Integer)
if n != capacity(cb)
buf_new = Vector{eltype(cb)}(undef, n)
len_new = min(length(cb), n)
for i in 1:len_new
@inbounds buf_new[i] = cb[i]
end
cb.capacity = n
cb.first = 1
cb.length = len_new
... | function Base.resize!(cb::CircularBuffer, n::Integer)
if n != capacity(cb)
buf_new = Vector{eltype(cb)}(undef, n)
len_new = min(length(cb), n)
for i in 1:len_new
@inbounds buf_new[i] = cb[i]
end
cb.capacity = n
cb.first = 1
cb.length = len_new
... | [
243,
257
] | function Base.resize!(cb::CircularBuffer, n::Integer)
if n != capacity(cb)
buf_new = Vector{eltype(cb)}(undef, n)
len_new = min(length(cb), n)
for i in 1:len_new
@inbounds buf_new[i] = cb[i]
end
cb.capacity = n
cb.first = 1
cb.length = len_new
... | function Base.resize!(cb::CircularBuffer, n::Integer)
if n != capacity(cb)
buf_new = Vector{eltype(cb)}(undef, n)
len_new = min(length(cb), n)
for i in 1:len_new
@inbounds buf_new[i] = cb[i]
end
cb.capacity = n
cb.first = 1
cb.length = len_new
... | Base.resize! | 243 | 257 | src/circular_buffer.jl | #FILE: DataStructures.jl/src/circ_deque.jl
##CHUNK 1
Create a double-ended queue of maximum capacity `n`, implemented as a circular buffer. The element type is `T`.
"""
CircularDeque{T}(n::Int) where {T} = CircularDeque(Vector{T}(undef, n), n, 0, 1, n)
CircularDeque{T}(n::Integer) where {T} = CircularDeque(Vector{T}(u... |
141 | 152 | DataStructures.jl | 13 | function Base.iterate(di::DequeIterator{T}, (cb, i) = (di.d.head, di.d.head.front)) where T
i > cb.back && return nothing
x = cb.data[i]
i += 1
if i > cb.back && !isrear(cb)
cb = cb.next
i = 1
end
return (x, (cb, i))
end | function Base.iterate(di::DequeIterator{T}, (cb, i) = (di.d.head, di.d.head.front)) where T
i > cb.back && return nothing
x = cb.data[i]
i += 1
if i > cb.back && !isrear(cb)
cb = cb.next
i = 1
end
return (x, (cb, i))
end | [
141,
152
] | function Base.iterate(di::DequeIterator{T}, (cb, i) = (di.d.head, di.d.head.front)) where T
i > cb.back && return nothing
x = cb.data[i]
i += 1
if i > cb.back && !isrear(cb)
cb = cb.next
i = 1
end
return (x, (cb, i))
end | function Base.iterate(di::DequeIterator{T}, (cb, i) = (di.d.head, di.d.head.front)) where T
i > cb.back && return nothing
x = cb.data[i]
i += 1
if i > cb.back && !isrear(cb)
cb = cb.next
i = 1
end
return (x, (cb, i))
end | iterate | 141 | 152 | src/deque.jl | #FILE: DataStructures.jl/src/circ_deque.jl
##CHUNK 1
# getindex sans bounds checking
@inline function _unsafe_getindex(D::CircularDeque, i::Integer)
j = D.first + i - 1
if j > D.capacity
j -= D.capacity
end
@inbounds ret = D.buffer[j]
return ret
end
@inline function Base.getindex(D::Circul... |
156 | 168 | DataStructures.jl | 14 | function Base.iterate(di::Iterators.Reverse{<:Deque}, (cb, i) = (di.itr.rear, di.itr.rear.back))
i < cb.front && return nothing
x = cb.data[i]
i -= 1
# If we're past the beginning of a block, go to the previous one
if i < cb.front && !ishead(cb)
cb = cb.prev
i = cb.back
end
... | function Base.iterate(di::Iterators.Reverse{<:Deque}, (cb, i) = (di.itr.rear, di.itr.rear.back))
i < cb.front && return nothing
x = cb.data[i]
i -= 1
# If we're past the beginning of a block, go to the previous one
if i < cb.front && !ishead(cb)
cb = cb.prev
i = cb.back
end
... | [
156,
168
] | function Base.iterate(di::Iterators.Reverse{<:Deque}, (cb, i) = (di.itr.rear, di.itr.rear.back))
i < cb.front && return nothing
x = cb.data[i]
i -= 1
# If we're past the beginning of a block, go to the previous one
if i < cb.front && !ishead(cb)
cb = cb.prev
i = cb.back
end
... | function Base.iterate(di::Iterators.Reverse{<:Deque}, (cb, i) = (di.itr.rear, di.itr.rear.back))
i < cb.front && return nothing
x = cb.data[i]
i -= 1
# If we're past the beginning of a block, go to the previous one
if i < cb.front && !ishead(cb)
cb = cb.prev
i = cb.back
end
... | iterate | 156 | 168 | src/deque.jl | #CURRENT FILE: DataStructures.jl/src/deque.jl
##CHUNK 1
function Base.iterate(di::DequeIterator{T}, (cb, i) = (di.d.head, di.d.head.front)) where T
i > cb.back && return nothing
x = cb.data[i]
i += 1
if i > cb.back && !isrear(cb)
cb = cb.next
i = 1
end
return (x, (cb, i))
end
... |
212 | 230 | DataStructures.jl | 15 | function Base.empty!(d::Deque{T}) where T
# release all blocks except the head
if d.nblocks > 1
cb::DequeBlock{T} = d.rear
while cb != d.head
empty!(cb.data)
cb = cb.prev
end
end
# clean the head block (but retain the block itself)
reset!(d.head, 1)
... | function Base.empty!(d::Deque{T}) where T
# release all blocks except the head
if d.nblocks > 1
cb::DequeBlock{T} = d.rear
while cb != d.head
empty!(cb.data)
cb = cb.prev
end
end
# clean the head block (but retain the block itself)
reset!(d.head, 1)
... | [
212,
230
] | function Base.empty!(d::Deque{T}) where T
# release all blocks except the head
if d.nblocks > 1
cb::DequeBlock{T} = d.rear
while cb != d.head
empty!(cb.data)
cb = cb.prev
end
end
# clean the head block (but retain the block itself)
reset!(d.head, 1)
... | function Base.empty!(d::Deque{T}) where T
# release all blocks except the head
if d.nblocks > 1
cb::DequeBlock{T} = d.rear
while cb != d.head
empty!(cb.data)
cb = cb.prev
end
end
# clean the head block (but retain the block itself)
reset!(d.head, 1)
... | Base.empty! | 212 | 230 | src/deque.jl | #CURRENT FILE: DataStructures.jl/src/deque.jl
##CHUNK 1
function Base.popfirst!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
head = d.head
@assert head.back >= head.front
@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front) # see issue/8... |
238 | 258 | DataStructures.jl | 16 | function Base.push!(d::Deque{T}, x) where T
rear = d.rear
if isempty(rear)
rear.front = 1
rear.back = 0
end
if rear.back < rear.capa
@inbounds rear.data[rear.back += 1] = convert(T, x)
else
new_rear = rear_deque_block(T, d.blksize)
new_rear.back = 1
... | function Base.push!(d::Deque{T}, x) where T
rear = d.rear
if isempty(rear)
rear.front = 1
rear.back = 0
end
if rear.back < rear.capa
@inbounds rear.data[rear.back += 1] = convert(T, x)
else
new_rear = rear_deque_block(T, d.blksize)
new_rear.back = 1
... | [
238,
258
] | function Base.push!(d::Deque{T}, x) where T
rear = d.rear
if isempty(rear)
rear.front = 1
rear.back = 0
end
if rear.back < rear.capa
@inbounds rear.data[rear.back += 1] = convert(T, x)
else
new_rear = rear_deque_block(T, d.blksize)
new_rear.back = 1
... | function Base.push!(d::Deque{T}, x) where T
rear = d.rear
if isempty(rear)
rear.front = 1
rear.back = 0
end
if rear.back < rear.capa
@inbounds rear.data[rear.back += 1] = convert(T, x)
else
new_rear = rear_deque_block(T, d.blksize)
new_rear.back = 1
... | Base.push! | 238 | 258 | src/deque.jl | #CURRENT FILE: DataStructures.jl/src/deque.jl
##CHUNK 1
Remove the element at the back of deque `d`.
"""
function Base.pop!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
rear = d.rear
@assert rear.back >= rear.front
@inbounds x = rear.data[rear.back]
Base._unset... |
265 | 287 | DataStructures.jl | 17 | function Base.pushfirst!(d::Deque{T}, x) where T
head = d.head
if isempty(head)
n = head.capa
head.front = n + 1
head.back = n
end
if head.front > 1
@inbounds head.data[head.front -= 1] = convert(T, x)
else
n::Int = d.blksize
new_head = head_deque_bl... | function Base.pushfirst!(d::Deque{T}, x) where T
head = d.head
if isempty(head)
n = head.capa
head.front = n + 1
head.back = n
end
if head.front > 1
@inbounds head.data[head.front -= 1] = convert(T, x)
else
n::Int = d.blksize
new_head = head_deque_bl... | [
265,
287
] | function Base.pushfirst!(d::Deque{T}, x) where T
head = d.head
if isempty(head)
n = head.capa
head.front = n + 1
head.back = n
end
if head.front > 1
@inbounds head.data[head.front -= 1] = convert(T, x)
else
n::Int = d.blksize
new_head = head_deque_bl... | function Base.pushfirst!(d::Deque{T}, x) where T
head = d.head
if isempty(head)
n = head.capa
head.front = n + 1
head.back = n
end
if head.front > 1
@inbounds head.data[head.front -= 1] = convert(T, x)
else
n::Int = d.blksize
new_head = head_deque_bl... | Base.pushfirst! | 265 | 287 | src/deque.jl | #FILE: DataStructures.jl/src/circ_deque.jl
##CHUNK 1
v
end
"""
pushfirst!(D::CircularDeque, v)
Add an element to the front.
"""
@inline function Base.pushfirst!(D::CircularDeque, v)
@boundscheck D.n < D.capacity || throw(BoundsError())
D.n += 1
tmp = D.first - 1
D.first = ifelse(tmp < 1, D.cap... |
294 | 313 | DataStructures.jl | 18 | function Base.pop!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
rear = d.rear
@assert rear.back >= rear.front
@inbounds x = rear.data[rear.back]
Base._unsetindex!(rear.data, rear.back) # see issue/884
rear.back -= 1
if rear.back < rear.front
if ... | function Base.pop!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
rear = d.rear
@assert rear.back >= rear.front
@inbounds x = rear.data[rear.back]
Base._unsetindex!(rear.data, rear.back) # see issue/884
rear.back -= 1
if rear.back < rear.front
if ... | [
294,
313
] | function Base.pop!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
rear = d.rear
@assert rear.back >= rear.front
@inbounds x = rear.data[rear.back]
Base._unsetindex!(rear.data, rear.back) # see issue/884
rear.back -= 1
if rear.back < rear.front
if ... | function Base.pop!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
rear = d.rear
@assert rear.back >= rear.front
@inbounds x = rear.data[rear.back]
Base._unsetindex!(rear.data, rear.back) # see issue/884
rear.back -= 1
if rear.back < rear.front
if ... | Base.pop! | 294 | 313 | src/deque.jl | #CURRENT FILE: DataStructures.jl/src/deque.jl
##CHUNK 1
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
head = d.head
@assert head.back >= head.front
@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front) # see issue/884
head.front += 1
if head.back < hea... |
320 | 339 | DataStructures.jl | 19 | function Base.popfirst!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
head = d.head
@assert head.back >= head.front
@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front) # see issue/884
head.front += 1
if head.back < head.front
... | function Base.popfirst!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
head = d.head
@assert head.back >= head.front
@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front) # see issue/884
head.front += 1
if head.back < head.front
... | [
320,
339
] | function Base.popfirst!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
head = d.head
@assert head.back >= head.front
@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front) # see issue/884
head.front += 1
if head.back < head.front
... | function Base.popfirst!(d::Deque{T}) where T
isempty(d) && throw(ArgumentError("Deque must be non-empty"))
head = d.head
@assert head.back >= head.front
@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front) # see issue/884
head.front += 1
if head.back < head.front
... | Base.popfirst! | 320 | 339 | src/deque.jl | #FILE: DataStructures.jl/src/circ_deque.jl
##CHUNK 1
D.n += 1
tmp = D.first - 1
D.first = ifelse(tmp < 1, D.capacity, tmp)
@inbounds D.buffer[D.first] = v
D
end
"""
popfirst!(D::CircularDeque)
Remove the element at the front.
"""
@inline Base.@propagate_inbounds function Base.popfirst!(D::Circ... |
15 | 27 | DataStructures.jl | 20 | function DiBitVector(n::Integer, v::Integer)
if Int(n) < 0
throw(ArgumentError("n ($n) must be greater than or equal to zero"))
end
if !(Int(v) in 0:3)
throw(ArgumentError("v ($v) must be in 0:3"))
end
fv = (0x0000000000000000, 0x5555555555555555,
... | function DiBitVector(n::Integer, v::Integer)
if Int(n) < 0
throw(ArgumentError("n ($n) must be greater than or equal to zero"))
end
if !(Int(v) in 0:3)
throw(ArgumentError("v ($v) must be in 0:3"))
end
fv = (0x0000000000000000, 0x5555555555555555,
... | [
15,
27
] | function DiBitVector(n::Integer, v::Integer)
if Int(n) < 0
throw(ArgumentError("n ($n) must be greater than or equal to zero"))
end
if !(Int(v) in 0:3)
throw(ArgumentError("v ($v) must be in 0:3"))
end
fv = (0x0000000000000000, 0x5555555555555555,
... | function DiBitVector(n::Integer, v::Integer)
if Int(n) < 0
throw(ArgumentError("n ($n) must be greater than or equal to zero"))
end
if !(Int(v) in 0:3)
throw(ArgumentError("v ($v) must be in 0:3"))
end
fv = (0x0000000000000000, 0x5555555555555555,
... | DiBitVector | 15 | 27 | src/dibit_vector.jl | #FILE: DataStructures.jl/src/int_set.jl
##CHUNK 1
idx = n+1
if 1 <= idx <= length(s.bits)
unsafe_getindex(s.bits, idx) != s.inverse
else
ifelse((idx <= 0) | (idx > typemax(Int)), false, s.inverse)
end
end
function findnextidx(s::IntSet, i::Int, invert=false)
if s.inverse ⊻ invert
... |
3 | 16 | DataStructures.jl | 21 | function not_iterator_of_pairs(kv::T) where T
# if the object is not iterable, return true, else check the eltype of the iteration
Base.isiterable(T) || return true
# else, check if we can check `eltype`:
if Base.IteratorEltype(kv) isa Base.HasEltype
typ = eltype(kv)
if !(typ == Any)
... | function not_iterator_of_pairs(kv::T) where T
# if the object is not iterable, return true, else check the eltype of the iteration
Base.isiterable(T) || return true
# else, check if we can check `eltype`:
if Base.IteratorEltype(kv) isa Base.HasEltype
typ = eltype(kv)
if !(typ == Any)
... | [
3,
16
] | function not_iterator_of_pairs(kv::T) where T
# if the object is not iterable, return true, else check the eltype of the iteration
Base.isiterable(T) || return true
# else, check if we can check `eltype`:
if Base.IteratorEltype(kv) isa Base.HasEltype
typ = eltype(kv)
if !(typ == Any)
... | function not_iterator_of_pairs(kv::T) where T
# if the object is not iterable, return true, else check the eltype of the iteration
Base.isiterable(T) || return true
# else, check if we can check `eltype`:
if Base.IteratorEltype(kv) isa Base.HasEltype
typ = eltype(kv)
if !(typ == Any)
... | not_iterator_of_pairs | 3 | 16 | src/dict_support.jl | #FILE: DataStructures.jl/test/test_priority_queue.jl
##CHUNK 1
x::T
end
Base.IteratorEltype(::EltypeUnknownIterator) = Base.EltypeUnknown()
Base.iterate(i::EltypeUnknownIterator) = Base.iterate(i.x)
Base.iterate(i::EltypeUnknownIterator... |
103 | 117 | DataStructures.jl | 22 | function root_union!(s::IntDisjointSet{T}, x::T, y::T) where {T<:Integer}
parents = s.parents
rks = s.ranks
@inbounds xrank = rks[x]
@inbounds yrank = rks[y]
if xrank < yrank
x, y = y, x
elseif xrank == yrank
rks[x] += one(T)
end
@inbounds parents[y] = x
s.ngroups -=... | function root_union!(s::IntDisjointSet{T}, x::T, y::T) where {T<:Integer}
parents = s.parents
rks = s.ranks
@inbounds xrank = rks[x]
@inbounds yrank = rks[y]
if xrank < yrank
x, y = y, x
elseif xrank == yrank
rks[x] += one(T)
end
@inbounds parents[y] = x
s.ngroups -=... | [
103,
117
] | function root_union!(s::IntDisjointSet{T}, x::T, y::T) where {T<:Integer}
parents = s.parents
rks = s.ranks
@inbounds xrank = rks[x]
@inbounds yrank = rks[y]
if xrank < yrank
x, y = y, x
elseif xrank == yrank
rks[x] += one(T)
end
@inbounds parents[y] = x
s.ngroups -=... | function root_union!(s::IntDisjointSet{T}, x::T, y::T) where {T<:Integer}
parents = s.parents
rks = s.ranks
@inbounds xrank = rks[x]
@inbounds yrank = rks[y]
if xrank < yrank
x, y = y, x
elseif xrank == yrank
rks[x] += one(T)
end
@inbounds parents[y] = x
s.ngroups -=... | root_union! | 103 | 117 | src/disjoint_set.jl | #CURRENT FILE: DataStructures.jl/src/disjoint_set.jl
##CHUNK 1
Assume `x ≠ y` (unsafe).
"""
"""
push!(s::IntDisjointSet{T})
Make a new subset with an automatically chosen new element `x`.
Returns the new element. Throw an `ArgumentError` if the
capacity of the set would be exceeded.
"""
function Base.push!(s::Int... |
150 | 162 | DataStructures.jl | 23 | function DisjointSet{T}(xs) where T # xs must be iterable
imap = Dict{T,Int}()
rmap = Vector{T}()
n = length(xs)::Int
sizehint!(imap, n)
sizehint!(rmap, n)
id = 0
for x in xs
imap[x] = (id += 1)
push!(rmap,x)
end
return n... | function DisjointSet{T}(xs) where T # xs must be iterable
imap = Dict{T,Int}()
rmap = Vector{T}()
n = length(xs)::Int
sizehint!(imap, n)
sizehint!(rmap, n)
id = 0
for x in xs
imap[x] = (id += 1)
push!(rmap,x)
end
return n... | [
150,
162
] | function DisjointSet{T}(xs) where T # xs must be iterable
imap = Dict{T,Int}()
rmap = Vector{T}()
n = length(xs)::Int
sizehint!(imap, n)
sizehint!(rmap, n)
id = 0
for x in xs
imap[x] = (id += 1)
push!(rmap,x)
end
return n... | function DisjointSet{T}(xs) where T # xs must be iterable
imap = Dict{T,Int}()
rmap = Vector{T}()
n = length(xs)::Int
sizehint!(imap, n)
sizehint!(rmap, n)
id = 0
for x in xs
imap[x] = (id += 1)
push!(rmap,x)
end
return n... | DisjointSet{T} | 150 | 162 | src/disjoint_set.jl | #CURRENT FILE: DataStructures.jl/src/disjoint_set.jl
##CHUNK 1
push!(s.ranks, zero(T))
s.ngroups += one(T)
return x
end
"""
DisjointSet{T}(xs)
A forest of disjoint sets of arbitrary value type `T`.
It is a wrapper of `IntDisjointSet{Int}`, which uses a
dictionary to map the input value to an internal... |
111 | 131 | DataStructures.jl | 24 | function nextreme(ord::Base.Ordering, n::Int, arr::AbstractVector{T}) where T
if n <= 0
return T[] # sort(arr)[1:n] returns [] for n <= 0
elseif n >= length(arr)
return sort(arr, order = ord)
end
rev = Base.ReverseOrdering(ord)
buffer = heapify(arr[1:n], rev)
for i = n + 1 : l... | function nextreme(ord::Base.Ordering, n::Int, arr::AbstractVector{T}) where T
if n <= 0
return T[] # sort(arr)[1:n] returns [] for n <= 0
elseif n >= length(arr)
return sort(arr, order = ord)
end
rev = Base.ReverseOrdering(ord)
buffer = heapify(arr[1:n], rev)
for i = n + 1 : l... | [
111,
131
] | function nextreme(ord::Base.Ordering, n::Int, arr::AbstractVector{T}) where T
if n <= 0
return T[] # sort(arr)[1:n] returns [] for n <= 0
elseif n >= length(arr)
return sort(arr, order = ord)
end
rev = Base.ReverseOrdering(ord)
buffer = heapify(arr[1:n], rev)
for i = n + 1 : l... | function nextreme(ord::Base.Ordering, n::Int, arr::AbstractVector{T}) where T
if n <= 0
return T[] # sort(arr)[1:n] returns [] for n <= 0
elseif n >= length(arr)
return sort(arr, order = ord)
end
rev = Base.ReverseOrdering(ord)
buffer = heapify(arr[1:n], rev)
for i = n + 1 : l... | nextreme | 111 | 131 | src/heaps.jl | #FILE: DataStructures.jl/src/heaps/arrays_as_heaps.jl
##CHUNK 1
j = r > len || lt(o, xs[l], xs[r]) ? l : r
lt(o, xs[j], x) || break
xs[i] = xs[j]
i = j
end
xs[i] = x
end
percolate_down!(xs::AbstractArray, i::Integer, o::Ordering, len::Integer=length(xs)) = percolate_down!(xs, i,... |
159 | 169 | DataStructures.jl | 25 | function findnextidx(s::IntSet, i::Int, invert=false)
if s.inverse ⊻ invert
# i+1 could rollover causing a BoundsError in findnext/findnextnot
nextidx = i == typemax(Int) ? 0 : something(findnextnot(s.bits, i+1), 0)
# Extend indices beyond the length of the bits since it is inverted
... | function findnextidx(s::IntSet, i::Int, invert=false)
if s.inverse ⊻ invert
# i+1 could rollover causing a BoundsError in findnext/findnextnot
nextidx = i == typemax(Int) ? 0 : something(findnextnot(s.bits, i+1), 0)
# Extend indices beyond the length of the bits since it is inverted
... | [
159,
169
] | function findnextidx(s::IntSet, i::Int, invert=false)
if s.inverse ⊻ invert
# i+1 could rollover causing a BoundsError in findnext/findnextnot
nextidx = i == typemax(Int) ? 0 : something(findnextnot(s.bits, i+1), 0)
# Extend indices beyond the length of the bits since it is inverted
... | function findnextidx(s::IntSet, i::Int, invert=false)
if s.inverse ⊻ invert
# i+1 could rollover causing a BoundsError in findnext/findnextnot
nextidx = i == typemax(Int) ? 0 : something(findnextnot(s.bits, i+1), 0)
# Extend indices beyond the length of the bits since it is inverted
... | findnextidx | 159 | 169 | src/int_set.jl | #FILE: DataStructures.jl/src/robin_dict.jl
##CHUNK 1
# this assumes that there is a key/value present in the dictionary at index
index0 = index
sz = length(h.keys)
@inbounds while true
index0 = (index0 & (sz - 1)) + 1
if isslotempty(h, index0) || calculate_distance(h, index0) == 0
... |
64 | 76 | DataStructures.jl | 26 | function Base.pop!(d::MultiDict, key, default)
vs = get(d, key, Base.secret_table_token)
if vs === Base.secret_table_token
if default !== Base.secret_table_token
return default
else
throw(KeyError(key))
end
end
v = pop!(vs)
(length(vs) == 0) && delete!... | function Base.pop!(d::MultiDict, key, default)
vs = get(d, key, Base.secret_table_token)
if vs === Base.secret_table_token
if default !== Base.secret_table_token
return default
else
throw(KeyError(key))
end
end
v = pop!(vs)
(length(vs) == 0) && delete!... | [
64,
76
] | function Base.pop!(d::MultiDict, key, default)
vs = get(d, key, Base.secret_table_token)
if vs === Base.secret_table_token
if default !== Base.secret_table_token
return default
else
throw(KeyError(key))
end
end
v = pop!(vs)
(length(vs) == 0) && delete!... | function Base.pop!(d::MultiDict, key, default)
vs = get(d, key, Base.secret_table_token)
if vs === Base.secret_table_token
if default !== Base.secret_table_token
return default
else
throw(KeyError(key))
end
end
v = pop!(vs)
(length(vs) == 0) && delete!... | length | 64 | 76 | src/multi_dict.jl | #FILE: DataStructures.jl/src/sorted_dict.jl
##CHUNK 1
Returns `sc`. This is a no-op if `k` is not present in `sd`.
Time: O(*c* log *n*)
"""
@inline function Base.delete!(m::SortedDict, k_)
i, exactfound = findkey(m.bt, convert(keytype(m), k_))
if exactfound
delete!(m.bt, i)
end
m
end
"""
... |
98 | 112 | DataStructures.jl | 27 | function Base.iterate(e::EnumerateAll)
V = eltype(eltype(values(e.d)))
vs = V[]
dstate = iterate(e.d.d)
vstate = iterate(vs)
dstate === nothing || vstate === nothing && return nothing
k = nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
... | function Base.iterate(e::EnumerateAll)
V = eltype(eltype(values(e.d)))
vs = V[]
dstate = iterate(e.d.d)
vstate = iterate(vs)
dstate === nothing || vstate === nothing && return nothing
k = nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
... | [
98,
112
] | function Base.iterate(e::EnumerateAll)
V = eltype(eltype(values(e.d)))
vs = V[]
dstate = iterate(e.d.d)
vstate = iterate(vs)
dstate === nothing || vstate === nothing && return nothing
k = nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
... | function Base.iterate(e::EnumerateAll)
V = eltype(eltype(values(e.d)))
vs = V[]
dstate = iterate(e.d.d)
vstate = iterate(vs)
dstate === nothing || vstate === nothing && return nothing
k = nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
... | Base.iterate | 98 | 112 | src/multi_dict.jl | #FILE: DataStructures.jl/src/sorted_dict.jl
##CHUNK 1
end
end
foundsemitoken = state[foundi]
for i = firsti : N
@inbounds if state[i] != pastendsemitoken(sds.vec[i]) &&
eq(ord, deref_key((sds.vec[i], state[i])), firstk)
state[i] = advance((sds.vec[i], state[i]))
... |
114 | 124 | DataStructures.jl | 28 | function Base.iterate(e::EnumerateAll, s)
dstate, k, vs, vstate = s
dstate === nothing || vstate === nothing && return nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
vstate = iterate(vs)
end
v, vst = vstate
return ((k, v), (dstate, k... | function Base.iterate(e::EnumerateAll, s)
dstate, k, vs, vstate = s
dstate === nothing || vstate === nothing && return nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
vstate = iterate(vs)
end
v, vst = vstate
return ((k, v), (dstate, k... | [
114,
124
] | function Base.iterate(e::EnumerateAll, s)
dstate, k, vs, vstate = s
dstate === nothing || vstate === nothing && return nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
vstate = iterate(vs)
end
v, vst = vstate
return ((k, v), (dstate, k... | function Base.iterate(e::EnumerateAll, s)
dstate, k, vs, vstate = s
dstate === nothing || vstate === nothing && return nothing
while vstate === nothing
((k, vs), dst) = dstate
dstate = iterate(e.d.d, dst)
vstate = iterate(vs)
end
v, vst = vstate
return ((k, v), (dstate, k... | Base.iterate | 114 | 124 | src/multi_dict.jl | #FILE: DataStructures.jl/src/sorted_dict.jl
##CHUNK 1
end
end
foundsemitoken = state[foundi]
for i = firsti : N
@inbounds if state[i] != pastendsemitoken(sds.vec[i]) &&
eq(ord, deref_key((sds.vec[i], state[i])), firstk)
state[i] = advance((sds.vec[i], state[i]))
... |
127 | 141 | DataStructures.jl | 29 | function Base.getindex(l::MutableLinkedList{T}, r::UnitRange) where T
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
l2 = MutableLinkedList{T}()
node = l.node
for i in 1:first(r)
node = node.next
end
len = length(r)
for j in 1:len
push!(l2, node.data... | function Base.getindex(l::MutableLinkedList{T}, r::UnitRange) where T
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
l2 = MutableLinkedList{T}()
node = l.node
for i in 1:first(r)
node = node.next
end
len = length(r)
for j in 1:len
push!(l2, node.data... | [
127,
141
] | function Base.getindex(l::MutableLinkedList{T}, r::UnitRange) where T
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
l2 = MutableLinkedList{T}()
node = l.node
for i in 1:first(r)
node = node.next
end
len = length(r)
for j in 1:len
push!(l2, node.data... | function Base.getindex(l::MutableLinkedList{T}, r::UnitRange) where T
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
l2 = MutableLinkedList{T}()
node = l.node
for i in 1:first(r)
node = node.next
end
len = length(r)
for j in 1:len
push!(l2, node.data... | Base.getindex | 127 | 141 | src/mutable_list.jl | #CURRENT FILE: DataStructures.jl/src/mutable_list.jl
##CHUNK 1
l2 = MutableLinkedList{T}()
for h in l
push!(l2, h)
end
return l2
end
function Base.getindex(l::MutableLinkedList, idx::Int)
@boundscheck 0 < idx <= l.len || throw(BoundsError(l, idx))
node = l.node
for i in 1:idx
... |
153 | 164 | DataStructures.jl | 30 | function Base.append!(l1::MutableLinkedList{T}, l2::MutableLinkedList{T}) where T
l1.node.prev.next = l2.node.next # l1's last's next is now l2's first
l2.node.prev.next = l1.node # l2's last's next is now l1.node
l2.node.next.prev = l1.node.prev # l2's first's prev is now l1's last
l1.node.prev = ... | function Base.append!(l1::MutableLinkedList{T}, l2::MutableLinkedList{T}) where T
l1.node.prev.next = l2.node.next # l1's last's next is now l2's first
l2.node.prev.next = l1.node # l2's last's next is now l1.node
l2.node.next.prev = l1.node.prev # l2's first's prev is now l1's last
l1.node.prev = ... | [
153,
164
] | function Base.append!(l1::MutableLinkedList{T}, l2::MutableLinkedList{T}) where T
l1.node.prev.next = l2.node.next # l1's last's next is now l2's first
l2.node.prev.next = l1.node # l2's last's next is now l1.node
l2.node.next.prev = l1.node.prev # l2's first's prev is now l1's last
l1.node.prev = ... | function Base.append!(l1::MutableLinkedList{T}, l2::MutableLinkedList{T}) where T
l1.node.prev.next = l2.node.next # l1's last's next is now l2's first
l2.node.prev.next = l1.node # l2's last's next is now l1.node
l2.node.next.prev = l1.node.prev # l2's first's prev is now l1's last
l1.node.prev = ... | Base.append! | 153 | 164 | src/mutable_list.jl | #FILE: DataStructures.jl/test/test_mutable_list.jl
##CHUNK 1
l = MutableLinkedList{Int}()
@testset "push back" begin
for i = 1:n
push!(l, i)
@test last(l) == i
if i > 4
@test getindex(l, i) == i
... |
175 | 187 | DataStructures.jl | 31 | function Base.delete!(l::MutableLinkedList, idx::Int)
@boundscheck 0 < idx <= l.len || throw(BoundsError(l, idx))
node = l.node
for i = 1:idx
node = node.next
end
prev = node.prev
next = node.next
prev.next = next
next.prev = prev
l.len -= 1
return l
end | function Base.delete!(l::MutableLinkedList, idx::Int)
@boundscheck 0 < idx <= l.len || throw(BoundsError(l, idx))
node = l.node
for i = 1:idx
node = node.next
end
prev = node.prev
next = node.next
prev.next = next
next.prev = prev
l.len -= 1
return l
end | [
175,
187
] | function Base.delete!(l::MutableLinkedList, idx::Int)
@boundscheck 0 < idx <= l.len || throw(BoundsError(l, idx))
node = l.node
for i = 1:idx
node = node.next
end
prev = node.prev
next = node.next
prev.next = next
next.prev = prev
l.len -= 1
return l
end | function Base.delete!(l::MutableLinkedList, idx::Int)
@boundscheck 0 < idx <= l.len || throw(BoundsError(l, idx))
node = l.node
for i = 1:idx
node = node.next
end
prev = node.prev
next = node.next
prev.next = next
next.prev = prev
l.len -= 1
return l
end | Base.delete! | 175 | 187 | src/mutable_list.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
node = node.leftChild
end
return node
end
"""
delete!(tree::RBTree, key)
Deletes `key` from `tree`, if present, else returns the unmodified tree.
"""
function Base.delete!(tree::RBTree{K}, d::K) where K
z = tree.nil
node = tree.root
... |
189 | 205 | DataStructures.jl | 32 | function Base.delete!(l::MutableLinkedList, r::UnitRange)
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
node = l.node
for i in 1:first(r)
node = node.next
end
prev = node.prev
len = length(r)
for j in 1:len
node = node.next
end
next = node
... | function Base.delete!(l::MutableLinkedList, r::UnitRange)
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
node = l.node
for i in 1:first(r)
node = node.next
end
prev = node.prev
len = length(r)
for j in 1:len
node = node.next
end
next = node
... | [
189,
205
] | function Base.delete!(l::MutableLinkedList, r::UnitRange)
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
node = l.node
for i in 1:first(r)
node = node.next
end
prev = node.prev
len = length(r)
for j in 1:len
node = node.next
end
next = node
... | function Base.delete!(l::MutableLinkedList, r::UnitRange)
@boundscheck 0 < first(r) < last(r) <= l.len || throw(BoundsError(l, r))
node = l.node
for i in 1:first(r)
node = node.next
end
prev = node.prev
len = length(r)
for j in 1:len
node = node.next
end
next = node
... | Base.delete! | 189 | 205 | src/mutable_list.jl | #CURRENT FILE: DataStructures.jl/src/mutable_list.jl
##CHUNK 1
end
return l
end
function Base.delete!(l::MutableLinkedList, idx::Int)
@boundscheck 0 < idx <= l.len || throw(BoundsError(l, idx))
node = l.node
for i = 1:idx
node = node.next
end
prev = node.prev
next = node.next
... |
125 | 141 | DataStructures.jl | 33 | function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
key = convert(K, key0)
v = convert(V, v0)
index = get(h.dict, key, -2)
if index < 0
_setindex!(h, v0, key0)
else
@assert haskey(h, key0)
@inbounds orig_v = h.vals[index]
!isequal(orig_v, v0) && ... | function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
key = convert(K, key0)
v = convert(V, v0)
index = get(h.dict, key, -2)
if index < 0
_setindex!(h, v0, key0)
else
@assert haskey(h, key0)
@inbounds orig_v = h.vals[index]
!isequal(orig_v, v0) && ... | [
125,
141
] | function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
key = convert(K, key0)
v = convert(V, v0)
index = get(h.dict, key, -2)
if index < 0
_setindex!(h, v0, key0)
else
@assert haskey(h, key0)
@inbounds orig_v = h.vals[index]
!isequal(orig_v, v0) && ... | function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
key = convert(K, key0)
v = convert(V, v0)
index = get(h.dict, key, -2)
if index < 0
_setindex!(h, v0, key0)
else
@assert haskey(h, key0)
@inbounds orig_v = h.vals[index]
!isequal(orig_v, v0) && ... | Base.setindex! | 125 | 141 | src/ordered_robin_dict.jl | #FILE: DataStructures.jl/src/swiss_dict.jl
##CHUNK 1
return h
end
function Base.setindex!(h::SwissDict{K,V}, v0, key0) where {K, V}
key = convert(K, key0)
_setindex!(h, v0, key)
end
function _setindex!(h::SwissDict{K,V}, v0, key::K) where {K, V}
v = convert(V, v0)
index, tag = ht_keyindex2!(h, key... |
151 | 171 | DataStructures.jl | 34 | function rehash!(h::OrderedRobinDict{K, V}) where {K, V}
keys = h.keys
vals = h.vals
hk = Vector{K}()
hv = Vector{V}()
for (idx, (k, v)) in enumerate(zip(keys, vals))
if get(h.dict, k, -1) == idx
push!(hk, k)
push!(hv, v)
end
end
h.keys = hk
h.va... | function rehash!(h::OrderedRobinDict{K, V}) where {K, V}
keys = h.keys
vals = h.vals
hk = Vector{K}()
hv = Vector{V}()
for (idx, (k, v)) in enumerate(zip(keys, vals))
if get(h.dict, k, -1) == idx
push!(hk, k)
push!(hv, v)
end
end
h.keys = hk
h.va... | [
151,
171
] | function rehash!(h::OrderedRobinDict{K, V}) where {K, V}
keys = h.keys
vals = h.vals
hk = Vector{K}()
hv = Vector{V}()
for (idx, (k, v)) in enumerate(zip(keys, vals))
if get(h.dict, k, -1) == idx
push!(hk, k)
push!(hv, v)
end
end
h.keys = hk
h.va... | function rehash!(h::OrderedRobinDict{K, V}) where {K, V}
keys = h.keys
vals = h.vals
hk = Vector{K}()
hv = Vector{V}()
for (idx, (k, v)) in enumerate(zip(keys, vals))
if get(h.dict, k, -1) == idx
push!(hk, k)
push!(hv, v)
end
end
h.keys = hk
h.va... | rehash! | 151 | 171 | src/ordered_robin_dict.jl | #FILE: DataStructures.jl/src/robin_dict.jl
##CHUNK 1
RobinDict{String, Int64}()
```
"""
function Base.empty!(h::RobinDict{K,V}) where {K, V}
sz = length(h.keys)
empty!(h.hashes)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
resize!(h.hashes, sz)
fill!(h.hashes, 0)... |
173 | 183 | DataStructures.jl | 35 | function Base.sizehint!(d::OrderedRobinDict, newsz)
oldsz = length(d)
# grow at least 25%
if newsz < (oldsz*5)>>2
return d
end
sizehint!(d.keys, newsz)
sizehint!(d.vals, newsz)
sizehint!(d.dict, newsz)
return d
end | function Base.sizehint!(d::OrderedRobinDict, newsz)
oldsz = length(d)
# grow at least 25%
if newsz < (oldsz*5)>>2
return d
end
sizehint!(d.keys, newsz)
sizehint!(d.vals, newsz)
sizehint!(d.dict, newsz)
return d
end | [
173,
183
] | function Base.sizehint!(d::OrderedRobinDict, newsz)
oldsz = length(d)
# grow at least 25%
if newsz < (oldsz*5)>>2
return d
end
sizehint!(d.keys, newsz)
sizehint!(d.vals, newsz)
sizehint!(d.dict, newsz)
return d
end | function Base.sizehint!(d::OrderedRobinDict, newsz)
oldsz = length(d)
# grow at least 25%
if newsz < (oldsz*5)>>2
return d
end
sizehint!(d.keys, newsz)
sizehint!(d.vals, newsz)
sizehint!(d.dict, newsz)
return d
end | Base.sizehint! | 173 | 183 | src/ordered_robin_dict.jl | #FILE: DataStructures.jl/src/swiss_dict.jl
##CHUNK 1
sz = length(h.keys)
if h.count*4 < sz && sz > 16
rehash!(h, sz>>1)
end
end
function Base.sizehint!(d::SwissDict, newsz::Integer)
newsz = _tablesz(newsz*2) # *2 for keys and values in same array
oldsz = length(d.keys)
# grow at least 25%
... |
343 | 353 | DataStructures.jl | 36 | function Base.pop!(h::OrderedRobinDict)
check_for_rehash(h) && rehash!(h)
index = length(h.keys)
while (index > 0)
isslotfilled(h, index) && break
index -= 1
end
index == 0 && rehash!(h)
@inbounds key = h.keys[index]
return key => _pop!(h, index)
end | function Base.pop!(h::OrderedRobinDict)
check_for_rehash(h) && rehash!(h)
index = length(h.keys)
while (index > 0)
isslotfilled(h, index) && break
index -= 1
end
index == 0 && rehash!(h)
@inbounds key = h.keys[index]
return key => _pop!(h, index)
end | [
343,
353
] | function Base.pop!(h::OrderedRobinDict)
check_for_rehash(h) && rehash!(h)
index = length(h.keys)
while (index > 0)
isslotfilled(h, index) && break
index -= 1
end
index == 0 && rehash!(h)
@inbounds key = h.keys[index]
return key => _pop!(h, index)
end | function Base.pop!(h::OrderedRobinDict)
check_for_rehash(h) && rehash!(h)
index = length(h.keys)
while (index > 0)
isslotfilled(h, index) && break
index -= 1
end
index == 0 && rehash!(h)
@inbounds key = h.keys[index]
return key => _pop!(h, index)
end | Base.pop! | 343 | 353 | src/ordered_robin_dict.jl | #FILE: DataStructures.jl/src/robin_dict.jl
##CHUNK 1
```
"""
function Base.getkey(h::RobinDict{K,V}, key, default) where {K, V}
index = rh_search(h, key)
@inbounds return (index < 0) ? default : h.keys[index]::K
end
# backward shift deletion by not keeping any tombstones
function rh_delete!(h::RobinDict{K, V},... |
49 | 67 | DataStructures.jl | 37 | function PriorityQueue{K,V,O}(o::O, itr) where {K,V,O<:Ordering}
xs = Vector{Pair{K,V}}(undef, length(itr))
index = Dict{K, Int}()
for (i, (k, v)) in enumerate(itr)
xs[i] = Pair{K,V}(k, v)
if haskey(index, k)
throw(ArgumentError("PriorityQueue keys must be... | function PriorityQueue{K,V,O}(o::O, itr) where {K,V,O<:Ordering}
xs = Vector{Pair{K,V}}(undef, length(itr))
index = Dict{K, Int}()
for (i, (k, v)) in enumerate(itr)
xs[i] = Pair{K,V}(k, v)
if haskey(index, k)
throw(ArgumentError("PriorityQueue keys must be... | [
49,
67
] | function PriorityQueue{K,V,O}(o::O, itr) where {K,V,O<:Ordering}
xs = Vector{Pair{K,V}}(undef, length(itr))
index = Dict{K, Int}()
for (i, (k, v)) in enumerate(itr)
xs[i] = Pair{K,V}(k, v)
if haskey(index, k)
throw(ArgumentError("PriorityQueue keys must be... | function PriorityQueue{K,V,O}(o::O, itr) where {K,V,O<:Ordering}
xs = Vector{Pair{K,V}}(undef, length(itr))
index = Dict{K, Int}()
for (i, (k, v)) in enumerate(itr)
xs[i] = Pair{K,V}(k, v)
if haskey(index, k)
throw(ArgumentError("PriorityQueue keys must be... | PriorityQueue{K,V,O} | 49 | 67 | src/priorityqueue.jl | #CURRENT FILE: DataStructures.jl/src/priorityqueue.jl
##CHUNK 1
return default
else
return pq.xs[i].second
end
end
# Change the priority of an existing element, or enqueue it if it isn't present.
function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
i = get(pq.index, key,... |
237 | 251 | DataStructures.jl | 38 | function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
i = get(pq.index, key, 0)
if i != 0
@inbounds oldvalue = pq.xs[i].second
pq.xs[i] = Pair{K,V}(key, value)
if lt(pq.o, oldvalue, value)
percolate_down!(pq, i)
else
percolate_up!(pq, i)... | function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
i = get(pq.index, key, 0)
if i != 0
@inbounds oldvalue = pq.xs[i].second
pq.xs[i] = Pair{K,V}(key, value)
if lt(pq.o, oldvalue, value)
percolate_down!(pq, i)
else
percolate_up!(pq, i)... | [
237,
251
] | function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
i = get(pq.index, key, 0)
if i != 0
@inbounds oldvalue = pq.xs[i].second
pq.xs[i] = Pair{K,V}(key, value)
if lt(pq.o, oldvalue, value)
percolate_down!(pq, i)
else
percolate_up!(pq, i)... | function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
i = get(pq.index, key, 0)
if i != 0
@inbounds oldvalue = pq.xs[i].second
pq.xs[i] = Pair{K,V}(key, value)
if lt(pq.o, oldvalue, value)
percolate_down!(pq, i)
else
percolate_up!(pq, i)... | Base.setindex! | 237 | 251 | src/priorityqueue.jl | #CURRENT FILE: DataStructures.jl/src/priorityqueue.jl
##CHUNK 1
break
end
end
pq.index[x.first] = i
pq.xs[i] = x
end
function percolate_up!(pq::PriorityQueue, i::Integer)
x = pq.xs[i]
@inbounds while i > 1
j = heapparent(i)
xj = pq.xs[j]
if lt(pq.o, x.se... |
277 | 287 | DataStructures.jl | 39 | function Base.push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
key = pair.first
if haskey(pq, key)
throw(ArgumentError("PriorityQueue keys must be unique"))
end
push!(pq.xs, pair)
pq.index[key] = length(pq)
percolate_up!(pq, length(pq))
return pq
end | function Base.push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
key = pair.first
if haskey(pq, key)
throw(ArgumentError("PriorityQueue keys must be unique"))
end
push!(pq.xs, pair)
pq.index[key] = length(pq)
percolate_up!(pq, length(pq))
return pq
end | [
277,
287
] | function Base.push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
key = pair.first
if haskey(pq, key)
throw(ArgumentError("PriorityQueue keys must be unique"))
end
push!(pq.xs, pair)
pq.index[key] = length(pq)
percolate_up!(pq, length(pq))
return pq
end | function Base.push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
key = pair.first
if haskey(pq, key)
throw(ArgumentError("PriorityQueue keys must be unique"))
end
push!(pq.xs, pair)
pq.index[key] = length(pq)
percolate_up!(pq, length(pq))
return pq
end | Base.push! | 277 | 287 | src/priorityqueue.jl | #FILE: DataStructures.jl/test/test_priority_queue.jl
##CHUNK 1
ks, vs = 1:n, rand(1:pmax, n)
pq = PriorityQueue(zip(ks, vs))
@test_throws ArgumentError push!(pq, 1=>10)
end
@testset "Iteration" begin
pq = PriorityQueue(priorities)
pq2 = Priori... |
314 | 324 | DataStructures.jl | 40 | function Base.popfirst!(pq::PriorityQueue)
x = pq.xs[1]
y = pop!(pq.xs)
if !isempty(pq)
@inbounds pq.xs[1] = y
pq.index[y.first] = 1
percolate_down!(pq, 1)
end
delete!(pq.index, x.first)
return x
end | function Base.popfirst!(pq::PriorityQueue)
x = pq.xs[1]
y = pop!(pq.xs)
if !isempty(pq)
@inbounds pq.xs[1] = y
pq.index[y.first] = 1
percolate_down!(pq, 1)
end
delete!(pq.index, x.first)
return x
end | [
314,
324
] | function Base.popfirst!(pq::PriorityQueue)
x = pq.xs[1]
y = pop!(pq.xs)
if !isempty(pq)
@inbounds pq.xs[1] = y
pq.index[y.first] = 1
percolate_down!(pq, 1)
end
delete!(pq.index, x.first)
return x
end | function Base.popfirst!(pq::PriorityQueue)
x = pq.xs[1]
y = pop!(pq.xs)
if !isempty(pq)
@inbounds pq.xs[1] = y
pq.index[y.first] = 1
percolate_down!(pq, 1)
end
delete!(pq.index, x.first)
return x
end | Base.popfirst! | 314 | 324 | src/priorityqueue.jl | #FILE: DataStructures.jl/src/heaps/arrays_as_heaps.jl
##CHUNK 1
@inline percolate_up!(xs::AbstractArray, i::Integer, o::Ordering) = percolate_up!(xs, i, xs[i], o)
"""
heappop!(v, [ord])
Given a binary heap-ordered array, remove and return the lowest ordered element.
For efficiency, this function does not check t... |
54 | 64 | DataStructures.jl | 41 | function search_node(tree::RBTree{K}, d::K) where K
node = tree.root
while node !== tree.nil && d != node.data
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return node
end | function search_node(tree::RBTree{K}, d::K) where K
node = tree.root
while node !== tree.nil && d != node.data
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return node
end | [
54,
64
] | function search_node(tree::RBTree{K}, d::K) where K
node = tree.root
while node !== tree.nil && d != node.data
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return node
end | function search_node(tree::RBTree{K}, d::K) where K
node = tree.root
while node !== tree.nil && d != node.data
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
return node
end | search_node | 54 | 64 | src/red_black_tree.jl | #FILE: DataStructures.jl/src/avl_tree.jl
##CHUNK 1
return node
end
function search_node(tree::AVLTree{K}, d::K) where K
prev = nothing
node = tree.root
while node != nothing && node.data != nothing && node.data != d
prev = node
if d < node.data
node = node.leftChild
... |
211 | 230 | DataStructures.jl | 42 | function Base.insert!(tree::RBTree{K}, d::K) where K
# if the key exists in the tree, no need to insert
haskey(tree, d) && return tree
# insert, if not present in the tree
node = RBTreeNode{K}(d)
node.leftChild = node.rightChild = tree.nil
insert_node!(tree, node)
if node.parent == nothin... | function Base.insert!(tree::RBTree{K}, d::K) where K
# if the key exists in the tree, no need to insert
haskey(tree, d) && return tree
# insert, if not present in the tree
node = RBTreeNode{K}(d)
node.leftChild = node.rightChild = tree.nil
insert_node!(tree, node)
if node.parent == nothin... | [
211,
230
] | function Base.insert!(tree::RBTree{K}, d::K) where K
# if the key exists in the tree, no need to insert
haskey(tree, d) && return tree
# insert, if not present in the tree
node = RBTreeNode{K}(d)
node.leftChild = node.rightChild = tree.nil
insert_node!(tree, node)
if node.parent == nothin... | function Base.insert!(tree::RBTree{K}, d::K) where K
# if the key exists in the tree, no need to insert
haskey(tree, d) && return tree
# insert, if not present in the tree
node = RBTreeNode{K}(d)
node.leftChild = node.rightChild = tree.nil
insert_node!(tree, node)
if node.parent == nothin... | Base.insert! | 211 | 230 | src/red_black_tree.jl | #FILE: DataStructures.jl/src/splay_tree.jl
##CHUNK 1
s = x
s.rightChild = nothing
if s.leftChild !== nothing
s.leftChild.parent = nothing
end
tree.root = _join!(tree, s.leftChild, t)
tree.count -= 1
return tree
end
function Base.push!(tree::SplayTree{K}, d0) where K
d = conve... |
247 | 305 | DataStructures.jl | 43 | function delete_fix(tree::RBTree, node::Union{RBTreeNode, Nothing})
while node != tree.root && !node.color
if node == node.parent.leftChild
sibling = node.parent.rightChild
if sibling.color
sibling.color = false
node.parent.color = true
... | function delete_fix(tree::RBTree, node::Union{RBTreeNode, Nothing})
while node != tree.root && !node.color
if node == node.parent.leftChild
sibling = node.parent.rightChild
if sibling.color
sibling.color = false
node.parent.color = true
... | [
247,
305
] | function delete_fix(tree::RBTree, node::Union{RBTreeNode, Nothing})
while node != tree.root && !node.color
if node == node.parent.leftChild
sibling = node.parent.rightChild
if sibling.color
sibling.color = false
node.parent.color = true
... | function delete_fix(tree::RBTree, node::Union{RBTreeNode, Nothing})
while node != tree.root && !node.color
if node == node.parent.leftChild
sibling = node.parent.rightChild
if sibling.color
sibling.color = false
node.parent.color = true
... | delete_fix | 247 | 305 | src/red_black_tree.jl | #FILE: DataStructures.jl/src/splay_tree.jl
##CHUNK 1
# double rotation
elseif node_x == parent.leftChild && parent == grand_parent.leftChild
# zig-zig rotation
right_rotate!(tree, grand_parent)
right_rotate!(tree, parent)
elseif node_x == parent.rightChild... |
341 | 390 | DataStructures.jl | 44 | function Base.delete!(tree::RBTree{K}, d::K) where K
z = tree.nil
node = tree.root
while node !== tree.nil
if node.data == d
z = node
end
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
(z === t... | function Base.delete!(tree::RBTree{K}, d::K) where K
z = tree.nil
node = tree.root
while node !== tree.nil
if node.data == d
z = node
end
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
(z === t... | [
341,
390
] | function Base.delete!(tree::RBTree{K}, d::K) where K
z = tree.nil
node = tree.root
while node !== tree.nil
if node.data == d
z = node
end
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
(z === t... | function Base.delete!(tree::RBTree{K}, d::K) where K
z = tree.nil
node = tree.root
while node !== tree.nil
if node.data == d
z = node
end
if d < node.data
node = node.leftChild
else
node = node.rightChild
end
end
(z === t... | Base.delete! | 341 | 390 | src/red_black_tree.jl | #FILE: DataStructures.jl/src/splay_tree.jl
##CHUNK 1
# double rotation
elseif node_x == parent.leftChild && parent == grand_parent.leftChild
# zig-zig rotation
right_rotate!(tree, grand_parent)
right_rotate!(tree, parent)
elseif node_x == parent.rightChild... |
399 | 412 | DataStructures.jl | 45 | function Base.getindex(tree::RBTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(ArgumentError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::RBTreeNode{K}) where K
if (node !== tree.nil)
left = traverse_tree_inorder(node.leftChild)
... | function Base.getindex(tree::RBTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(ArgumentError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::RBTreeNode{K}) where K
if (node !== tree.nil)
left = traverse_tree_inorder(node.leftChild)
... | [
399,
412
] | function Base.getindex(tree::RBTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(ArgumentError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::RBTreeNode{K}) where K
if (node !== tree.nil)
left = traverse_tree_inorder(node.leftChild)
... | function Base.getindex(tree::RBTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(ArgumentError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::RBTreeNode{K}) where K
if (node !== tree.nil)
left = traverse_tree_inorder(node.leftChild)
... | traverse_tree_inorder | 399 | 412 | src/red_black_tree.jl | #FILE: DataStructures.jl/src/splay_tree.jl
##CHUNK 1
end
splay!(tree, node)
tree.count += 1
return tree
end
function Base.getindex(tree::SplayTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(KeyError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_in... |
97 | 148 | DataStructures.jl | 46 | function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
sz = length(h.keys)
(h.count > ROBIN_DICT_LOAD_FACTOR * sz) && rehash!(h, sz<<2)
# table full
@assert h.count != length(h.keys)
ckey, cval, chash = key, val, hash_key(key)
sz = length(h.keys)
index_init = desired_index(ch... | function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
sz = length(h.keys)
(h.count > ROBIN_DICT_LOAD_FACTOR * sz) && rehash!(h, sz<<2)
# table full
@assert h.count != length(h.keys)
ckey, cval, chash = key, val, hash_key(key)
sz = length(h.keys)
index_init = desired_index(ch... | [
97,
148
] | function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
sz = length(h.keys)
(h.count > ROBIN_DICT_LOAD_FACTOR * sz) && rehash!(h, sz<<2)
# table full
@assert h.count != length(h.keys)
ckey, cval, chash = key, val, hash_key(key)
sz = length(h.keys)
index_init = desired_index(ch... | function rh_insert!(h::RobinDict{K, V}, key::K, val::V) where {K, V}
sz = length(h.keys)
(h.count > ROBIN_DICT_LOAD_FACTOR * sz) && rehash!(h, sz<<2)
# table full
@assert h.count != length(h.keys)
ckey, cval, chash = key, val, hash_key(key)
sz = length(h.keys)
index_init = desired_index(ch... | rh_insert! | 97 | 148 | src/robin_dict.jl | #FILE: DataStructures.jl/test/test_robin_dict.jl
##CHUNK 1
# Functions which are not exported, but are required for checking invariants
hash_key(key) = (hash(key)%UInt32) | 0x80000000
desired_index(hash, sz) = (hash & (sz - 1)) + 1
isslotfilled(h::RobinDict, index) = (h.hashes[index] != 0)
isslotemp... |
150 | 193 | DataStructures.jl | 47 | function rh_insert_for_rehash!(h_new::RobinDict{K, V}, key::K, val::V, hash::UInt32) where {K, V}
# table full
@assert h_new.count != length(h_new.keys)
ckey, cval, chash = key, val, hash
sz = length(h_new.keys)
index_init = desired_index(chash, sz)
index_curr = index_init
probe_distance =... | function rh_insert_for_rehash!(h_new::RobinDict{K, V}, key::K, val::V, hash::UInt32) where {K, V}
# table full
@assert h_new.count != length(h_new.keys)
ckey, cval, chash = key, val, hash
sz = length(h_new.keys)
index_init = desired_index(chash, sz)
index_curr = index_init
probe_distance =... | [
150,
193
] | function rh_insert_for_rehash!(h_new::RobinDict{K, V}, key::K, val::V, hash::UInt32) where {K, V}
# table full
@assert h_new.count != length(h_new.keys)
ckey, cval, chash = key, val, hash
sz = length(h_new.keys)
index_init = desired_index(chash, sz)
index_curr = index_init
probe_distance =... | function rh_insert_for_rehash!(h_new::RobinDict{K, V}, key::K, val::V, hash::UInt32) where {K, V}
# table full
@assert h_new.count != length(h_new.keys)
ckey, cval, chash = key, val, hash
sz = length(h_new.keys)
index_init = desired_index(chash, sz)
index_curr = index_init
probe_distance =... | rh_insert_for_rehash! | 150 | 193 | src/robin_dict.jl | #FILE: DataStructures.jl/src/ordered_robin_dict.jl
##CHUNK 1
_setindex!(h, v0, key0)
else
@assert haskey(h, key0)
@inbounds orig_v = h.vals[index]
!isequal(orig_v, v0) && (@inbounds h.vals[index] = v0)
end
check_for_rehash(h) && rehash!(h)
return h
end
# rehash when th... |
196 | 226 | DataStructures.jl | 48 | function rehash!(h::RobinDict{K,V}, newsz = length(h.keys)) where {K, V}
oldk = h.keys
oldv = h.vals
oldh = h.hashes
sz = length(oldk)
newsz = _tablesz(newsz)
if h.count == 0
resize!(h.keys, newsz)
resize!(h.vals, newsz)
resize!(h.hashes, newsz)
fill!(h.hashes, 0)... | function rehash!(h::RobinDict{K,V}, newsz = length(h.keys)) where {K, V}
oldk = h.keys
oldv = h.vals
oldh = h.hashes
sz = length(oldk)
newsz = _tablesz(newsz)
if h.count == 0
resize!(h.keys, newsz)
resize!(h.vals, newsz)
resize!(h.hashes, newsz)
fill!(h.hashes, 0)... | [
196,
226
] | function rehash!(h::RobinDict{K,V}, newsz = length(h.keys)) where {K, V}
oldk = h.keys
oldv = h.vals
oldh = h.hashes
sz = length(oldk)
newsz = _tablesz(newsz)
if h.count == 0
resize!(h.keys, newsz)
resize!(h.vals, newsz)
resize!(h.hashes, newsz)
fill!(h.hashes, 0)... | function rehash!(h::RobinDict{K,V}, newsz = length(h.keys)) where {K, V}
oldk = h.keys
oldv = h.vals
oldh = h.hashes
sz = length(oldk)
newsz = _tablesz(newsz)
if h.count == 0
resize!(h.keys, newsz)
resize!(h.vals, newsz)
resize!(h.hashes, newsz)
fill!(h.hashes, 0)... | rehash! | 196 | 226 | src/robin_dict.jl | #FILE: DataStructures.jl/src/swiss_dict.jl
##CHUNK 1
if newsz < (oldsz*5)>>2
return d
end
rehash!(d, newsz)
end
function rehash!(h::SwissDict{K,V}, newsz = length(h.keys)) where {K, V}
olds = h.slots
oldk = h.keys
oldv = h.vals
sz = length(oldk)
newsz = _tablesz(newsz)
(news... |
274 | 286 | DataStructures.jl | 49 | function Base.empty!(h::RobinDict{K,V}) where {K, V}
sz = length(h.keys)
empty!(h.hashes)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
resize!(h.hashes, sz)
fill!(h.hashes, 0)
h.count = 0
h.idxfloor = 0
return h
end | function Base.empty!(h::RobinDict{K,V}) where {K, V}
sz = length(h.keys)
empty!(h.hashes)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
resize!(h.hashes, sz)
fill!(h.hashes, 0)
h.count = 0
h.idxfloor = 0
return h
end | [
274,
286
] | function Base.empty!(h::RobinDict{K,V}) where {K, V}
sz = length(h.keys)
empty!(h.hashes)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
resize!(h.hashes, sz)
fill!(h.hashes, 0)
h.count = 0
h.idxfloor = 0
return h
end | function Base.empty!(h::RobinDict{K,V}) where {K, V}
sz = length(h.keys)
empty!(h.hashes)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
resize!(h.hashes, sz)
fill!(h.hashes, 0)
h.count = 0
h.idxfloor = 0
return h
end | Base.empty! | 274 | 286 | src/robin_dict.jl | #FILE: DataStructures.jl/src/ordered_robin_dict.jl
##CHUNK 1
julia> empty!(A);
julia> A
OrderedRobinDict{String, Int64}()
```
"""
function Base.empty!(h::OrderedRobinDict{K,V}) where {K, V}
empty!(h.dict)
empty!(h.keys)
empty!(h.vals)
h.count = 0
return h
end
function _setindex!(h::OrderedRobinDi... |
459 | 494 | DataStructures.jl | 50 | function rh_delete!(h::RobinDict{K, V}, index) where {K, V}
@assert index > 0
# this assumes that there is a key/value present in the dictionary at index
index0 = index
sz = length(h.keys)
@inbounds while true
index0 = (index0 & (sz - 1)) + 1
if isslotempty(h, index0) || calculate_d... | function rh_delete!(h::RobinDict{K, V}, index) where {K, V}
@assert index > 0
# this assumes that there is a key/value present in the dictionary at index
index0 = index
sz = length(h.keys)
@inbounds while true
index0 = (index0 & (sz - 1)) + 1
if isslotempty(h, index0) || calculate_d... | [
459,
494
] | function rh_delete!(h::RobinDict{K, V}, index) where {K, V}
@assert index > 0
# this assumes that there is a key/value present in the dictionary at index
index0 = index
sz = length(h.keys)
@inbounds while true
index0 = (index0 & (sz - 1)) + 1
if isslotempty(h, index0) || calculate_d... | function rh_delete!(h::RobinDict{K, V}, index) where {K, V}
@assert index > 0
# this assumes that there is a key/value present in the dictionary at index
index0 = index
sz = length(h.keys)
@inbounds while true
index0 = (index0 & (sz - 1)) + 1
if isslotempty(h, index0) || calculate_d... | rh_delete! | 459 | 494 | src/robin_dict.jl | #FILE: DataStructures.jl/src/ordered_robin_dict.jl
##CHUNK 1
end
function Base.pop!(h::OrderedRobinDict)
check_for_rehash(h) && rehash!(h)
index = length(h.keys)
while (index > 0)
isslotfilled(h, index) && break
index -= 1
end
index == 0 && rehash!(h)
@inbounds key = h.keys[inde... |
395 | 418 | DataStructures.jl | 51 | function Base.iterate(twoss::IntersectTwoSortedSets,
state = TwoSortedSets_State(firstindex(twoss.m1),
firstindex(twoss.m2)))
m1 = twoss.m1
m2 = twoss.m2
ord = orderobject(m1)
p1 = state.p1
p2 = state.p2
while p1 != pastends... | function Base.iterate(twoss::IntersectTwoSortedSets,
state = TwoSortedSets_State(firstindex(twoss.m1),
firstindex(twoss.m2)))
m1 = twoss.m1
m2 = twoss.m2
ord = orderobject(m1)
p1 = state.p1
p2 = state.p2
while p1 != pastends... | [
395,
418
] | function Base.iterate(twoss::IntersectTwoSortedSets,
state = TwoSortedSets_State(firstindex(twoss.m1),
firstindex(twoss.m2)))
m1 = twoss.m1
m2 = twoss.m2
ord = orderobject(m1)
p1 = state.p1
p2 = state.p2
while p1 != pastends... | function Base.iterate(twoss::IntersectTwoSortedSets,
state = TwoSortedSets_State(firstindex(twoss.m1),
firstindex(twoss.m2)))
m1 = twoss.m1
m2 = twoss.m2
ord = orderobject(m1)
p1 = state.p1
p2 = state.p2
while p1 != pastends... | Base.iterate | 395 | 418 | src/sorted_set.jl | #FILE: DataStructures.jl/src/sorted_dict.jl
##CHUNK 1
p2 = firstindex(m2)
while true
p1 == pastendsemitoken(m1) && return p2 == pastendsemitoken(m2)
p2 == pastendsemitoken(m2) && return false
@inbounds k1,d1 = deref((m1,p1))
@inbounds k2,d2 = deref((m2,p2))
(!eq(ord,k1,k2... |
648 | 670 | DataStructures.jl | 52 | function Base.issubset(m1::SortedSet{K,Ord}, m2::SortedSet{K,Ord}) where {K, Ord <: Ordering}
ord = orderobject(m1)
if ord != orderobject(m2) ||
length(m1) < length(m2) / log2(length(m2) + 2)
return invoke(issubset, Tuple{Any, SortedSet}, m1, m2)
end
p1 = firstindex(m1)
p2 = firstind... | function Base.issubset(m1::SortedSet{K,Ord}, m2::SortedSet{K,Ord}) where {K, Ord <: Ordering}
ord = orderobject(m1)
if ord != orderobject(m2) ||
length(m1) < length(m2) / log2(length(m2) + 2)
return invoke(issubset, Tuple{Any, SortedSet}, m1, m2)
end
p1 = firstindex(m1)
p2 = firstind... | [
648,
670
] | function Base.issubset(m1::SortedSet{K,Ord}, m2::SortedSet{K,Ord}) where {K, Ord <: Ordering}
ord = orderobject(m1)
if ord != orderobject(m2) ||
length(m1) < length(m2) / log2(length(m2) + 2)
return invoke(issubset, Tuple{Any, SortedSet}, m1, m2)
end
p1 = firstindex(m1)
p2 = firstind... | function Base.issubset(m1::SortedSet{K,Ord}, m2::SortedSet{K,Ord}) where {K, Ord <: Ordering}
ord = orderobject(m1)
if ord != orderobject(m2) ||
length(m1) < length(m2) / log2(length(m2) + 2)
return invoke(issubset, Tuple{Any, SortedSet}, m1, m2)
end
p1 = firstindex(m1)
p2 = firstind... | Base.issubset | 648 | 670 | src/sorted_set.jl | #FILE: DataStructures.jl/src/sorted_dict.jl
##CHUNK 1
Time: O(*cn*)
"""
function Base.isequal(m1::SortedDict{K, D, Ord}, m2::SortedDict{K, D, Ord}) where
{K, D, Ord <: Ordering}
ord = orderobject(m1)
if ord != orderobject(m2)
return invoke((==), Tuple{AbstractDict, AbstractDict}, m1, m2)
end
p1... |
30 | 44 | DataStructures.jl | 53 | function Base.copy!(to::SparseIntSet, from::SparseIntSet)
to.packed = copy(from.packed)
#we want to keep the null pages === NULL_INT_PAGE
resize!(to.reverse, length(from.reverse))
for i in eachindex(from.reverse)
page = from.reverse[i]
if page === NULL_INT_PAGE
to.reverse[i] ... | function Base.copy!(to::SparseIntSet, from::SparseIntSet)
to.packed = copy(from.packed)
#we want to keep the null pages === NULL_INT_PAGE
resize!(to.reverse, length(from.reverse))
for i in eachindex(from.reverse)
page = from.reverse[i]
if page === NULL_INT_PAGE
to.reverse[i] ... | [
30,
44
] | function Base.copy!(to::SparseIntSet, from::SparseIntSet)
to.packed = copy(from.packed)
#we want to keep the null pages === NULL_INT_PAGE
resize!(to.reverse, length(from.reverse))
for i in eachindex(from.reverse)
page = from.reverse[i]
if page === NULL_INT_PAGE
to.reverse[i] ... | function Base.copy!(to::SparseIntSet, from::SparseIntSet)
to.packed = copy(from.packed)
#we want to keep the null pages === NULL_INT_PAGE
resize!(to.reverse, length(from.reverse))
for i in eachindex(from.reverse)
page = from.reverse[i]
if page === NULL_INT_PAGE
to.reverse[i] ... | Base.copy! | 30 | 44 | src/sparse_int_set.jl | #CURRENT FILE: DataStructures.jl/src/sparse_int_set.jl
##CHUNK 1
page = @inbounds s.reverse[pageid]
return page !== NULL_INT_PAGE && @inbounds page[offset] != 0
end
end
Base.length(s::SparseIntSet) = length(s.packed)
@inline function Base.push!(s::SparseIntSet, i::Integer)
i <= 0 && throw(Dom... |
129 | 141 | DataStructures.jl | 54 | function search_node(tree::SplayTree{K}, d::K) where K
node = tree.root
prev = nothing
while node != nothing && node.data != d
prev = node
if node.data < d
node = node.rightChild
else
node = node.leftChild
end
end
return (node == nothing) ? pre... | function search_node(tree::SplayTree{K}, d::K) where K
node = tree.root
prev = nothing
while node != nothing && node.data != d
prev = node
if node.data < d
node = node.rightChild
else
node = node.leftChild
end
end
return (node == nothing) ? pre... | [
129,
141
] | function search_node(tree::SplayTree{K}, d::K) where K
node = tree.root
prev = nothing
while node != nothing && node.data != d
prev = node
if node.data < d
node = node.rightChild
else
node = node.leftChild
end
end
return (node == nothing) ? pre... | function search_node(tree::SplayTree{K}, d::K) where K
node = tree.root
prev = nothing
while node != nothing && node.data != d
prev = node
if node.data < d
node = node.rightChild
else
node = node.leftChild
end
end
return (node == nothing) ? pre... | search_node | 129 | 141 | src/splay_tree.jl | #FILE: DataStructures.jl/src/avl_tree.jl
##CHUNK 1
return node
end
function search_node(tree::AVLTree{K}, d::K) where K
prev = nothing
node = tree.root
while node != nothing && node.data != nothing && node.data != d
prev = node
if d < node.data
node = node.leftChild
... |
158 | 182 | DataStructures.jl | 55 | function Base.delete!(tree::SplayTree{K}, d::K) where K
node = tree.root
x = search_node(tree, d)
(x == nothing) && return tree
t = nothing
s = nothing
splay!(tree, x)
if x.rightChild !== nothing
t = x.rightChild
t.parent = nothing
end
s = x
s.rightChild = noth... | function Base.delete!(tree::SplayTree{K}, d::K) where K
node = tree.root
x = search_node(tree, d)
(x == nothing) && return tree
t = nothing
s = nothing
splay!(tree, x)
if x.rightChild !== nothing
t = x.rightChild
t.parent = nothing
end
s = x
s.rightChild = noth... | [
158,
182
] | function Base.delete!(tree::SplayTree{K}, d::K) where K
node = tree.root
x = search_node(tree, d)
(x == nothing) && return tree
t = nothing
s = nothing
splay!(tree, x)
if x.rightChild !== nothing
t = x.rightChild
t.parent = nothing
end
s = x
s.rightChild = noth... | function Base.delete!(tree::SplayTree{K}, d::K) where K
node = tree.root
x = search_node(tree, d)
(x == nothing) && return tree
t = nothing
s = nothing
splay!(tree, x)
if x.rightChild !== nothing
t = x.rightChild
t.parent = nothing
end
s = x
s.rightChild = noth... | Base.delete! | 158 | 182 | src/splay_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
function Base.delete!(tree::RBTree{K}, d::K) where K
z = tree.nil
node = tree.root
while node !== tree.nil
if node.data == d
z = node
end
if d < node.data
node = node.leftChild
else
... |
184 | 215 | DataStructures.jl | 56 | function Base.push!(tree::SplayTree{K}, d0) where K
d = convert(K, d0)
is_present = search_node(tree, d)
if (is_present !== nothing) && (is_present.data == d)
return tree
end
# only unique keys are inserted
node = SplayTreeNode{K}(d)
y = nothing
x = tree.root
while x !== not... | function Base.push!(tree::SplayTree{K}, d0) where K
d = convert(K, d0)
is_present = search_node(tree, d)
if (is_present !== nothing) && (is_present.data == d)
return tree
end
# only unique keys are inserted
node = SplayTreeNode{K}(d)
y = nothing
x = tree.root
while x !== not... | [
184,
215
] | function Base.push!(tree::SplayTree{K}, d0) where K
d = convert(K, d0)
is_present = search_node(tree, d)
if (is_present !== nothing) && (is_present.data == d)
return tree
end
# only unique keys are inserted
node = SplayTreeNode{K}(d)
y = nothing
x = tree.root
while x !== not... | function Base.push!(tree::SplayTree{K}, d0) where K
d = convert(K, d0)
is_present = search_node(tree, d)
if (is_present !== nothing) && (is_present.data == d)
return tree
end
# only unique keys are inserted
node = SplayTreeNode{K}(d)
y = nothing
x = tree.root
while x !== not... | Base.push! | 184 | 215 | src/splay_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
function Base.insert!(tree::RBTree{K}, d::K) where K
# if the key exists in the tree, no need to insert
haskey(tree, d) && return tree
# insert, if not present in the tree
node = RBTreeNode{K}(d)
node.leftChild = node.rightChild = tree.nil
... |
217 | 230 | DataStructures.jl | 57 | function Base.getindex(tree::SplayTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(KeyError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::Union{SplayTreeNode, Nothing})
if (node != nothing)
left = traverse_tree_inorder(node.leftChi... | function Base.getindex(tree::SplayTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(KeyError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::Union{SplayTreeNode, Nothing})
if (node != nothing)
left = traverse_tree_inorder(node.leftChi... | [
217,
230
] | function Base.getindex(tree::SplayTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(KeyError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::Union{SplayTreeNode, Nothing})
if (node != nothing)
left = traverse_tree_inorder(node.leftChi... | function Base.getindex(tree::SplayTree{K}, ind) where K
@boundscheck (1 <= ind <= tree.count) || throw(KeyError("$ind should be in between 1 and $(tree.count)"))
function traverse_tree_inorder(node::Union{SplayTreeNode, Nothing})
if (node != nothing)
left = traverse_tree_inorder(node.leftChi... | traverse_tree_inorder | 217 | 230 | src/splay_tree.jl | #FILE: DataStructures.jl/src/red_black_tree.jl
##CHUNK 1
function traverse_tree_inorder(node::RBTreeNode{K}) where K
if (node !== tree.nil)
left = traverse_tree_inorder(node.leftChild)
right = traverse_tree_inorder(node.rightChild)
append!(push!(left, node.data), right)
... |
149 | 170 | DataStructures.jl | 58 | function ht_keyindex(h::SwissDict, key, i0, tag)
slots = h.slots
keys = h.keys
sz = length(slots)
i = i0 & (sz-1)
_prefetchr(pointer(h.keys, i*16+1))
_prefetchr(pointer(h.vals, i*16+1))
#Todo/discuss: _prefetchr(pointer(h.keys, i*16+9))?
@inbounds while true
msk = slots[i+1]
... | function ht_keyindex(h::SwissDict, key, i0, tag)
slots = h.slots
keys = h.keys
sz = length(slots)
i = i0 & (sz-1)
_prefetchr(pointer(h.keys, i*16+1))
_prefetchr(pointer(h.vals, i*16+1))
#Todo/discuss: _prefetchr(pointer(h.keys, i*16+9))?
@inbounds while true
msk = slots[i+1]
... | [
149,
170
] | function ht_keyindex(h::SwissDict, key, i0, tag)
slots = h.slots
keys = h.keys
sz = length(slots)
i = i0 & (sz-1)
_prefetchr(pointer(h.keys, i*16+1))
_prefetchr(pointer(h.vals, i*16+1))
#Todo/discuss: _prefetchr(pointer(h.keys, i*16+9))?
@inbounds while true
msk = slots[i+1]
... | function ht_keyindex(h::SwissDict, key, i0, tag)
slots = h.slots
keys = h.keys
sz = length(slots)
i = i0 & (sz-1)
_prefetchr(pointer(h.keys, i*16+1))
_prefetchr(pointer(h.vals, i*16+1))
#Todo/discuss: _prefetchr(pointer(h.keys, i*16+9))?
@inbounds while true
msk = slots[i+1]
... | ht_keyindex | 149 | 170 | src/swiss_dict.jl | #FILE: DataStructures.jl/src/robin_dict.jl
##CHUNK 1
curr = next
next = (next & (sz-1)) + 1
end
#curr is at the last position, reset back to normal
isbitstype(K) || isbitsunion(K) || ccall(:jl_arrayunset, Cvoid, (Any, UInt), h.keys, curr-1)
isbitstype(V) || isbitsunion(V) || ccall(:jl_a... |
244 | 254 | DataStructures.jl | 59 | function _iterslots(h::SwissDict, state)
i, sl = state
while iszero(sl)
i += 1
i <= length(h.slots) || return nothing
@inbounds msk = h.slots[i]
sl = _find_free(msk)
sl = (~sl & 0xffff)
end
return ((i-1)*16 + trailing_zeros(sl) + 1, (i, _blsr(sl)))
end | function _iterslots(h::SwissDict, state)
i, sl = state
while iszero(sl)
i += 1
i <= length(h.slots) || return nothing
@inbounds msk = h.slots[i]
sl = _find_free(msk)
sl = (~sl & 0xffff)
end
return ((i-1)*16 + trailing_zeros(sl) + 1, (i, _blsr(sl)))
end | [
244,
254
] | function _iterslots(h::SwissDict, state)
i, sl = state
while iszero(sl)
i += 1
i <= length(h.slots) || return nothing
@inbounds msk = h.slots[i]
sl = _find_free(msk)
sl = (~sl & 0xffff)
end
return ((i-1)*16 + trailing_zeros(sl) + 1, (i, _blsr(sl)))
end | function _iterslots(h::SwissDict, state)
i, sl = state
while iszero(sl)
i += 1
i <= length(h.slots) || return nothing
@inbounds msk = h.slots[i]
sl = _find_free(msk)
sl = (~sl & 0xffff)
end
return ((i-1)*16 + trailing_zeros(sl) + 1, (i, _blsr(sl)))
end | _iterslots | 244 | 254 | src/swiss_dict.jl | #CURRENT FILE: DataStructures.jl/src/swiss_dict.jl
##CHUNK 1
end
function _delete!(h::SwissDict{K,V}, index) where {K,V}
# Caller is responsible for maybe shrinking the SwissDict after the deletion.
isbitstype(K) || isbitsunion(K) || ccall(:jl_arrayunset, Cvoid, (Any, UInt), h.keys, index-1)
isbitstype(V) ... |
287 | 346 | DataStructures.jl | 60 | function rehash!(h::SwissDict{K,V}, newsz = length(h.keys)) where {K, V}
olds = h.slots
oldk = h.keys
oldv = h.vals
sz = length(oldk)
newsz = _tablesz(newsz)
(newsz*SWISS_DICT_LOAD_FACTOR) > h.count || (newsz <<= 1)
h.age += 1
h.idxfloor = 1
if h.count == 0
resize!(h.slots, n... | function rehash!(h::SwissDict{K,V}, newsz = length(h.keys)) where {K, V}
olds = h.slots
oldk = h.keys
oldv = h.vals
sz = length(oldk)
newsz = _tablesz(newsz)
(newsz*SWISS_DICT_LOAD_FACTOR) > h.count || (newsz <<= 1)
h.age += 1
h.idxfloor = 1
if h.count == 0
resize!(h.slots, n... | [
287,
346
] | function rehash!(h::SwissDict{K,V}, newsz = length(h.keys)) where {K, V}
olds = h.slots
oldk = h.keys
oldv = h.vals
sz = length(oldk)
newsz = _tablesz(newsz)
(newsz*SWISS_DICT_LOAD_FACTOR) > h.count || (newsz <<= 1)
h.age += 1
h.idxfloor = 1
if h.count == 0
resize!(h.slots, n... | function rehash!(h::SwissDict{K,V}, newsz = length(h.keys)) where {K, V}
olds = h.slots
oldk = h.keys
oldv = h.vals
sz = length(oldk)
newsz = _tablesz(newsz)
(newsz*SWISS_DICT_LOAD_FACTOR) > h.count || (newsz <<= 1)
h.age += 1
h.idxfloor = 1
if h.count == 0
resize!(h.slots, n... | rehash! | 287 | 346 | src/swiss_dict.jl | #FILE: DataStructures.jl/src/robin_dict.jl
##CHUNK 1
end
return index_curr
end
#rehash! algorithm
function rehash!(h::RobinDict{K,V}, newsz = length(h.keys)) where {K, V}
oldk = h.keys
oldv = h.vals
oldh = h.hashes
sz = length(oldk)
newsz = _tablesz(newsz)
if h.count == 0
resize... |
370 | 382 | DataStructures.jl | 61 | function Base.empty!(h::SwissDict{K,V}) where {K, V}
fill!(h.slots, _expand16(0x00))
sz = length(h.keys)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
h.nbfull = 0
h.count = 0
h.age += 1
h.idxfloor = 1
return h
end | function Base.empty!(h::SwissDict{K,V}) where {K, V}
fill!(h.slots, _expand16(0x00))
sz = length(h.keys)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
h.nbfull = 0
h.count = 0
h.age += 1
h.idxfloor = 1
return h
end | [
370,
382
] | function Base.empty!(h::SwissDict{K,V}) where {K, V}
fill!(h.slots, _expand16(0x00))
sz = length(h.keys)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
h.nbfull = 0
h.count = 0
h.age += 1
h.idxfloor = 1
return h
end | function Base.empty!(h::SwissDict{K,V}) where {K, V}
fill!(h.slots, _expand16(0x00))
sz = length(h.keys)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
h.nbfull = 0
h.count = 0
h.age += 1
h.idxfloor = 1
return h
end | Base.empty! | 370 | 382 | src/swiss_dict.jl | #FILE: DataStructures.jl/src/robin_dict.jl
##CHUNK 1
RobinDict{String, Int64}()
```
"""
function Base.empty!(h::RobinDict{K,V}) where {K, V}
sz = length(h.keys)
empty!(h.hashes)
empty!(h.keys)
empty!(h.vals)
resize!(h.keys, sz)
resize!(h.vals, sz)
resize!(h.hashes, sz)
fill!(h.hashes, 0)... |
389 | 402 | DataStructures.jl | 62 | function _setindex!(h::SwissDict{K,V}, v0, key::K) where {K, V}
v = convert(V, v0)
index, tag = ht_keyindex2!(h, key)
if index > 0
h.age += 1
@inbounds h.keys[index] = key
@inbounds h.vals[index] = v
else
_setindex!(h, v, key, -index, tag)
end
return h
end | function _setindex!(h::SwissDict{K,V}, v0, key::K) where {K, V}
v = convert(V, v0)
index, tag = ht_keyindex2!(h, key)
if index > 0
h.age += 1
@inbounds h.keys[index] = key
@inbounds h.vals[index] = v
else
_setindex!(h, v, key, -index, tag)
end
return h
end | [
389,
402
] | function _setindex!(h::SwissDict{K,V}, v0, key::K) where {K, V}
v = convert(V, v0)
index, tag = ht_keyindex2!(h, key)
if index > 0
h.age += 1
@inbounds h.keys[index] = key
@inbounds h.vals[index] = v
else
_setindex!(h, v, key, -index, tag)
end
return h
end | function _setindex!(h::SwissDict{K,V}, v0, key::K) where {K, V}
v = convert(V, v0)
index, tag = ht_keyindex2!(h, key)
if index > 0
h.age += 1
@inbounds h.keys[index] = key
@inbounds h.vals[index] = v
else
_setindex!(h, v, key, -index, tag)
end
return h
end | _setindex! | 389 | 402 | src/swiss_dict.jl | #FILE: DataStructures.jl/src/ordered_robin_dict.jl
##CHUNK 1
@inbounds h.dict[key] = Int32(nk)
h.count += 1
end
function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
key = convert(K, key0)
v = convert(V, v0)
index = get(h.dict, key, -2)
if index < 0
_setindex!(h, v0,... |
449 | 467 | DataStructures.jl | 63 | function _get!(default::Callable, h::SwissDict{K,V}, key::K) where {K, V}
index, tag = ht_keyindex2!(h, key)
index > 0 && return @inbounds h.vals[index]
age0 = h.age
v = convert(V, default())
if h.age != age0
index, tag = ht_keyindex2!(h, key)
end
if index > 0
h.age += 1
... | function _get!(default::Callable, h::SwissDict{K,V}, key::K) where {K, V}
index, tag = ht_keyindex2!(h, key)
index > 0 && return @inbounds h.vals[index]
age0 = h.age
v = convert(V, default())
if h.age != age0
index, tag = ht_keyindex2!(h, key)
end
if index > 0
h.age += 1
... | [
449,
467
] | function _get!(default::Callable, h::SwissDict{K,V}, key::K) where {K, V}
index, tag = ht_keyindex2!(h, key)
index > 0 && return @inbounds h.vals[index]
age0 = h.age
v = convert(V, default())
if h.age != age0
index, tag = ht_keyindex2!(h, key)
end
if index > 0
h.age += 1
... | function _get!(default::Callable, h::SwissDict{K,V}, key::K) where {K, V}
index, tag = ht_keyindex2!(h, key)
index > 0 && return @inbounds h.vals[index]
age0 = h.age
v = convert(V, default())
if h.age != age0
index, tag = ht_keyindex2!(h, key)
end
if index > 0
h.age += 1
... | _get! | 449 | 467 | src/swiss_dict.jl | #FILE: DataStructures.jl/src/ordered_robin_dict.jl
##CHUNK 1
@inbounds h.dict[key] = Int32(nk)
h.count += 1
end
function Base.setindex!(h::OrderedRobinDict{K, V}, v0, key0) where {K,V}
key = convert(K, key0)
v = convert(V, v0)
index = get(h.dict, key, -2)
if index < 0
_setindex!(h, v0,... |
601 | 611 | DataStructures.jl | 64 | function Base.pop!(h::SwissDict)
isempty(h) && throw(ArgumentError("SwissDict must be non-empty"))
is = _iterslots(h, h.idxfloor)
@assert is !== nothing
idx, s = is
@inbounds key = h.keys[idx]
@inbounds val = h.vals[idx]
_delete!(h, idx)
h.idxfloor = idx
return key => val
end | function Base.pop!(h::SwissDict)
isempty(h) && throw(ArgumentError("SwissDict must be non-empty"))
is = _iterslots(h, h.idxfloor)
@assert is !== nothing
idx, s = is
@inbounds key = h.keys[idx]
@inbounds val = h.vals[idx]
_delete!(h, idx)
h.idxfloor = idx
return key => val
end | [
601,
611
] | function Base.pop!(h::SwissDict)
isempty(h) && throw(ArgumentError("SwissDict must be non-empty"))
is = _iterslots(h, h.idxfloor)
@assert is !== nothing
idx, s = is
@inbounds key = h.keys[idx]
@inbounds val = h.vals[idx]
_delete!(h, idx)
h.idxfloor = idx
return key => val
end | function Base.pop!(h::SwissDict)
isempty(h) && throw(ArgumentError("SwissDict must be non-empty"))
is = _iterslots(h, h.idxfloor)
@assert is !== nothing
idx, s = is
@inbounds key = h.keys[idx]
@inbounds val = h.vals[idx]
_delete!(h, idx)
h.idxfloor = idx
return key => val
end | Base.pop! | 601 | 611 | src/swiss_dict.jl | #FILE: DataStructures.jl/src/ordered_robin_dict.jl
##CHUNK 1
OrderedRobinDict{String, Int64} with 1 entry:
"a" => 1
```
"""
function Base.delete!(h::OrderedRobinDict, key)
pop!(h, key)
return h
end
function _delete!(h::OrderedRobinDict, index)
@inbounds h.dict[h.keys[index]] = -1
h.count -= 1
che... |
78 | 88 | DataStructures.jl | 65 | function Base.keys(t::Trie{K,V},
prefix=_empty_prefix(t),
found=Vector{typeof(prefix)}()) where {K,V}
if t.is_key
push!(found, prefix)
end
for (char,child) in t.children
keys(child, _concat(prefix, char), found)
end
return found
end | function Base.keys(t::Trie{K,V},
prefix=_empty_prefix(t),
found=Vector{typeof(prefix)}()) where {K,V}
if t.is_key
push!(found, prefix)
end
for (char,child) in t.children
keys(child, _concat(prefix, char), found)
end
return found
end | [
78,
88
] | function Base.keys(t::Trie{K,V},
prefix=_empty_prefix(t),
found=Vector{typeof(prefix)}()) where {K,V}
if t.is_key
push!(found, prefix)
end
for (char,child) in t.children
keys(child, _concat(prefix, char), found)
end
return found
end | function Base.keys(t::Trie{K,V},
prefix=_empty_prefix(t),
found=Vector{typeof(prefix)}()) where {K,V}
if t.is_key
push!(found, prefix)
end
for (char,child) in t.children
keys(child, _concat(prefix, char), found)
end
return found
end | Base.keys | 78 | 88 | src/trie.jl | #FILE: DataStructures.jl/test/test_trie.jl
##CHUNK 1
t[[1,2,3,4]] = 1
t[[1,2]] = 2
@test haskey(t, [1,2])
@test get(t, [1,2], nothing) == 2
st = subtrie(t, [1,2,3])
@test keys(st) == [[4]]
@test st[[4]] == 1
@test find_prefixes(t, [1,2,3,5]) == [[1,2]]
... |
154 | 165 | DataStructures.jl | 66 | function find_prefixes(t::Trie, str::T) where {T}
prefixes = T[]
it = partial_path(t, str)
idx = 0
for t in it
if t.is_key
push!(prefixes, str[firstindex(str):idx])
end
idx = nextind(str, idx)
end
return prefixes
end | function find_prefixes(t::Trie, str::T) where {T}
prefixes = T[]
it = partial_path(t, str)
idx = 0
for t in it
if t.is_key
push!(prefixes, str[firstindex(str):idx])
end
idx = nextind(str, idx)
end
return prefixes
end | [
154,
165
] | function find_prefixes(t::Trie, str::T) where {T}
prefixes = T[]
it = partial_path(t, str)
idx = 0
for t in it
if t.is_key
push!(prefixes, str[firstindex(str):idx])
end
idx = nextind(str, idx)
end
return prefixes
end | function find_prefixes(t::Trie, str::T) where {T}
prefixes = T[]
it = partial_path(t, str)
idx = 0
for t in it
if t.is_key
push!(prefixes, str[firstindex(str):idx])
end
idx = nextind(str, idx)
end
return prefixes
end | find_prefixes | 154 | 165 | src/trie.jl | #FILE: DataStructures.jl/test/test_trie.jl
##CHUNK 1
t[[1,2,3,4]] = 1
t[[1,2]] = 2
@test haskey(t, [1,2])
@test get(t, [1,2], nothing) == 2
st = subtrie(t, [1,2,3])
@test keys(st) == [[4]]
@test st[[4]] == 1
@test find_prefixes(t, [1,2,3,5]) == [[1,2]]
... |
143 | 160 | DataStructures.jl | 67 | function is_minmax_heap(A::AbstractVector)
for i in 1:length(A)
if on_minlevel(i)
# check that A[i] < children A[i]
# and grandchildren A[i]
for j in children_and_grandchildren(length(A), i)
A[i] ≤ A[j] || return false
end
else
... | function is_minmax_heap(A::AbstractVector)
for i in 1:length(A)
if on_minlevel(i)
# check that A[i] < children A[i]
# and grandchildren A[i]
for j in children_and_grandchildren(length(A), i)
A[i] ≤ A[j] || return false
end
else
... | [
143,
160
] | function is_minmax_heap(A::AbstractVector)
for i in 1:length(A)
if on_minlevel(i)
# check that A[i] < children A[i]
# and grandchildren A[i]
for j in children_and_grandchildren(length(A), i)
A[i] ≤ A[j] || return false
end
else
... | function is_minmax_heap(A::AbstractVector)
for i in 1:length(A)
if on_minlevel(i)
# check that A[i] < children A[i]
# and grandchildren A[i]
for j in children_and_grandchildren(length(A), i)
A[i] ≤ A[j] || return false
end
else
... | is_minmax_heap | 143 | 160 | src/heaps/minmax_heap.jl | #CURRENT FILE: DataStructures.jl/src/heaps/minmax_heap.jl
##CHUNK 1
@inline isgrandchild(j, i) = j > rchild(i)
@inline hasgrandparent(i) = i ≥ 4
"""
children_and_grandchildren(maxlen, i)
Return the indices of all children and grandchildren of
position `i`.
"""
function children_and_grandchildren(maxlen::T, i::T) ... |
187 | 197 | DataStructures.jl | 68 | function popmin!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x = valtree[1]
y = pop!(valtree)
if !isempty(valtree)
@inbounds valtree[1] = y
@inbounds _minmax_heap_trickle_down!(valtree, 1)
end
return x... | function popmin!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x = valtree[1]
y = pop!(valtree)
if !isempty(valtree)
@inbounds valtree[1] = y
@inbounds _minmax_heap_trickle_down!(valtree, 1)
end
return x... | [
187,
197
] | function popmin!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x = valtree[1]
y = pop!(valtree)
if !isempty(valtree)
@inbounds valtree[1] = y
@inbounds _minmax_heap_trickle_down!(valtree, 1)
end
return x... | function popmin!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x = valtree[1]
y = pop!(valtree)
if !isempty(valtree)
@inbounds valtree[1] = y
@inbounds _minmax_heap_trickle_down!(valtree, 1)
end
return x... | popmin! | 187 | 197 | src/heaps/minmax_heap.jl | #CURRENT FILE: DataStructures.jl/src/heaps/minmax_heap.jl
##CHUNK 1
Remove up to the `k` smallest values from the heap.
"""
@inline function popmin!(h::BinaryMinMaxHeap, k::Integer)
return [popmin!(h) for _ in 1:min(length(h), k)]
end
"""
popmax!(h::BinaryMinMaxHeap) -> max
Remove the maximum value from the ... |
214 | 224 | DataStructures.jl | 69 | function popmax!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x, i = maximum(((valtree[j], j) for j in 1:min(length(valtree), 3)))
y = pop!(valtree)
if !isempty(valtree) && i <= length(valtree)
@inbounds valtree[i] = y... | function popmax!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x, i = maximum(((valtree[j], j) for j in 1:min(length(valtree), 3)))
y = pop!(valtree)
if !isempty(valtree) && i <= length(valtree)
@inbounds valtree[i] = y... | [
214,
224
] | function popmax!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x, i = maximum(((valtree[j], j) for j in 1:min(length(valtree), 3)))
y = pop!(valtree)
if !isempty(valtree) && i <= length(valtree)
@inbounds valtree[i] = y... | function popmax!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x, i = maximum(((valtree[j], j) for j in 1:min(length(valtree), 3)))
y = pop!(valtree)
if !isempty(valtree) && i <= length(valtree)
@inbounds valtree[i] = y... | popmax! | 214 | 224 | src/heaps/minmax_heap.jl | #CURRENT FILE: DataStructures.jl/src/heaps/minmax_heap.jl
##CHUNK 1
y = pop!(valtree)
if !isempty(valtree)
@inbounds valtree[1] = y
@inbounds _minmax_heap_trickle_down!(valtree, 1)
end
return x
end
"""
popmin!(h::BinaryMinMaxHeap, k::Integer) -> vals
Remove up to the `k` smallest ... |
103 | 130 | DataStructures.jl | 70 | function _binary_heap_pop!(ord::Ordering,
nodes::Vector{MutableBinaryHeapNode{T}}, nodemap::Vector{Int}, nd_id::Int=1) where T
# extract node
rt = nodes[nd_id]
v = rt.value
@inbounds nodemap[rt.handle] = 0
# if node-to-remove is at end, we can just pop it
# the same applies to 1-element he... | function _binary_heap_pop!(ord::Ordering,
nodes::Vector{MutableBinaryHeapNode{T}}, nodemap::Vector{Int}, nd_id::Int=1) where T
# extract node
rt = nodes[nd_id]
v = rt.value
@inbounds nodemap[rt.handle] = 0
# if node-to-remove is at end, we can just pop it
# the same applies to 1-element he... | [
103,
130
] | function _binary_heap_pop!(ord::Ordering,
nodes::Vector{MutableBinaryHeapNode{T}}, nodemap::Vector{Int}, nd_id::Int=1) where T
# extract node
rt = nodes[nd_id]
v = rt.value
@inbounds nodemap[rt.handle] = 0
# if node-to-remove is at end, we can just pop it
# the same applies to 1-element he... | function _binary_heap_pop!(ord::Ordering,
nodes::Vector{MutableBinaryHeapNode{T}}, nodemap::Vector{Int}, nd_id::Int=1) where T
# extract node
rt = nodes[nd_id]
v = rt.value
@inbounds nodemap[rt.handle] = 0
# if node-to-remove is at end, we can just pop it
# the same applies to 1-element he... | _binary_heap_pop! | 103 | 130 | src/heaps/mutable_binary_heap.jl | #FILE: DataStructures.jl/src/heaps/minmax_heap.jl
##CHUNK 1
"""
popmin!(h::BinaryMinMaxHeap) -> min
Remove the minimum value from the heap.
"""
function popmin!(h::BinaryMinMaxHeap)
valtree = h.valtree
!isempty(valtree) || throw(ArgumentError("heap must be non-empty"))
@inbounds x = valtree[1]
y =... |
132 | 150 | DataStructures.jl | 71 | function _make_mutable_binary_heap(ord::Ordering, ty::Type{T}, values) where T
# make a static binary index tree from a list of values
n = length(values)
nodes = Vector{MutableBinaryHeapNode{T}}(undef, n)
nodemap = Vector{Int}(undef, n)
i::Int = 0
for v in values
i += 1
@inboun... | function _make_mutable_binary_heap(ord::Ordering, ty::Type{T}, values) where T
# make a static binary index tree from a list of values
n = length(values)
nodes = Vector{MutableBinaryHeapNode{T}}(undef, n)
nodemap = Vector{Int}(undef, n)
i::Int = 0
for v in values
i += 1
@inboun... | [
132,
150
] | function _make_mutable_binary_heap(ord::Ordering, ty::Type{T}, values) where T
# make a static binary index tree from a list of values
n = length(values)
nodes = Vector{MutableBinaryHeapNode{T}}(undef, n)
nodemap = Vector{Int}(undef, n)
i::Int = 0
for v in values
i += 1
@inboun... | function _make_mutable_binary_heap(ord::Ordering, ty::Type{T}, values) where T
# make a static binary index tree from a list of values
n = length(values)
nodes = Vector{MutableBinaryHeapNode{T}}(undef, n)
nodemap = Vector{Int}(undef, n)
i::Int = 0
for v in values
i += 1
@inboun... | _make_mutable_binary_heap | 132 | 150 | src/heaps/mutable_binary_heap.jl | #FILE: DataStructures.jl/test/test_mutable_binheap.jl
##CHUNK 1
# Test of binary heaps
# auxiliary functions
function heap_values(h::MutableBinaryHeap{VT,O}) where {VT,O}
n = length(h)
nodes = h.nodes
@assert length(nodes) == n
vs = Vector{VT}(undef, n)
for i = 1 : n
vs[i] = nodes[i].value... |
187 | 197 | Distributions.jl | 72 | function mean(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
μ = (xexpy(lower, log_prob_lower) + xexpy(upper, log_prob_... | function mean(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
μ = (xexpy(lower, log_prob_lower) + xexpy(upper, log_prob_... | [
187,
197
] | function mean(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
μ = (xexpy(lower, log_prob_lower) + xexpy(upper, log_prob_... | function mean(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
μ = (xexpy(lower, log_prob_lower) + xexpy(upper, log_prob_... | mean | 187 | 197 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
# and τ is d₀ truncated to [l, u]
function mean(d::LeftCensored)
lower = d.lower
log_prob_lower = _logcdf_noninclusive(d.uncensored, lower)
log_prob_interval = log1mexp(log_prob_lower)
μ = xexpy(lower, log_prob_lower) + xexpy(mean(_to_truncated(... |
199 | 209 | Distributions.jl | 73 | function var(d::LeftCensored)
lower = d.lower
log_prob_lower = _logcdf_noninclusive(d.uncensored, lower)
log_prob_interval = log1mexp(log_prob_lower)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(lower, log_prob_lower) + xexpy(μ_interval, log_prob_interval)
v_interval = var(d... | function var(d::LeftCensored)
lower = d.lower
log_prob_lower = _logcdf_noninclusive(d.uncensored, lower)
log_prob_interval = log1mexp(log_prob_lower)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(lower, log_prob_lower) + xexpy(μ_interval, log_prob_interval)
v_interval = var(d... | [
199,
209
] | function var(d::LeftCensored)
lower = d.lower
log_prob_lower = _logcdf_noninclusive(d.uncensored, lower)
log_prob_interval = log1mexp(log_prob_lower)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(lower, log_prob_lower) + xexpy(μ_interval, log_prob_interval)
v_interval = var(d... | function var(d::LeftCensored)
lower = d.lower
log_prob_lower = _logcdf_noninclusive(d.uncensored, lower)
log_prob_interval = log1mexp(log_prob_lower)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(lower, log_prob_lower) + xexpy(μ_interval, log_prob_interval)
v_interval = var(d... | var | 199 | 209 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
μ = (xexpy(lower, log_prob_lower) + xexpy(upper, log_prob_upper) +
xexpy(mean(_t... |
210 | 220 | Distributions.jl | 74 | function var(d::RightCensored)
upper = d.upper
log_prob_upper = logccdf(d.uncensored, upper)
log_prob_interval = log1mexp(log_prob_upper)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(upper, log_prob_upper) + xexpy(μ_interval, log_prob_interval)
v_interval = var(dtrunc) + abs... | function var(d::RightCensored)
upper = d.upper
log_prob_upper = logccdf(d.uncensored, upper)
log_prob_interval = log1mexp(log_prob_upper)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(upper, log_prob_upper) + xexpy(μ_interval, log_prob_interval)
v_interval = var(dtrunc) + abs... | [
210,
220
] | function var(d::RightCensored)
upper = d.upper
log_prob_upper = logccdf(d.uncensored, upper)
log_prob_interval = log1mexp(log_prob_upper)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(upper, log_prob_upper) + xexpy(μ_interval, log_prob_interval)
v_interval = var(dtrunc) + abs... | function var(d::RightCensored)
upper = d.upper
log_prob_upper = logccdf(d.uncensored, upper)
log_prob_interval = log1mexp(log_prob_upper)
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
μ = xexpy(upper, log_prob_upper) + xexpy(μ_interval, log_prob_interval)
v_interval = var(dtrunc) + abs... | var | 210 | 220 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
μ = (xexpy(lower, log_prob_lower) + xexpy(upper, log_prob_upper) +
xexpy(mean(_t... |
221 | 236 | Distributions.jl | 75 | function var(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
... | function var(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
... | [
221,
236
] | function var(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
... | function var(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower = _logcdf_noninclusive(d0, lower)
log_prob_upper = logccdf(d0, upper)
log_prob_interval = log1mexp(logaddexp(log_prob_lower, log_prob_upper))
dtrunc = _to_truncated(d)
μ_interval = mean(dtrunc)
... | var | 221 | 236 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
upper = d.upper
log_prob_upper = logccdf(d.uncensored, upper)
log_prob_interval = log1mexp(log_prob_upper)
μ = xexpy(upper, log_prob_upper) + xexpy(mean(_to_truncated(d)), log_prob_interval)
return μ
end
function mean(d::Censored)
d0 = d.... |
245 | 262 | Distributions.jl | 76 | function entropy(d::LeftCensored)
d0 = d.uncensored
lower = d.lower
log_prob_lower_inc = logcdf(d0, lower)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
log_prob_lower = logsubexp(log_prob_lower_inc, logpl)
xlogx_pl = xexpx(logpl)
else
log_prob_l... | function entropy(d::LeftCensored)
d0 = d.uncensored
lower = d.lower
log_prob_lower_inc = logcdf(d0, lower)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
log_prob_lower = logsubexp(log_prob_lower_inc, logpl)
xlogx_pl = xexpx(logpl)
else
log_prob_l... | [
245,
262
] | function entropy(d::LeftCensored)
d0 = d.uncensored
lower = d.lower
log_prob_lower_inc = logcdf(d0, lower)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
log_prob_lower = logsubexp(log_prob_lower_inc, logpl)
xlogx_pl = xexpx(logpl)
else
log_prob_l... | function entropy(d::LeftCensored)
d0 = d.uncensored
lower = d.lower
log_prob_lower_inc = logcdf(d0, lower)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
log_prob_lower = logsubexp(log_prob_lower_inc, logpl)
xlogx_pl = xexpx(logpl)
else
log_prob_l... | entropy | 245 | 262 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
log_prob_upper_inc = logaddexp(log_prob_upper, logpu)
xlogx_pu = xexpx(logpu)
else
log_prob_upper_inc = log_prob_upper
xlogx_pu = 0
end
log_prob_interval = log1mexp(log_prob_upper)
entropy_bound = -xexpx(log_prob_u... |
263 | 280 | Distributions.jl | 77 | function entropy(d::RightCensored)
d0 = d.uncensored
upper = d.upper
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpu = logpdf(d0, upper)
log_prob_upper_inc = logaddexp(log_prob_upper, logpu)
xlogx_pu = xexpx(logpu)
else
log_prob_upp... | function entropy(d::RightCensored)
d0 = d.uncensored
upper = d.upper
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpu = logpdf(d0, upper)
log_prob_upper_inc = logaddexp(log_prob_upper, logpu)
xlogx_pu = xexpx(logpu)
else
log_prob_upp... | [
263,
280
] | function entropy(d::RightCensored)
d0 = d.uncensored
upper = d.upper
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpu = logpdf(d0, upper)
log_prob_upper_inc = logaddexp(log_prob_upper, logpu)
xlogx_pu = xexpx(logpu)
else
log_prob_upp... | function entropy(d::RightCensored)
d0 = d.uncensored
upper = d.upper
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpu = logpdf(d0, upper)
log_prob_upper_inc = logaddexp(log_prob_upper, logpu)
xlogx_pu = xexpx(logpu)
else
log_prob_upp... | entropy | 263 | 280 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
log_prob_lower = logsubexp(log_prob_lower_inc, logpl)
xlogx_pl = xexpx(logpl)
else
log_prob_lower = log_prob_lower_inc
xlogx_pl = 0
end
log_prob_interval = log1mexp(log_prob_lower)
entropy_bound = -xexpx(log_prob_l... |
281 | 304 | Distributions.jl | 78 | function entropy(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower_inc = logcdf(d0, lower)
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
logpu = logpdf(d0, upper)
log_prob_lower = logsub... | function entropy(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower_inc = logcdf(d0, lower)
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
logpu = logpdf(d0, upper)
log_prob_lower = logsub... | [
281,
304
] | function entropy(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower_inc = logcdf(d0, lower)
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
logpu = logpdf(d0, upper)
log_prob_lower = logsub... | function entropy(d::Censored)
d0 = d.uncensored
lower = d.lower
upper = d.upper
log_prob_lower_inc = logcdf(d0, lower)
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpl = logpdf(d0, lower)
logpu = logpdf(d0, upper)
log_prob_lower = logsub... | entropy | 281 | 304 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
return entropy_interval + entropy_bound
end
function entropy(d::RightCensored)
d0 = d.uncensored
upper = d.upper
log_prob_upper = logccdf(d0, upper)
if value_support(typeof(d0)) === Discrete
logpu = logpdf(d0, upper)
log_prob_... |
309 | 327 | Distributions.jl | 79 | function pdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
px = float(pdf(d0, x))
return if _in_open_interval(x, lower, upper)
px
elseif x == lower
x == upper ? one(px) : oftype(px, cdf(d0, x))
elseif x == upper
if value_support(typeof(d0)) =... | function pdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
px = float(pdf(d0, x))
return if _in_open_interval(x, lower, upper)
px
elseif x == lower
x == upper ? one(px) : oftype(px, cdf(d0, x))
elseif x == upper
if value_support(typeof(d0)) =... | [
309,
327
] | function pdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
px = float(pdf(d0, x))
return if _in_open_interval(x, lower, upper)
px
elseif x == lower
x == upper ? one(px) : oftype(px, cdf(d0, x))
elseif x == upper
if value_support(typeof(d0)) =... | function pdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
px = float(pdf(d0, x))
return if _in_open_interval(x, lower, upper)
px
elseif x == lower
x == upper ? one(px) : oftype(px, cdf(d0, x))
elseif x == upper
if value_support(typeof(d0)) =... | pdf | 309 | 327 | src/censored.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
end
function logpdf(d::Truncated, x::Real)
result = logpdf(d.untruncated, x) - d.logtp
return _in_closed_interval(x, d.lower, d.upper) ? result : oftype(result, -Inf)
end
function cdf(d::Truncated, x::Real)
result = clamp((cdf(d.untruncated, x) - d.lcdf) /... |
329 | 347 | Distributions.jl | 80 | function logpdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, x)
return if _in_open_interval(x, lower, upper)
logpx
elseif x == lower
x == upper ? zero(logpx) : oftype(logpx, logcdf(d0, x))
elseif x == upper
if value_suppor... | function logpdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, x)
return if _in_open_interval(x, lower, upper)
logpx
elseif x == lower
x == upper ? zero(logpx) : oftype(logpx, logcdf(d0, x))
elseif x == upper
if value_suppor... | [
329,
347
] | function logpdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, x)
return if _in_open_interval(x, lower, upper)
logpx
elseif x == lower
x == upper ? zero(logpx) : oftype(logpx, logcdf(d0, x))
elseif x == upper
if value_suppor... | function logpdf(d::Censored, x::Real)
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, x)
return if _in_open_interval(x, lower, upper)
logpx
elseif x == lower
x == upper ? zero(logpx) : oftype(logpx, logcdf(d0, x))
elseif x == upper
if value_suppor... | logpdf | 329 | 347 | src/censored.jl | #FILE: Distributions.jl/src/quantilealgs.jl
##CHUNK 1
x0 = x
x = x0 + exp(lp - logpdf(d,x0) + log1mexp(min(logcdf(d,x0)-lp,0)))
end
end
return x
elseif lp == -Inf
return T(minimum(d))
elseif lp == 0
return T(maximum(d))
else
... |
349 | 363 | Distributions.jl | 81 | function loglikelihood(d::Censored, x::AbstractArray{<:Real})
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, first(x))
log_prob_lower = lower === nothing ? zero(logpx) : oftype(logpx, logcdf(d0, lower))
log_prob_upper = upper === nothing ? zero(logpx) : oftype(logpx, _logcc... | function loglikelihood(d::Censored, x::AbstractArray{<:Real})
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, first(x))
log_prob_lower = lower === nothing ? zero(logpx) : oftype(logpx, logcdf(d0, lower))
log_prob_upper = upper === nothing ? zero(logpx) : oftype(logpx, _logcc... | [
349,
363
] | function loglikelihood(d::Censored, x::AbstractArray{<:Real})
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, first(x))
log_prob_lower = lower === nothing ? zero(logpx) : oftype(logpx, logcdf(d0, lower))
log_prob_upper = upper === nothing ? zero(logpx) : oftype(logpx, _logcc... | function loglikelihood(d::Censored, x::AbstractArray{<:Real})
d0 = d.uncensored
lower = d.lower
upper = d.upper
logpx = logpdf(d0, first(x))
log_prob_lower = lower === nothing ? zero(logpx) : oftype(logpx, logcdf(d0, lower))
log_prob_upper = upper === nothing ? zero(logpx) : oftype(logpx, _logcc... | loglikelihood | 349 | 363 | src/censored.jl | #CURRENT FILE: Distributions.jl/src/censored.jl
##CHUNK 1
lower = d.lower
upper = d.upper
logpx = logpdf(d0, x)
return if _in_open_interval(x, lower, upper)
logpx
elseif x == lower
x == upper ? zero(logpx) : oftype(logpx, logcdf(d0, x))
elseif x == upper
if value_support(... |
365 | 376 | Distributions.jl | 82 | function cdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = cdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
one(result)
end
end | function cdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = cdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
one(result)
end
end | [
365,
376
] | function cdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = cdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
one(result)
end
end | function cdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = cdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
one(result)
end
end | cdf | 365 | 376 | src/censored.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
return if d.lower !== nothing && x < d.lower
zero(result)
elseif d.upper !== nothing && x >= d.upper
one(result)
else
result
end
end
function logcdf(d::Truncated, x::Real)
result = logsubexp(logcdf(d.untruncated, x), d.loglcd... |
378 | 389 | Distributions.jl | 83 | function logcdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = logcdf(d.uncensored, x)
return if d.lower !== nothing && x < d.lower
oftype(result, -Inf)
elseif d.upper === nothing || x < d.upper
result
else
zero(result)
end
end | function logcdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = logcdf(d.uncensored, x)
return if d.lower !== nothing && x < d.lower
oftype(result, -Inf)
elseif d.upper === nothing || x < d.upper
result
else
zero(result)
end
end | [
378,
389
] | function logcdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = logcdf(d.uncensored, x)
return if d.lower !== nothing && x < d.lower
oftype(result, -Inf)
elseif d.upper === nothing || x < d.upper
result
else
zero(result)
end
end | function logcdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = logcdf(d.uncensored, x)
return if d.lower !== nothing && x < d.lower
oftype(result, -Inf)
elseif d.upper === nothing || x < d.upper
result
else
zero(result)
end
end | logcdf | 378 | 389 | src/censored.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
391 | 402 | Distributions.jl | 84 | function ccdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = ccdf(d.uncensored, x)
return if lower !== nothing && x < lower
one(result)
elseif upper === nothing || x < upper
result
else
zero(result)
end
end | function ccdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = ccdf(d.uncensored, x)
return if lower !== nothing && x < lower
one(result)
elseif upper === nothing || x < upper
result
else
zero(result)
end
end | [
391,
402
] | function ccdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = ccdf(d.uncensored, x)
return if lower !== nothing && x < lower
one(result)
elseif upper === nothing || x < upper
result
else
zero(result)
end
end | function ccdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = ccdf(d.uncensored, x)
return if lower !== nothing && x < lower
one(result)
elseif upper === nothing || x < upper
result
else
zero(result)
end
end | ccdf | 391 | 402 | src/censored.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
404 | 415 | Distributions.jl | 85 | function logccdf(d::Censored{<:Any,<:Any,T}, x::Real) where {T}
lower = d.lower
upper = d.upper
result = logccdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
oftype(result, -Inf)
end
end | function logccdf(d::Censored{<:Any,<:Any,T}, x::Real) where {T}
lower = d.lower
upper = d.upper
result = logccdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
oftype(result, -Inf)
end
end | [
404,
415
] | function logccdf(d::Censored{<:Any,<:Any,T}, x::Real) where {T}
lower = d.lower
upper = d.upper
result = logccdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
oftype(result, -Inf)
end
end | function logccdf(d::Censored{<:Any,<:Any,T}, x::Real) where {T}
lower = d.lower
upper = d.upper
result = logccdf(d.uncensored, x)
return if lower !== nothing && x < lower
zero(result)
elseif upper === nothing || x < upper
result
else
oftype(result, -Inf)
end
end | logccdf | 404 | 415 | src/censored.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
156 | 172 | Distributions.jl | 86 | function _rand!(
rng::AbstractRNG,
s::Sampleable{ArrayLikeVariate{N}},
x::AbstractArray{<:AbstractArray{<:Real,N}},
allocate::Bool,
) where {N}
if allocate
@inbounds for i in eachindex(x)
x[i] = rand(rng, s)
end
else
@inbounds for xi in x
rand!(rng... | function _rand!(
rng::AbstractRNG,
s::Sampleable{ArrayLikeVariate{N}},
x::AbstractArray{<:AbstractArray{<:Real,N}},
allocate::Bool,
) where {N}
if allocate
@inbounds for i in eachindex(x)
x[i] = rand(rng, s)
end
else
@inbounds for xi in x
rand!(rng... | [
156,
172
] | function _rand!(
rng::AbstractRNG,
s::Sampleable{ArrayLikeVariate{N}},
x::AbstractArray{<:AbstractArray{<:Real,N}},
allocate::Bool,
) where {N}
if allocate
@inbounds for i in eachindex(x)
x[i] = rand(rng, s)
end
else
@inbounds for xi in x
rand!(rng... | function _rand!(
rng::AbstractRNG,
s::Sampleable{ArrayLikeVariate{N}},
x::AbstractArray{<:AbstractArray{<:Real,N}},
allocate::Bool,
) where {N}
if allocate
@inbounds for i in eachindex(x)
x[i] = rand(rng, s)
end
else
@inbounds for xi in x
rand!(rng... | _rand! | 156 | 172 | src/genericrand.jl | #FILE: Distributions.jl/src/samplers/multinomial.jl
##CHUNK 1
function _rand!(rng::AbstractRNG, s::MultinomialSampler,
x::AbstractVector{<:Real})
n = s.n
k = length(s)
if n^2 > k
multinom_rand!(rng, n, s.prob, x)
else
# Use an alias table
fill!(x, zero(eltype(x))... |
54 | 66 | Distributions.jl | 87 | function cov(d::MatrixDistribution)
M = length(d)
V = zeros(partype(d), M, M)
iter = CartesianIndices(size(d))
for el1 = 1:M
for el2 = 1:el1
i, j = Tuple(iter[el1])
k, l = Tuple(iter[el2])
V[el1, el2] = cov(d, i, j, k, l)
end
end
return V + tri... | function cov(d::MatrixDistribution)
M = length(d)
V = zeros(partype(d), M, M)
iter = CartesianIndices(size(d))
for el1 = 1:M
for el2 = 1:el1
i, j = Tuple(iter[el1])
k, l = Tuple(iter[el2])
V[el1, el2] = cov(d, i, j, k, l)
end
end
return V + tri... | [
54,
66
] | function cov(d::MatrixDistribution)
M = length(d)
V = zeros(partype(d), M, M)
iter = CartesianIndices(size(d))
for el1 = 1:M
for el2 = 1:el1
i, j = Tuple(iter[el1])
k, l = Tuple(iter[el2])
V[el1, el2] = cov(d, i, j, k, l)
end
end
return V + tri... | function cov(d::MatrixDistribution)
M = length(d)
V = zeros(partype(d), M, M)
iter = CartesianIndices(size(d))
for el1 = 1:M
for el2 = 1:el1
i, j = Tuple(iter[el1])
k, l = Tuple(iter[el2])
V[el1, el2] = cov(d, i, j, k, l)
end
end
return V + tri... | cov | 54 | 66 | src/matrixvariates.jl | #FILE: Distributions.jl/src/multivariates.jl
##CHUNK 1
cov(d::MultivariateDistribution)
"""
cor(d::MultivariateDistribution)
Computes the correlation matrix for distribution `d`.
"""
function cor(d::MultivariateDistribution)
C = cov(d)
n = size(C, 1)
@assert size(C, 2) == n
R = Matrix{eltype(C)}(u... |
98 | 115 | Distributions.jl | 88 | function cor(d::MultivariateDistribution)
C = cov(d)
n = size(C, 1)
@assert size(C, 2) == n
R = Matrix{eltype(C)}(undef, n, n)
for j = 1:n
for i = 1:j-1
@inbounds R[i, j] = R[j, i]
end
R[j, j] = 1.0
for i = j+1:n
@inbounds R[i, j] = C[i, j] / ... | function cor(d::MultivariateDistribution)
C = cov(d)
n = size(C, 1)
@assert size(C, 2) == n
R = Matrix{eltype(C)}(undef, n, n)
for j = 1:n
for i = 1:j-1
@inbounds R[i, j] = R[j, i]
end
R[j, j] = 1.0
for i = j+1:n
@inbounds R[i, j] = C[i, j] / ... | [
98,
115
] | function cor(d::MultivariateDistribution)
C = cov(d)
n = size(C, 1)
@assert size(C, 2) == n
R = Matrix{eltype(C)}(undef, n, n)
for j = 1:n
for i = 1:j-1
@inbounds R[i, j] = R[j, i]
end
R[j, j] = 1.0
for i = j+1:n
@inbounds R[i, j] = C[i, j] / ... | function cor(d::MultivariateDistribution)
C = cov(d)
n = size(C, 1)
@assert size(C, 2) == n
R = Matrix{eltype(C)}(undef, n, n)
for j = 1:n
for i = 1:j-1
@inbounds R[i, j] = R[j, i]
end
R[j, j] = 1.0
for i = j+1:n
@inbounds R[i, j] = C[i, j] / ... | cor | 98 | 115 | src/multivariates.jl | #FILE: Distributions.jl/src/multivariate/multinomial.jl
##CHUNK 1
@inbounds p_i = p[i]
v[i] = n * p_i * (1 - p_i)
end
v
end
function cov(d::Multinomial{T}) where T<:Real
p = probs(d)
k = length(p)
n = ntrials(d)
C = Matrix{T}(undef, k, k)
for j = 1:k
pj = p[j]
... |
177 | 187 | Distributions.jl | 89 | function __logpdf(
d::ProductDistribution{N,M},
x::AbstractArray{<:Real,N},
) where {N,M}
# we use pairwise summation (https://github.com/JuliaLang/julia/pull/31020)
# to compute `sum(logpdf.(d.dists, eachvariate))`
@inbounds broadcasted = Broadcast.broadcasted(
logpdf, d.dists, eachvariate(... | function __logpdf(
d::ProductDistribution{N,M},
x::AbstractArray{<:Real,N},
) where {N,M}
# we use pairwise summation (https://github.com/JuliaLang/julia/pull/31020)
# to compute `sum(logpdf.(d.dists, eachvariate))`
@inbounds broadcasted = Broadcast.broadcasted(
logpdf, d.dists, eachvariate(... | [
177,
187
] | function __logpdf(
d::ProductDistribution{N,M},
x::AbstractArray{<:Real,N},
) where {N,M}
# we use pairwise summation (https://github.com/JuliaLang/julia/pull/31020)
# to compute `sum(logpdf.(d.dists, eachvariate))`
@inbounds broadcasted = Broadcast.broadcasted(
logpdf, d.dists, eachvariate(... | function __logpdf(
d::ProductDistribution{N,M},
x::AbstractArray{<:Real,N},
) where {N,M}
# we use pairwise summation (https://github.com/JuliaLang/julia/pull/31020)
# to compute `sum(logpdf.(d.dists, eachvariate))`
@inbounds broadcasted = Broadcast.broadcasted(
logpdf, d.dists, eachvariate(... | __logpdf | 177 | 187 | src/product.jl | #FILE: Distributions.jl/src/common.jl
##CHUNK 1
"""
@inline function logpdf!(
out::AbstractArray{<:Real},
d::Distribution{ArrayLikeVariate{N}},
x::AbstractArray{<:Real,M},
) where {N,M}
@boundscheck begin
M > N ||
throw(DimensionMismatch(
"number of dimensions of the ... |
3 | 35 | Distributions.jl | 90 | function quantile_bisect(d::ContinuousUnivariateDistribution, p::Real, lx::T, rx::T) where {T<:Real}
rx < lx && throw(ArgumentError("empty bracketing interval [$lx, $rx]"))
# In some special cases, e.g. #1501, rx == lx`
# If the distribution is degenerate the check below can fail, hence we skip it
if r... | function quantile_bisect(d::ContinuousUnivariateDistribution, p::Real, lx::T, rx::T) where {T<:Real}
rx < lx && throw(ArgumentError("empty bracketing interval [$lx, $rx]"))
# In some special cases, e.g. #1501, rx == lx`
# If the distribution is degenerate the check below can fail, hence we skip it
if r... | [
3,
35
] | function quantile_bisect(d::ContinuousUnivariateDistribution, p::Real, lx::T, rx::T) where {T<:Real}
rx < lx && throw(ArgumentError("empty bracketing interval [$lx, $rx]"))
# In some special cases, e.g. #1501, rx == lx`
# If the distribution is degenerate the check below can fail, hence we skip it
if r... | function quantile_bisect(d::ContinuousUnivariateDistribution, p::Real, lx::T, rx::T) where {T<:Real}
rx < lx && throw(ArgumentError("empty bracketing interval [$lx, $rx]"))
# In some special cases, e.g. #1501, rx == lx`
# If the distribution is degenerate the check below can fail, hence we skip it
if r... | quantile_bisect | 3 | 35 | src/quantilealgs.jl | #FILE: Distributions.jl/src/univariate/continuous/triangular.jl
##CHUNK 1
# Handle x == c separately to avoid `NaN` if `c == a` or `c == b`
oftype(x - a, 2) / (b - a)
end
return insupport(d, x) ? res : zero(res)
end
logpdf(d::TriangularDist, x::Real) = log(pdf(d, x))
function cdf(d::TriangularD... |
25 | 48 | Distributions.jl | 91 | function _use_multline_show(d::Distribution, pnames)
# decide whether to use one-line or multi-line format
#
# Criteria: if total number of values is greater than 8, or
# there are params that are neither numbers, tuples, or vectors,
# we use multi-line format
#
namevals = _NameVal[]
mul... | function _use_multline_show(d::Distribution, pnames)
# decide whether to use one-line or multi-line format
#
# Criteria: if total number of values is greater than 8, or
# there are params that are neither numbers, tuples, or vectors,
# we use multi-line format
#
namevals = _NameVal[]
mul... | [
25,
48
] | function _use_multline_show(d::Distribution, pnames)
# decide whether to use one-line or multi-line format
#
# Criteria: if total number of values is greater than 8, or
# there are params that are neither numbers, tuples, or vectors,
# we use multi-line format
#
namevals = _NameVal[]
mul... | function _use_multline_show(d::Distribution, pnames)
# decide whether to use one-line or multi-line format
#
# Criteria: if total number of values is greater than 8, or
# there are params that are neither numbers, tuples, or vectors,
# we use multi-line format
#
namevals = _NameVal[]
mul... | _use_multline_show | 25 | 48 | src/show.jl | #FILE: Distributions.jl/src/Distributions.jl
##CHUNK 1
modes, # mode(s) of distribution as vector
moment, # moments of distribution
nsamples, # get the number of samples contained in an array
ncategories, # the number of categories in a Categorical distribution
... |
168 | 178 | Distributions.jl | 92 | function cdf(d::Truncated, x::Real)
result = clamp((cdf(d.untruncated, x) - d.lcdf) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x < d.lower
zero(result)
elseif d.upper !== nothing && x >= d.upper
... | function cdf(d::Truncated, x::Real)
result = clamp((cdf(d.untruncated, x) - d.lcdf) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x < d.lower
zero(result)
elseif d.upper !== nothing && x >= d.upper
... | [
168,
178
] | function cdf(d::Truncated, x::Real)
result = clamp((cdf(d.untruncated, x) - d.lcdf) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x < d.lower
zero(result)
elseif d.upper !== nothing && x >= d.upper
... | function cdf(d::Truncated, x::Real)
result = clamp((cdf(d.untruncated, x) - d.lcdf) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x < d.lower
zero(result)
elseif d.upper !== nothing && x >= d.upper
... | cdf | 168 | 178 | src/truncate.jl | #FILE: Distributions.jl/src/censored.jl
##CHUNK 1
elseif upper === nothing || x < upper
result
else
one(result)
end
end
function logcdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = logcdf(d.uncensored, x)
return if d.lower !== nothing && x < d.lower
... |
191 | 201 | Distributions.jl | 93 | function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
elseif d.upper !== nothing && x > d.upper
... | function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
elseif d.upper !== nothing && x > d.upper
... | [
191,
201
] | function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
elseif d.upper !== nothing && x > d.upper
... | function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
elseif d.upper !== nothing && x > d.upper
... | ccdf | 191 | 201 | src/truncate.jl | #FILE: Distributions.jl/src/censored.jl
##CHUNK 1
elseif upper === nothing || x < upper
result
else
one(result)
end
end
function logcdf(d::Censored, x::Real)
lower = d.lower
upper = d.upper
result = logcdf(d.uncensored, x)
return if d.lower !== nothing && x < d.lower
... |
426 | 463 | Distributions.jl | 94 | function _pdf_fill_outside!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange)
vl = vfirst = first(X)
vr = vlast = last(X)
n = vlast - vfirst + 1
if islowerbounded(d)
lb = minimum(d)
if vl < lb
vl = lb
end
end
if isupperbounded(d)
ub = ... | function _pdf_fill_outside!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange)
vl = vfirst = first(X)
vr = vlast = last(X)
n = vlast - vfirst + 1
if islowerbounded(d)
lb = minimum(d)
if vl < lb
vl = lb
end
end
if isupperbounded(d)
ub = ... | [
426,
463
] | function _pdf_fill_outside!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange)
vl = vfirst = first(X)
vr = vlast = last(X)
n = vlast - vfirst + 1
if islowerbounded(d)
lb = minimum(d)
if vl < lb
vl = lb
end
end
if isupperbounded(d)
ub = ... | function _pdf_fill_outside!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange)
vl = vfirst = first(X)
vr = vlast = last(X)
n = vlast - vfirst + 1
if islowerbounded(d)
lb = minimum(d)
if vl < lb
vl = lb
end
end
if isupperbounded(d)
ub = ... | _pdf_fill_outside! | 426 | 463 | src/univariates.jl | #FILE: Distributions.jl/test/testutils.jl
##CHUNK 1
elseif islowerbounded(d)
@test map(Base.Fix1(pdf, d), rmin-2:rmax) ≈ vcat(0.0, 0.0, p0)
end
end
function test_evaluation(d::DiscreteUnivariateDistribution, vs::AbstractVector, testquan::Bool=true)
nv = length(vs)
p = Vector{Float64}(undef,... |
479 | 492 | Distributions.jl | 95 | function _pdf!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange, rpe::RecursiveProbabilityEvaluator)
vl,vr, vfirst, vlast = _pdf_fill_outside!(r, d, X)
# fill central part: with non-zero pdf
if vl <= vr
fm1 = vfirst - 1
r[vl - fm1] = pv = pdf(d, vl)
for v = (vl+1):v... | function _pdf!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange, rpe::RecursiveProbabilityEvaluator)
vl,vr, vfirst, vlast = _pdf_fill_outside!(r, d, X)
# fill central part: with non-zero pdf
if vl <= vr
fm1 = vfirst - 1
r[vl - fm1] = pv = pdf(d, vl)
for v = (vl+1):v... | [
479,
492
] | function _pdf!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange, rpe::RecursiveProbabilityEvaluator)
vl,vr, vfirst, vlast = _pdf_fill_outside!(r, d, X)
# fill central part: with non-zero pdf
if vl <= vr
fm1 = vfirst - 1
r[vl - fm1] = pv = pdf(d, vl)
for v = (vl+1):v... | function _pdf!(r::AbstractArray, d::DiscreteUnivariateDistribution, X::UnitRange, rpe::RecursiveProbabilityEvaluator)
vl,vr, vfirst, vlast = _pdf_fill_outside!(r, d, X)
# fill central part: with non-zero pdf
if vl <= vr
fm1 = vfirst - 1
r[vl - fm1] = pv = pdf(d, vl)
for v = (vl+1):v... | _pdf! | 479 | 492 | src/univariates.jl | #FILE: Distributions.jl/src/univariate/discrete/categorical.jl
##CHUNK 1
function _pdf!(r::AbstractArray{<:Real}, d::Categorical{T}, rgn::UnitRange) where {T<:Real}
vfirst = round(Int, first(rgn))
vlast = round(Int, last(rgn))
vl = max(vfirst, 1)
vr = min(vlast, ncategories(d))
p = probs(d)
if ... |
496 | 510 | Distributions.jl | 96 | function cdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(cdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x < 0... | function cdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(cdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x < 0... | [
496,
510
] | function cdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(cdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x < 0... | function cdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(cdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x < 0... | cdf_int | 496 | 510 | src/univariates.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
512 | 526 | Distributions.jl | 97 | function ccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(ccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x <... | function ccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(ccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x <... | [
512,
526
] | function ccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(ccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x <... | function ccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(ccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif x <... | ccdf_int | 512 | 526 | src/univariates.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
528 | 542 | Distributions.jl | 98 | function logcdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logcdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif... | function logcdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logcdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif... | [
528,
542
] | function logcdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logcdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif... | function logcdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logcdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
elseif... | logcdf_int | 528 | 542 | src/univariates.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
544 | 558 | Distributions.jl | 99 | function logccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
else... | function logccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
else... | [
544,
558
] | function logccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
else... | function logccdf_int(d::DiscreteUnivariateDistribution, x::Real)
# handle `NaN` and `±Inf` which can't be truncated to `Int`
isfinite_x = isfinite(x)
_x = isfinite_x ? x : zero(x)
c = float(logccdf(d, floor(Int, _x)))
return if isfinite_x
c
elseif isnan(x)
oftype(c, NaN)
else... | logccdf_int | 544 | 558 | src/univariates.jl | #FILE: Distributions.jl/src/truncate.jl
##CHUNK 1
function ccdf(d::Truncated, x::Real)
result = clamp((d.ucdf - cdf(d.untruncated, x)) / d.tp, 0, 1)
# Special cases for values outside of the support to avoid e.g. NaN issues with `Binomial`
return if d.lower !== nothing && x <= d.lower
one(result)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.