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... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 5