Class: DSPy::DeepSearch::GapQueue
- Inherits:
-
Object
- Object
- DSPy::DeepSearch::GapQueue
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/deep_search/gap_queue.rb
Defined Under Namespace
Classes: Empty
Instance Method Summary collapse
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(item) ⇒ Object
-
#initialize ⇒ GapQueue
constructor
A new instance of GapQueue.
- #size ⇒ Object
Constructor Details
#initialize ⇒ GapQueue
Returns a new instance of GapQueue.
13 14 15 16 |
# File 'lib/dspy/deep_search/gap_queue.rb', line 13 def initialize @queue = T.let([], T::Array[T.untyped]) @seen = T.let(Set.new, T::Set[T.untyped]) end |
Instance Method Details
#dequeue ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/dspy/deep_search/gap_queue.rb', line 27 def dequeue raise Empty, "No items remaining in gap queue" if @queue.empty? item = @queue.shift @seen.delete(item) item end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/dspy/deep_search/gap_queue.rb', line 41 def empty? @queue.empty? end |
#enqueue(item) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/dspy/deep_search/gap_queue.rb', line 19 def enqueue(item) return if @seen.include?(item) @queue << item @seen << item end |
#size ⇒ Object
36 37 38 |
# File 'lib/dspy/deep_search/gap_queue.rb', line 36 def size @queue.length end |