Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ struct DequeIterator{T}
d::Deque{T}
end

Base.eltype(::Type{DequeIterator{T}}) where {T} = T

Base.last(di::DequeIterator) = last(di.d)

function Base.iterate(di::DequeIterator{T}, (cb, i) = (di.d.head, di.d.head.front)) where T
Expand Down
3 changes: 3 additions & 0 deletions src/sparse_int_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ end

Base.length(it::ZippedSparseIntSetIterator) = length(it.shortest_set)

Base.eltype(::Type{ZippedSparseIntSetIterator{VT,IT}}) where {VT,IT} =
NTuple{length(VT.parameters), Int}

# we know it is not in_excluded, as there are no excluded
@inline in_excluded(id, it::ZippedSparseIntSetIterator{VT,Tuple{}}) where {VT} = false

Expand Down
10 changes: 6 additions & 4 deletions src/trie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ end
# and i is the index of the current character of the string.
# The indexing is potentially confusing;
# see the comments and implementation below for details.
struct TrieIterator
t::Trie
str
struct TrieIterator{T<:Trie,S}
t::T
str::S
end

# At the start, there is no previous iteration,
Expand All @@ -119,7 +119,9 @@ function Base.iterate(it::TrieIterator, (t, i) = (it.t, 0))
end

partial_path(t::Trie, str) = TrieIterator(t, str)
Base.IteratorSize(::Type{TrieIterator}) = Base.SizeUnknown()

Base.eltype(::Type{TrieIterator{T,S}}) where {T,S} = T
Base.IteratorSize(::Type{<:TrieIterator}) = Base.SizeUnknown()

"""
find_prefixes(t::Trie, str)
Expand Down
4 changes: 4 additions & 0 deletions test/test_sparse_int_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ import DataStructures: SparseIntSet, IntSet
@test SparseIntSet(2:2:10) <= SparseIntSet(2:2:10)
end
@testset "zip" begin
a2 = SparseIntSet([1, 2])
@test eltype(zip(a2, a2)) === Tuple{Int, Int}
@test typeof(collect(zip(a2, a2))) === Vector{Tuple{Int, Int}}

a = SparseIntSet([1,2,3,5, 6, 9, 12, 24])
b = SparseIntSet([6, 12, 24, 1000, 2000, 3000])
c = SparseIntSet(2:2:100)
Expand Down
2 changes: 2 additions & 0 deletions test/test_stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@

@test arr == [i for i in Iterators.reverse(stk)]
@test reverse(arr) == [i for i in stk]
@test eltype(Iterators.reverse(stk)) === Int
@test typeof(collect(Iterators.reverse(stk))) === Vector{Int}
@test first(Iterators.reverse(stk)) === last(stk)
@test last(Iterators.reverse(stk)) === first(stk)
@test length(Iterators.reverse(stk)) === length(stk)
Expand Down
2 changes: 2 additions & 0 deletions test/test_trie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
t1 = t0.children['r']
t2 = t1.children['o']
t3 = t2.children['b']
@test eltype(partial_path(t, "rob")) === Trie{Char,Int}
@test typeof(collect(partial_path(t, "rob"))) === Vector{Trie{Char,Int}}
@test collect(partial_path(t, "b")) == [t0]
@test collect(partial_path(t, "rob")) == [t0, t1, t2, t3]
@test collect(partial_path(t, "robb")) == [t0, t1, t2, t3]
Expand Down
Loading