Class: FrugalTimeout::SortedQueue
- Inherits:
-
Object
- Object
- FrugalTimeout::SortedQueue
- Includes:
- MonitorMixin
- Defined in:
- lib/frugal_timeout.rb
Overview
{{{1 SortedQueue
Instance Method Summary collapse
- #each(&b) ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(storage = []) ⇒ SortedQueue
constructor
A new instance of SortedQueue.
- #last ⇒ Object
- #push(*args) ⇒ Object (also: #<<)
- #reject!(&b) ⇒ Object
- #reject_and_get!(&b) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(storage = []) ⇒ SortedQueue
Returns a new instance of SortedQueue.
208 209 210 211 |
# File 'lib/frugal_timeout.rb', line 208 def initialize storage=[] super() @array, @unsorted = storage, false end |
Instance Method Details
#each(&b) ⇒ Object
213 214 215 |
# File 'lib/frugal_timeout.rb', line 213 def each &b synchronize { @array.each &b } end |
#empty? ⇒ Boolean
217 218 219 |
# File 'lib/frugal_timeout.rb', line 217 def empty? synchronize { @array.empty? } end |
#first ⇒ Object
221 222 223 |
# File 'lib/frugal_timeout.rb', line 221 def first synchronize { @array.first } end |
#last ⇒ Object
225 226 227 228 229 230 |
# File 'lib/frugal_timeout.rb', line 225 def last synchronize { sort! @array.last } end |
#push(*args) ⇒ Object Also known as: <<
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/frugal_timeout.rb', line 232 def push *args synchronize { args.each { |arg| case @array.first <=> arg when -1, 0, nil @array.push arg when 1 @array.unshift arg end } @unsorted = true } end |
#reject!(&b) ⇒ Object
247 248 249 250 251 252 |
# File 'lib/frugal_timeout.rb', line 247 def reject! &b synchronize { sort! @array.reject! &b } end |
#reject_and_get!(&b) ⇒ Object
254 255 256 257 258 259 260 261 262 |
# File 'lib/frugal_timeout.rb', line 254 def reject_and_get! &b res = [] reject! { |el| break unless b.call el res << el } res end |
#size ⇒ Object
264 265 266 |
# File 'lib/frugal_timeout.rb', line 264 def size synchronize { @array.size } end |