Skip to content

Commit

Permalink
Convenience function for accessing elements in piecewise quadratic.
Browse files Browse the repository at this point in the history
  • Loading branch information
olof3 committed Sep 6, 2017
1 parent f172a18 commit e948bb6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/types/PiecewiseQuadratic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ start{T}(pwq::PiecewiseQuadratic{T}) = pwq.next
done{T}(pwq::PiecewiseQuadratic{T}, iterstate::Nullable{PiecewiseQuadratic{T}}) = isnull(iterstate)
next{T}(pwq::PiecewiseQuadratic{T}, iterstate::Nullable{PiecewiseQuadratic{T}}) = (unsafe_get(iterstate), unsafe_get(iterstate).next)

# For trouble-shooting etc.
function getindex::dev.PiecewiseQuadratic, n::Int64)
if n <= 0
error("Attempted to access index <= 0 in piecewise quadratic.")
end

λ = get.next)
for k=1:n-1
λ = get.next)
end
return λ
end


function insert{T}(pwq::PiecewiseQuadratic{T}, p::QuadraticPolynomial, left_endpoint)
pwq.next = PiecewiseQuadratic(p, left_endpoint, pwq.next)
return pwq.next
Expand Down

0 comments on commit e948bb6

Please sign in to comment.