Class: Tupelo::Client::SimpleTuplespace
- Defined in:
- lib/tupelo/client/tuplespace.rb
Overview
Simplest fully functional tuplespace. Not efficient for large spaces.
Instance Method Summary collapse
- #delete_once(elt) ⇒ Object
- #find_distinct_matches_for(templates) ⇒ Object
- #find_match_for(template, distinct_from: []) ⇒ Object
- #transaction(inserts: [], deletes: [], tick: nil) ⇒ Object
Instance Method Details
#delete_once(elt) ⇒ Object
6 7 8 9 10 |
# File 'lib/tupelo/client/tuplespace.rb', line 6 def delete_once elt if i=index(elt) delete_at i end end |
#find_distinct_matches_for(templates) ⇒ Object
22 23 24 25 26 |
# File 'lib/tupelo/client/tuplespace.rb', line 22 def find_distinct_matches_for templates templates.inject([]) do |tuples, template| tuples << find_match_for(template, distinct_from: tuples) end end |
#find_match_for(template, distinct_from: []) ⇒ Object
28 29 30 31 32 |
# File 'lib/tupelo/client/tuplespace.rb', line 28 def find_match_for template, distinct_from: [] find do |tuple| template === tuple and not distinct_from.any? {|t| t.equal? tuple} end end |
#transaction(inserts: [], deletes: [], tick: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/tupelo/client/tuplespace.rb', line 12 def transaction inserts: [], deletes: [], tick: nil deletes.each do |tuple| delete_once tuple or raise "bug" end inserts.each do |tuple| insert tuple.freeze ## freeze recursively end end |