Skip to content

Commit

Permalink
Use pairs instead of enumerate as appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Dec 8, 2018
1 parent b1773ee commit 33fd608
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/UniqueVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ indexin(a::AbstractArray, b::AbstractUniqueVector) =
findall(p::Union{Base.Fix2{typeof(in),<:AbstractUniqueVector},
Base.Fix2{typeof(!in),<:AbstractUniqueVector}},
a::Union{Tuple, AbstractArray}) =
[i for (i, ai) in enumerate(a) if p(ai)]
[i for (i, ai) in (@static if VERSION >= v"1.1.0-DEV.832" pairs else enumerate end)(a) if p(ai)]

function findnext(p::EqualTo, A::AbstractUniqueVector, i::Integer)
idx = findfirst(p, A)
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ uv5[1] = 4
@test findlast(isequal(4), uv5) == 1
@test findall(isequal(4), uv5) == [1]

# Test indexin and findin
# Test indexin and findall([!]in)
@test indexin([1,2,34,0,5,56], UniqueVector([34,56,35,1,5,0])) == [4,nothing,1,6,5,2]
@test indexin([1,2,34,0,5,56], UniqueVector([34,56,35,1,5,0])) == [4,nothing,1,6,5,2]
@test findall(in(UniqueVector([34,56,35,1,5,0])), [1,2,34,0,5,56]) == [1,3,4,5,6]
@test findall(!in(UniqueVector([34,56,35,1,5,0])), [1,2,34,0,5,56]) == [2]
@test findall(in(UniqueVector([5,7,9])), [5 6; 7 8]) == findall(in([5,7,9]), [5 6; 7 8])
@test findall(!in(UniqueVector([5,7,9])), [5 6; 7 8]) == findall(!in([5,7,9]), [5 6; 7 8])

# Test findnext and findprev
@test findnext(isequal(7), UniqueVector([3,5,7,9]), 1) == 3
Expand Down

0 comments on commit 33fd608

Please sign in to comment.