This small package contains:
-
cavity!andcavity: Functions to compute theNall-but-one operations betweenNelements in timeO(N). The operation is arbitrary and needs only to be associative. This is equivalent to computing[reduce(op, (src[j] for j in eachindex(src) if i != j); init) for i in eachindex(src)]which however would needN*(N-1)evaluations ofop. Ifopis commutative with exact inverseinvop, you could obtain the same result ofcavity(src, op, init), also in timeO(N), withinvop.(reduce(op, src; init), src). -
Accumulator: Ana = Accumulator(v::AbstractVector)works as a replacement forvwith extra tracking computations.- Construction of
arequires timeO(N)whereN == length(v). sum(a)requires timeO(1).cumsum(a),cavity(a)require timeO(1)and return respectively aCumSumandCavityobjects that are linked toa.
- Construction of
-
c::CumSum(a::Accumulator): keeps a live-updatedcumsumofa.- Create it with
c = cumsum(a::Accumulator) - Retrieval
c[i]takes timeO(log N). collect(c)takes timeO(N)searchsortedfirst(r, c)takes timeO(log N)
- Create it with
-
c::Cavity(a::Accumulator): keeps a live-updatedcavityofa.- Create it with
c = cavity(a::Accumulator). - Retrieval
c[i]takes timeO(log N). collect(c)takes timeO(N)(but is slower thancavity(v::Vector)).
- Create it with