Class: Farce::WeakSet
- Inherits:
-
Abstract::WeakSet
- Object
- Abstract::Collection
- Abstract::Set
- Abstract::WeakSet
- Farce::WeakSet
- Includes:
- Shareable::Delegated
- Defined in:
- lib/farce/weak_set.rb
Overview
A Ractor-shareable concurrent set that retains prepared elements weakly. Elements support :raise (the default), :make_shareable, and :dedup. Membership refers to the prepared element itself. Lookup and deletion do not freeze or deduplicate their arguments. Already-shareable elements pass through unchanged, as with other mode-backed containers.
With :dedup, the stored canonical element can differ from the input. Keeping only the input alive may not keep that element alive. Callers are responsible for retaining elements they need. Both add and add? retain their usual set return values rather than returning the stored element.
Instance Method Summary collapse
-
#delete(element) ⇒ self
Remove an element and return self.
-
#delete?(element) ⇒ self?
Remove an element and return self, or nil if it was absent.
-
#include?(element) ⇒ Boolean
(also: #member?, #===)
Return whether an element is present.
-
#mode ⇒ Symbol
The default mode used to prepare elements for insertion.
Methods included from Shareable
#initialize, #ractor_shareable?
Methods inherited from Abstract::Set
#<=>, #==, #^, #add, #add?, #as_extended_json, #as_json, #bson_type, #classify, #clear, #compact_blank, #compact_blank!, #compare_by_identity?, #deep_dup, #delete_if, #difference, #disjoint?, #divide, #duplicable?, #each, #eql?, #excluding, #flatten, #hash, #including, #initialize, #intersect?, #intersection, #keep_if, #merge, #proper_subset?, #proper_superset?, #reject, #reject!, #select, #select!, #size, #subset?, #subtract, #superset?, #to_a, #to_bson, #to_bson_normalized_value, #to_cbor, #to_json, #to_msgpack, #to_param, #to_query, #to_set, #union, #weak?
Methods inherited from Abstract::Collection
#<<, [], #clear, #compare_by_identity?, #count, #each, #empty?, #filter, #join, #length, #reject, #select, #size, #to_a, #to_s
Methods included from Internal::Copyable
Instance Method Details
#delete(element) ⇒ self
Remove an element and return self.
40 41 42 43 44 45 |
# File 'lib/farce/weak_set.rb', line 40 def delete(element) check_frozen! key = lookup_key(normalize_element(element)) @map.delete(key) unless MISSING_KEY.equal?(key) self end |
#delete?(element) ⇒ self?
Remove an element and return self, or nil if it was absent.
48 49 50 51 52 |
# File 'lib/farce/weak_set.rb', line 48 def delete?(element) # rubocop:disable Naming/PredicateMethod check_frozen! key = lookup_key(normalize_element(element)) self unless MISSING_KEY.equal?(key) || !@map.delete(key) end |
#include?(element) ⇒ Boolean Also known as: member?, ===
Return whether an element is present.
32 33 34 35 |
# File 'lib/farce/weak_set.rb', line 32 def include?(element) key = lookup_key(normalize_element(element)) !MISSING_KEY.equal?(key) && @map.key?(key) end |
#mode ⇒ Symbol
The default mode used to prepare elements for insertion.
29 |
# File 'lib/farce/weak_set.rb', line 29 def mode = @manager.mode |