Class: Blodsband::Riak::Sset
Overview
A concurrent set. Named Sset to avoid colliding with ruby standard Set.
Instance Attribute Summary
Attributes inherited from List
Instance Method Summary collapse
- #delete(v) ⇒ Object
-
#include?(v) ⇒ true, false
Whether this set includes v.
-
#intersect(sset) ⇒ Set<Object>
A ruby Set containing the intersection of this Sset and the argument.
-
#retain(values) ⇒ Set<Object>
The values that are included in this set.
-
#to_set ⇒ Set<Object>
This Sset as a ruby Set.
Methods inherited from List
#append, #append_and_get_element, #append_element_after, #delete_element, #each, #empty?, #exists?, #first, #initialize, #last, #pop, #prepend, #prepend_element_before, #reload, #save, #shift, #size, #stack_each, #to_a, #to_s, #validate
Constructor Details
This class inherits a constructor from Blodsband::Riak::List
Instance Method Details
#delete(v) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/blodsband/riak/sset.rb', line 58 def delete(v) element_key = bucket.get(key_for(v)) if element_key.nil? nil else element = Element.find(self, element_key) element.delete element.value end end |
#include?(v) ⇒ true, false
Returns whether this set includes v.
16 17 18 |
# File 'lib/blodsband/riak/sset.rb', line 16 def include?(v) !bucket.get(key_for(v)).nil? end |
#intersect(sset) ⇒ Set<Object>
Returns a ruby Set containing the intersection of this Blodsband::Riak::Sset and the argument.
47 48 49 50 51 52 53 |
# File 'lib/blodsband/riak/sset.rb', line 47 def intersect(sset) if size > sset.size retain(sset.to_a) else sset.retain(to_a) end end |
#retain(values) ⇒ Set<Object>
Returns the values that are included in this set.
25 26 27 28 29 30 31 32 33 |
# File 'lib/blodsband/riak/sset.rb', line 25 def retain(values) map = values.inject({}) do |sum, value| sum.merge(key_for(value) => value) end included = bucket.has_many?(map.keys) Set.new(map.reject do |k, v| !included.include?(k) end.values) end |
#to_set ⇒ Set<Object>
Returns this Blodsband::Riak::Sset as a ruby Set.
38 39 40 |
# File 'lib/blodsband/riak/sset.rb', line 38 def to_set Set.new(to_a) end |