PatternFolds.jl
Documentation for PatternFolds.jl.
PatternFolds.PatternFold Type
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 bothlength(::P)andrand(::P)methods must be availablegap::TSfolds::int
Finally one can redefine PatternFold
PatternFold{T} = Union{AbstractVectorFold{T}, IntervalsFold{T}, MyFold{T[,P]}}PatternFolds.AbstractVectorFold Type
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 bothlength(::P)andrand(::P)methods must be availablegap::Tfolds::int
PatternFolds.IVectorFold Type
VectorFold{T,V <: AbstractVector{T}}A folded vector structure that extends the methods of AbstractVector to a folded structure.
PatternFolds.VectorFold Type
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.
Base.iterate Method
iterate(iter)Extends iterate methods from Base to allow forward and reverse iteration on both VectorFold and MVectorFold.
Base.rand Method
Base.rand(::Vector{AbstractVectorFold})
Extend the `Base.rand` function to `Vector{AbstractVectorFold}`.Base.rand Method
Base.rand(::Vector{IntervalsFold})Extend the Base.rand function to Vector{IntervalsFold}.
PatternFolds.fold Method
fold(v::V, depth = 0)returns a suitable VectorFold, which when unfolded gives the Vector V.
PatternFolds.folds Method
folds(<:PatternFold)Return the number of folds. An infinite folded pattern returns 0.
PatternFolds.gap Method
gap(<:PatternFold)Return the gap between the starts of consecutive folds.
PatternFolds.make_vector_fold Function
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.
PatternFolds.pattern Method
pattern(vf, index)Return the element at index in the original pattern.
PatternFolds.pattern Method
pattern(<:PatternFold)Return the pattern of any PatternFold. The pattern defines the occurrences of the first fold.
PatternFolds.pattern_length Method
pattern_length(pf<:PatternFold)Return the length of the basic pattern of pf.
PatternFolds.reset_pattern! Method
reset_pattern!(<:PatternFold)Reset the unfolded pattern to the first fold.
PatternFolds.set_fold! Function
set_fold!(mvf::VectorFold, new_fold = mvf.current + 1)Set the unfolded pattern to new_fold. By default move the next fold after current.
PatternFolds.unfold Method
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.