-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Herb-AI/uniform-solver
Move iteration out of the UniformSolver (PR 1/2)
- Loading branch information
Showing
12 changed files
with
171 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
Simple stack that can only increase in size. | ||
Supports backtracking by decreasing the size to the saved size. | ||
""" | ||
struct StateStack{T} | ||
vec::Vector{T} | ||
size::StateInt | ||
end | ||
|
||
""" | ||
function StateStack{T}(sm::AbstractStateManager) where T | ||
Create an empty StateStack supporting elements of type T | ||
""" | ||
function StateStack{T}(sm::AbstractStateManager) where T | ||
return StateStack{T}(Vector{T}(), StateInt(sm, 0)) | ||
end | ||
|
||
""" | ||
function StateStack{T}(sm::AbstractStateManager, vec::Vector{T}) where T | ||
Create a StateStack for the provided `vec` | ||
""" | ||
function StateStack{T}(sm::AbstractStateManager, vec::Vector{T}) where T | ||
return StateStack{T}(vec, StateInt(sm, length(vec))) | ||
end | ||
|
||
""" | ||
function Base.push!(stack::StateStack, item) | ||
Place an `item` on top of the `stack`. | ||
""" | ||
function Base.push!(stack::StateStack, item) | ||
increment!(stack.size) | ||
if length(stack.vec) > size(stack) | ||
stack.vec[size(stack)] = item | ||
else | ||
push!(stack.vec, item) | ||
end | ||
end | ||
|
||
""" | ||
function Base.size(stack::StateStack) | ||
Get the current size of the `stack`. | ||
""" | ||
function Base.size(stack::StateStack)::Int | ||
return get_value(stack.size) | ||
end | ||
|
||
""" | ||
function Base.collect(stack::StateStack) | ||
Return the internal `Vector` representation of the `stack`. | ||
!!! warning: | ||
The returned vector is read-only. | ||
""" | ||
function Base.collect(stack::StateStack) | ||
return stack.vec[1:size(stack)] | ||
end | ||
|
||
""" | ||
function Base.in(stack::StateStack, value)::Bool | ||
Checks whether the `value` is in the `stack`. | ||
""" | ||
function Base.in(stack::StateStack, value)::Bool | ||
return value ∈ stack.vec[1:size(stack)] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.