Skip to content

Commit dccf3b7

Browse files
authored
Avoid indexing for OrderedSet (#94)
1 parent 9eac113 commit dccf3b7

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/parse.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function parse_di(di_name::AbstractString, hdr::Dict{String,Any}; load_unused =
177177
end
178178
for i = 1:length(chns)
179179
biti = findfirst(x->x==parse(Int, split(chns[i], ".")[2]), hdr["di channel list"])
180-
if biti != findfirst(x->x==chns[i], DI_CHANS[rig])
180+
if biti != firstfound(x->x==chns[i], DI_CHANS[rig])
181181
@warn "DI channel list entry #$(biti) found in the .imagine header does not match the expected entry for this rig. Attempting to load anyway, but please report this issue"
182182
end
183183
end
@@ -220,7 +220,7 @@ function parse_di(di_name, rig, sample_rate::HasInverseTimeUnits)
220220
for i = 1:length(insigs)
221221
sig = insigs[i]
222222
daq_chan_str = daq_channel(sig)
223-
biti = findfirst(x->x==daq_chan_str, DI_CHANS[rig])
223+
biti = firstfound(x->x==daq_chan_str, DI_CHANS[rig])
224224
samps = mappedarray(UInt8, view(A, biti, :)) #feels a bit dishonest to call UInt8 the raw type, but there is no Bit type...
225225
sampsarr = Array{AbstractVector}(undef, 0)
226226
push!(sampsarr, samps)
@@ -298,3 +298,12 @@ function load_signals(any_name::AbstractString)
298298
end
299299
return coms
300300
end
301+
302+
function firstfound(@nospecialize(predicate), set::OrderedSet)
303+
i = 0
304+
for item in set
305+
i += 1
306+
predicate(item) && return i
307+
end
308+
error("predicate did not match any items in ", set)
309+
end

0 commit comments

Comments
 (0)