A RingList
is a list of distinct values that is
unchanged by rotation. These can be created by giving a list of values
or a one-dimensional array of values:
julia> a = RingList(1,2,3,4);
julia> b = RingList([2,3,4,1]);
julia> a==b
true
In this list, a
stands for a RingList
.
length(a)
gives the number of elements held in theRingList
.keys(a)
returns an iterator of the elements ina
.haskey(a,x)
checks ifx
is an element of theRingList
.Vector(a)
returns a one-dimensional array of the elements ina
.Set(a)
returns the elements ofa
(as an unordered collection).a[x]
returns the next element afterx
ina
.previous(a,x)
returns the elementy
witha[y]==x
.first(a)
returns an element ofa
; callfirst(a,true)
to attempt try to return the smallest value held ina
. Fails ifa
is empty.insert!(a,x)
inserts the elementa
into theRingList
. No guarantee where it will end up.delete!(a,x)
removesx
from the collection linking together its predecessor and successor.insertafter!(a,x,y)
insertsx
intoa
aftery
. For example:
julia> a = RingList(1,2,3)
RingList{Int64}(1,2,3)
julia> insertafter!(a,99,2)
julia> a
RingList{Int64}(1,2,99,3)
reverse(a)
returns a newRingList
with the elements reversed.
julia> a = RingList(1,2,3,4,5)
RingList{Int64}(1,2,3,4,5)
julia> b = reverse(a)
RingList{Int64}(1,5,4,3,2)