Class: Rinda::TupleBag Private
- Inherits:
-
Object
- Object
- Rinda::TupleBag
- Defined in:
- lib/pione/patch/rinda-patch.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: DataTupleBin, DomainTupleBin, HashTupleBin, TupleBin
Instance Method Summary collapse
- #[](ident) ⇒ Object private
-
#all_tuples ⇒ Object
private
Returns all tuples in the bag.
- #bin_class(key) ⇒ Object private
- #data_size ⇒ Object private
- #delete(tuple) ⇒ Object private
- #delete_unless_alive ⇒ Object private
- #find(template) ⇒ Object private
- #find_all(template) ⇒ Object private
- #find_template(tuple) ⇒ Object private
- #finished_size ⇒ Object private
-
#initialize ⇒ TupleBag
constructor
private
A new instance of TupleBag.
- #orig_find ⇒ Object private
- #orig_find_all ⇒ Object private
- #prepare_table(key) ⇒ Object private
- #push(tuple) ⇒ Object private
-
#set_special_bin(special_bin) ⇒ Object
private
Sets special bin class table by identifier.
- #task_size ⇒ Object private
- #working_size ⇒ Object private
Constructor Details
#initialize ⇒ TupleBag
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TupleBag.
384 385 386 387 388 389 |
# File 'lib/pione/patch/rinda-patch.rb', line 384 def initialize @hash = {} @mutex = Mutex.new @enum = enum_for(:each_entry) @special_bin = {} end |
Instance Method Details
#[](ident) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
391 392 393 |
# File 'lib/pione/patch/rinda-patch.rb', line 391 def [](ident) @hash[ident] end |
#all_tuples ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all tuples in the bag.
432 433 434 |
# File 'lib/pione/patch/rinda-patch.rb', line 432 def all_tuples @mutex.synchronize{@hash.values}.map{|bin| bin.elements}.flatten end |
#bin_class(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
421 422 423 424 |
# File 'lib/pione/patch/rinda-patch.rb', line 421 def bin_class(key) return TupleBin unless @special_bin return @special_bin.has_key?(key) ? @special_bin[key] : TupleBin end |
#data_size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
495 496 497 |
# File 'lib/pione/patch/rinda-patch.rb', line 495 def data_size @mutex.synchronize{@hash[:data]}.size rescue 0 end |
#delete(tuple) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
406 407 408 409 410 411 412 413 |
# File 'lib/pione/patch/rinda-patch.rb', line 406 def delete(tuple) key = bin_key(tuple) bin = @mutex.synchronize {@hash[key]} return nil unless bin @mutex.synchronize {bin.delete(tuple)} @mutex.synchronize {@hash.delete(key) if bin.empty?} return tuple end |
#delete_unless_alive ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/pione/patch/rinda-patch.rb', line 466 def delete_unless_alive deleted = [] @mutex.synchronize do @hash.each do |key, bin| bin.delete_if do |tuple| if tuple.alive? false else deleted.push(tuple) true end end end end deleted end |
#find(template) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/pione/patch/rinda-patch.rb', line 436 def find(template) key = bin_key(template) if @special_bin[key] prepare_table(key) @mutex.synchronize{@hash[key]}.find(template) do |tuple| tuple.alive? && template.match(tuple) end else orig_find(template) end end |
#find_all(template) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/pione/patch/rinda-patch.rb', line 448 def find_all(template) key = bin_key(template) if @special_bin[key] prepare_table(key) @mutex.synchronize{@hash[key]}.find_all(template) do |tuple| tuple.alive? && template.match(tuple) end else orig_find_all(template) end end |
#find_template(tuple) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
460 461 462 463 464 |
# File 'lib/pione/patch/rinda-patch.rb', line 460 def find_template(tuple) @enum.find do |template| template.alive? && template.match(tuple) end end |
#finished_size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
491 492 493 |
# File 'lib/pione/patch/rinda-patch.rb', line 491 def finished_size @mutex.synchronize{@hash[:finished]}.size rescue 0 end |
#orig_find ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
426 |
# File 'lib/pione/patch/rinda-patch.rb', line 426 alias :orig_find :find |
#orig_find_all ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
427 |
# File 'lib/pione/patch/rinda-patch.rb', line 427 alias :orig_find_all :find_all |
#prepare_table(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
415 416 417 418 419 |
# File 'lib/pione/patch/rinda-patch.rb', line 415 def prepare_table(key) unless @mutex.synchronize {@hash[key]} @mutex.synchronize {@hash[key] = bin_class(key).new} end end |
#push(tuple) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
400 401 402 403 404 |
# File 'lib/pione/patch/rinda-patch.rb', line 400 def push(tuple) key = bin_key(tuple) prepare_table(key) @mutex.synchronize {@hash[key].add(tuple)} end |
#set_special_bin(special_bin) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets special bin class table by identifier.
396 397 398 |
# File 'lib/pione/patch/rinda-patch.rb', line 396 def set_special_bin(special_bin) @special_bin = special_bin end |
#task_size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
483 484 485 |
# File 'lib/pione/patch/rinda-patch.rb', line 483 def task_size @mutex.synchronize{@hash[:task]}.size rescue 0 end |
#working_size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
487 488 489 |
# File 'lib/pione/patch/rinda-patch.rb', line 487 def working_size @mutex.synchronize{@hash[:working]}.size rescue 0 end |