SortedSequences

Index

Base.insert!Method
insert!(v, index, item)

The Base.Insert! function is extended to operate on NonDecreasingVector and IncreasingVector. An argument-error will be thrown if the item leads to an unsorted sequence.

Examples:

julia> v = NonDecreasingVector([1,2,3,4]);

julia> insert!(v, 3, 2)
5-element Vector{Int64}:
 1
 2
 2
 3
 4

julia> v = IncreasingVector([1,2,4,5]);

julia> insert!(v, 3, 3)
5-element Vector{Int64}:
 1
 2
 3
 4
 5
source
SortedSequences.construct_vectorMethod
construct_vector(u, m)

Construct a vector by repeating the elements in u m times.

Examples:

julia> u = [0.0,1.0,2.5,3.0]
4-element Vector{Float64}:
 0.0
 1.0
 2.5
 3.0

julia> m = [2,1,2,3]
4-element Vector{Int64}:
 2
 1
 2
 3

julia> construct_vector(u, m)
8-element Vector{Float64}:
 0.0
 0.0
 1.0
 2.5
 2.5
 3.0
 3.0
 3.0
source
SortedSequences.deconstruct_vectorMethod
deconstruct_vector(v)

Decompose a sequence into a new sequence, a multiplicity vector, and vectors specifying indexing into the sequence.

Examples:

julia> v = [0.0,0.0,1.0,2.0,2.0,3.0,3.0,3.0];

julia> u, m, ia, ic = deconstruct_vector(v)
([0.0, 1.0, 2.0, 3.0], [2, 1, 2, 3], [1, 1, 2, 3, 3, 4, 4, 4], [2, 3, 5, 8])

julia> construct_vector(u,m)==v
true

julia> u[ia]==v
true

julia> v[ic]==u
true
source
SortedSequences.global_insertMethod
global_insert(v, k)

Uniformly subdivide new values into an IncreasingVector or NonDecreasingVector.

Examples:

julia> v = IncreasingVector([0.0,1.0,2.0])
3-element IncreasingVector{Float64}:
 0.0
 1.0
 2.0

julia> global_insert(v, 3)
9-element IncreasingVector{Float64}:
 0.0
 0.25
 0.5
 0.75
 1.0
 1.25
 1.5
 1.75
 2.0

When applied to a NonDecreasingVector only the non-zero length intervals are subdivided

julia> v = NonDecreasingVector([0.0,0.0,1.0,1.0,2.0])
5-element NonDecreasingVector{Float64}:
 0.0
 0.0
 1.0
 1.0
 2.0

julia> global_insert(v, 3)
11-element NonDecreasingVector{Float64}:
 0.0
 0.0
 0.25
 0.5
 0.75
 1.0
 1.0
 1.25
 1.5
 1.75
 2.0
source
SortedSequences.IncreasingVectorType
IncreasingVector{T<:Real}

Construct a vector with an increasing set of real numbers.

Examples:

The element type T is a subtype of Real. Hence it is possible to make IncreasingVector{Int64} as well as IncreasingVector{Float64}

julia> IncreasingVector([0,1,2,3])
4-element IncreasingVector{Int64}:
 0
 1
 2
 3

julia> IncreasingVector([0.0,1.0,2.0,3.0])
4-element IncreasingVector{Float64}:
 0.0
 1.0
 2.0
 3.0

It is also possible to extract the unique values of a NonDecreasingVector into an IncreasingVector.

julia> v = NonDecreasingVector([0.0,0.0,1.0,2.0,2.0,3.0,3.0])
7-element NonDecreasingVector{Float64}:
 0.0
 0.0
 1.0
 2.0
 2.0
 3.0
 3.0

julia> IncreasingVector(v)
4-element IncreasingVector{Float64}:
 0.0
 1.0
 2.0
 3.0
source
SortedSequences.NonDecreasingVectorType
NonDecreasingVector{T}

Construct a vector with a non-decreasing set of real numbers.

Examples:

julia> v = NonDecreasingVector([0.0,0.0,1.0,2.0,2.0])
5-element NonDecreasingVector{Float64}:
 0.0
 0.0
 1.0
 2.0
 2.0

julia> u, m = deconstruct_vector(v)
([0.0, 1.0, 2.0], [2, 1, 2], [1, 1, 2, 3, 3], [2, 3, 5])

julia> u
3-element IncreasingVector{Float64}:
 0.0
 1.0
 2.0

julia> NonDecreasingVector(u, m) == v
true

It is also possible to extract the unique values of a NonDecreasingVector into an IncreasingVector.

julia> v = NonDecreasingVector([0.0,0.0,1.0,2.0,2.0,3.0,3.0])
7-element NonDecreasingVector{Float64}:
 0.0
 0.0
 1.0
 2.0
 2.0
 3.0
 3.0

julia> IncreasingVector(v)
4-element IncreasingVector{Float64}:
 0.0
 1.0
 2.0
 3.0
source
SortedSequences.UniqueType
Unique(v)

Convenience iterator that lazily returns a tuple with the unique consecutive values and their multiplicities.

Examples:

julia> v = [1,1,3,4,5,5,5,6,6,7];

julia> for item in Unique(v)
           @show item
       end
item = (1, 2)
item = (3, 1)
item = (4, 1)
item = (5, 3)
item = (6, 2)
item = (7, 1)
source