Skip to content

Commit

Permalink
get ind, find els
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jan 13, 2025
1 parent 250c320 commit 7cd0350
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaBase"
uuid = "075456b7-4006-432f-9324-2f8453996c49"
authors = ["PharmCat <[email protected]> and contributors"]
version = "0.12.1"
version = "0.13.0"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
48 changes: 46 additions & 2 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Base.getindex(d::DataSet, ind::Int)
d.ds[ind]
end

Base.getindex(d::DataSet, inds::UnitRange{Int64}) = subset(d, inds)
Base.getindex(d::DataSet, inds) = subset(d, inds)


@inline function getresultindex_safe(rd::T, ind::Symbol) where T <: AbstractResultData
Expand All @@ -34,6 +34,8 @@ end
@inline function getresultindex_unsafe(rd::T, ind::Symbol) where T <: AbstractResultData
rd.result[ind]
end
getresultindex_safe(rd, ind::AbstractString) = getresultindex_safe(rd, Symbol(ind))
getresultindex_unsafe(rd, ind::AbstractString) = getresultindex_unsafe(rd, Symbol(ind))

function Base.getindex(d::DataSet{T}, col::Int, ind) where T <: AbstractResultData
getresultindex_safe(d[col], ind)
Expand Down Expand Up @@ -171,8 +173,50 @@ function Base.findall(d::DataSet{<: AbstractIdData}, sort::Dict)
findall(x-> sort getid(x), getdata(d))
end

################################################################################
# find*el
################################################################################


function findfirstel(d::DataSet{<: AbstractIdData}, sort::Dict)
ind = findfirst(x-> sort getid(x), getdata(d))
if isnothing(ind)
return nothing
else
return d[ind]
end
end
function Base.findlastel(d::DataSet{<: AbstractIdData}, sort::Dict)
ind = findlast(x-> sort getid(x), getdata(d))
if isnothing(ind)
return nothing
else
return d[ind]
end
end
function Base.findnextel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int)
ind = findnext(x-> sort getid(x), getdata(d), i)
if isnothing(ind)
return nothing
else
return d[ind]
end
end
function Base.findprevel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int)
ind = findprev(x-> sort getid(x), getdata(d), i)
if isnothing(ind)
return nothing
else
return d[ind]
end
end
function Base.findallel(d::DataSet{<: AbstractIdData}, sort::Dict)
ind = findall(x-> sort getid(x), getdata(d))
if isnothing(ind)
return nothing
else
return d[ind]
end
end
################################################################################
# SELF
################################################################################
Expand Down

0 comments on commit 7cd0350

Please sign in to comment.