Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
phaverty committed Dec 31, 2020
2 parents 36d4577 + 452062b commit 78c2eb0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ is useful to know the bounds of genome regions covered by these runs,
the values associated with these runs, and to be able to perform
various mathematical operations on these values.

[![Build Status](https://travis-ci.org/phaverty/RLEVectors.jl.svg?branch=master)](https://travis-ci.org/phaverty/RLEVectors.jl)
[![Build Status](https://travis-ci.com/phaverty/RLEVectors.jl.svg?branch=master)](https://travis-ci.com/phaverty/RLEVectors.jl)
[![Coverage Status](https://codecov.io/github/phaverty/RLEVectors.jl/coverage.svg?branch=master)](https://codecov.io/github/phaverty/RLEVectors.jl?branch=master)

[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://phaverty.github.io/RLEVectors.jl/latest)
Expand Down
7 changes: 6 additions & 1 deletion src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function Base.setindex!(rle::RLEVector, value, i::Integer)
run = ind2run(rle, i)
runvalue = rle.runvalues[run]
runend = rle.runends[run]
#value == runvalue && return rle # replace with same value, no-op
isequal(value, runvalue) && return rle
previous_run = run - 1
next_run = run + 1
Expand Down Expand Up @@ -148,6 +147,12 @@ function Base.getindex(x::RLEVector, i::AbstractVector{<:Int})
RLEVector(x.runvalues[run_indices])
end

function Base.getindex(x::RLEVector, i::AbstractVector{Bool})
# FIXME: room for optimization for runs of true
new_inds = findall(i)
x[new_inds]
end

function Base.setindex!(x::RLEVector, value::AbstractVector, indices::UnitRange)
setindex!(x, RLEVector(value), indices)
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ using RLEVectors
## getindex with logical
x = RLEVector([1, 2], [2, 4])
@test x[[true, false, false, true]] == RLEVector([1, 2])
x = RLEVector(["a","a","b","c"])
@test x[[true,false,true,false]] == RLEVector(["a","b"])

## setindex! for single position
y = RLEVector([3, 4, 4, 5, 5])
Expand Down

0 comments on commit 78c2eb0

Please sign in to comment.