Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ValueHistories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export
MultivalueHistory,
MVHistory,
increment!,
@trace
@trace,
drop!

include("abstract.jl")
include("history.jl")
Expand Down
15 changes: 15 additions & 0 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ Base.push!(history::UnivalueHistory, iteration, value) =
# get(history::ValueHistory) = error()
# first(history::ValueHistory) = error()
# last(history::ValueHistory) = error()

"""
drop!(hist, it)

Deletes all values stored for iterations greater than `it`. If
`it>first(last(hist))` then it does nothing.
"""
function drop!(history::UnivalueHistory, it)
iter, vals = get(history)
n = findlast(x->x<=it, iter)
isnothing(n) && return last(iter)

resize!(history, n)
return history.lastiter
end
9 changes: 9 additions & 0 deletions src/history.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ function Base.show(io::IO, history::History{I,V}) where {I,V}
print(io, " * length: $(length(history))")
end

function Base.resize!(history::History, n)
iter, vals = get(history)
resize!(iter, n)
resize!(vals, n)
history.lastiter = last(iter)

history
end

"""
increment!(trace, iter, val)

Expand Down
14 changes: 14 additions & 0 deletions src/mvhistory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,17 @@ function increment!(trace::MVHistory{<:History}, key::Symbol, iter::Number, val)
end
push!(trace, key, iter, val)
end

"""
drop!(hist, it)

Deletes all values stored for iterations greater than `it` for all
keys stored in `hist`.
"""
function drop!(history::MVHistory, it)
lastiters = Int[]
for hist=values(history.storage)
push!(lastiters, drop!(hist, it))
end
maximum(lastiters)
end
12 changes: 12 additions & 0 deletions src/qhistory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ function Base.get(history::QHistory{I,V}) where {I,V}
karray, varray
end

function Base.resize!(history::QHistory, n)
@assert n <= length(history)

storage = history.storage
while n<length(storage)
it, val = pop!(storage)
end
history.lastiter = first(last(history))

history
end

Base.print(io::IO, history::QHistory{I,V}) where {I,V} = print(io, "$(length(history)) elements {$I,$V}")

function Base.show(io::IO, history::QHistory{I,V}) where {I,V}
Expand Down