ChrisRackauckas / LinkedLists.jl

A repository for singly and doubly linked lists in Julia
Other
15 stars 11 forks source link

maybe implement `getindex(list, idx::Int)` #6

Open JeffreySarnoff opened 5 years ago

JeffreySarnoff commented 5 years ago

I wrote these for something I am doing.

function Base.getindex(lst::SLinkedList, idx::Int)
    !(0 < idx <= length(lst)) && throw(BoundsError("index $idx")
    return lst[positiontoindex(idx, lst)]
end

function Base.getindex(lst::LinkedList, idx::Int)
    !(0 < idx <= length(lst)) && throw(BoundsError("index $idx")
    return lst[positiontoindex(idx, lst)]
end

If so, setindex!(list, idx::Int, value) [etc] similarly

ChrisRackauckas commented 5 years ago

Makes sense to me.

Tobias-Thomas commented 1 year ago

I like this implementation of Linked Lists, and would like to see this change but I am not sure whether it is still under development. I would do the pull request if there is someone willing to merge it. ;)

JeffreySarnoff commented 1 year ago

go right ahead --