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> using RingLists
julia> a = RingList(1,2,3,4);
julia> b = RingList([2,3,4,1]);
julia> a==b
true
julia> println(a)
[ 1 → 2 → 3 → 4 → 1 ]
Note the repeat of element 1 in the output showing that the list wraps around.
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 ifxis 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).collect(a)returns the elements ofain an ordered list.copy(a)makes an independent copy ofa.shuffle(a)returns a newRingListwith the same elements asabut in randomized order.next(a,x)returns the next element afterxina; alsoa[x].previous(a,x)returns the elementywitha[y]==x; alsoa(y).first(a)returns an element ofathat is, if possible, the smallest element ofa. Callfirst(a,false)to ignore trying to start at the smallest element. Fails ifais empty.delete!(a,x)removesxfrom the collection linking together its predecessor and successor.insert!(a,x)inserts the elementainto theRingList. No guarantee where it will end up.insertbefore!(a,x,y)insertsxintoabeforey.insertafter!(a,x,y)insertsxintoaaftery. For example:
> a = RingList(1,2,3)
[ 1 → 2 → 3 → 1 ]
julia> insertafter!(a,99,2)
julia> a
[ 1 → 2 → 99 → 3 → 1 ]
reverse(a)returns a newRingListwith the elements reversed.
julia> a = RingList(1,2,3,4,5)
[ 1 → 2 → 3 → 4 → 5 → 1 ]
julia> b = reverse(a)
[ 1 → 5 → 4 → 3 → 2 → 1 ]
firsts(a)returns a newRingListbuilt by taking thefirstmember of each element ofa.
julia> a
[ (19, 20) → (20, 25) → (25, 31) → (31, 27) → (27, 19) → (19, 20) ]
julia> firsts(a)
[ 19 → 20 → 25 → 31 → 27 → 19 ]
RingList elements can be iterated:
julia> a = RingList(1,2,3,4,5)
[ 1 → 2 → 3 → 4 → 5 → 1 ]
julia> for x in a
println(x)
end
1
2
3
4
5