Skip to content

PatternFolds.jl

Documentation for PatternFolds.jl.

PatternFolds.PatternFold Type
julia
PatternFold{T, P}

A Union type used as an interface for folded patterns such as VectorFold. To implement the interface and inherit from it, a new structure MyFold{T[,P]} must define three fields:

  • pattern::P. Note that both length(::P) and rand(::P) methods must be available

  • gap::TS

  • folds::int

Finally one can redefine PatternFold

julia
PatternFold{T} = Union{AbstractVectorFold{T}, IntervalsFold{T}, MyFold{T[,P]}}

source

PatternFolds.AbstractVectorFold Type
julia
AbstractVectorFold{T, P}

An abstract type used as an interface for folded vectors such as VectorFold. To implement the interface and inherit from it, a new structure must define three fields:

  • pattern::P. Note that both length(::P) and rand(::P) methods must be available

  • gap::T

  • folds::int

source

PatternFolds.IVectorFold Type
julia
VectorFold{T,V <: AbstractVector{T}}

A folded vector structure that extends the methods of AbstractVector to a folded structure.

source

PatternFolds.VectorFold Type
julia
VectorFold{T,V <: AbstractVector{T}}

A mutable structure for folded vector that extends the methods of AbstractVector. Compared to IVectorFold, this tructure is about 20% faster using iterators. Note that this structure keep an active pointer to the current unfolded pattern. However, its external behavior is similar to IVectorFold.

source

Base.iterate Method
julia
iterate(iter)

Extends iterate methods from Base to allow forward and reverse iteration on both VectorFold and MVectorFold.

source

Base.length Method
julia
length(pf<:PatternFold)

Return the length of pf if unfolded.

source

Base.rand Method
julia
rand(pf<:PatternFold)

Returns a random value of pf as if it was unfolded.

source

Base.rand Method
julia
Base.rand(::Vector{AbstractVectorFold})
Extend the `Base.rand` function to `Vector{AbstractVectorFold}`.

source

Base.rand Method
julia
Base.rand(::Vector{IntervalsFold})

Extend the Base.rand function to Vector{IntervalsFold}.

source

PatternFolds.fold Method
julia
fold(v::V, depth = 0)

returns a suitable VectorFold, which when unfolded gives the Vector V.

source

PatternFolds.folds Method
julia
folds(<:PatternFold)

Return the number of folds. An infinite folded pattern returns 0.

source

PatternFolds.gap Method
julia
gap(<:PatternFold)

Return the gap between the starts of consecutive folds.

source

PatternFolds.make_vector_fold Function
julia
make_vector_fold(pattern, gap, fold, kind = :mutable)

A dispatcher to construct a folded vector. The kind of vector can be set to either :mutable (default) or :immutable. The default is faster in most cases but it depends on the pattern, gap, and fold parameters. For critical code, it is recommended to benchmark both options.

source

PatternFolds.pattern Method
julia
pattern(vf, index)

Return the element at index in the original pattern.

source

PatternFolds.pattern Method
julia
pattern(<:PatternFold)

Return the pattern of any PatternFold. The pattern defines the occurrences of the first fold.

source

PatternFolds.pattern_length Method
julia
pattern_length(pf<:PatternFold)

Return the length of the basic pattern of pf.

source

PatternFolds.reset_pattern! Method
julia
reset_pattern!(<:PatternFold)

Reset the unfolded pattern to the first fold.

source

PatternFolds.set_fold! Function
julia
set_fold!(mvf::VectorFold, new_fold = mvf.current + 1)

Set the unfolded pattern to new_fold. By default move the next fold after current.

source

PatternFolds.unfold Method
julia
unfold(vf::VectorFold; from=1, to=folds(vf))

Construct the unfolded version of vf (with the same type as pattern(vf)) based. Please note that using an iterator on vf avoid memory allocation, which is not the case of unfold.

source