Class: Farce::Transaction::TreeMap
- Inherits:
-
Abstract::TreeMap
- Object
- Abstract::Map
- Abstract::TreeMap
- Farce::Transaction::TreeMap
- Defined in:
- lib/farce/transaction/tree_map.rb
Overview
A TreeMap that is part of a transaction.
Constant Summary
Constants included from MapOperations
Instance Method Summary collapse
- #compare_and_set(key, expected, replacement, mode: nil) ⇒ BasicObject
-
#first_key ⇒ BasicObject?
Return the smallest key according to the map's ordering.
-
#getkey(key) ⇒ BasicObject?
abstract
Return the stored key that matches a lookup key.
-
#keys ⇒ Array<BasicObject>
Return the keys currently stored in the map.
-
#last_key ⇒ BasicObject?
Return the largest key according to the map's ordering.
-
#pop ⇒ Array(BasicObject, BasicObject)?
Remove and return the entry with the largest key according to the map's ordering.
-
#shift ⇒ Array(BasicObject, BasicObject)?
Remove and return the entry with the smallest key according to the map's ordering.
- #swap(key, value, mode: nil) ⇒ BasicObject
Methods included from Unshareable
#initialize, #ractor_shareable?
Methods inherited from Abstract::TreeMap
#[], #[]=, #clear, #compare_keys_by_identity?, #compare_values_by_identity?, #delete, #each, #each_key, #each_value, #empty?, #fetch, #initialize, #key?, #length, #shareable_keys?, #size, #store_if_absent, #values
Methods included from Abstract::DuplicableMap
#compact, #compact_blank, #deep_dup, #duplicable?, #except, #flatten, #invert, #merge, #reject, #reverse_merge, #select, #slice, #stringify_keys, #symbolize_keys, #to_proc, #transform_keys, #transform_values, #with_indifferent_access
Methods inherited from Abstract::Map
#[], #[]=, #as_extended_json, #as_json, #assert_valid_keys, #assoc, #bson_type, #clear, #compare_by_identity?, #compare_keys_by_identity?, #compare_values_by_identity?, #deconstruct_keys, #delete, #dig, #each, #each_key, #each_pair, #each_value, #empty?, #fetch, #fetch_values, #has_key?, #key, #key?, #length, #rassoc, #shareable_keys?, #shareable_values?, #size, #store, #store_if_absent, #to_a, #to_bson, #to_bson_normalized_value, #to_cbor, #to_h, #to_hash, #to_json, #to_msgpack, #to_query, #to_s, #value?, #values_at, #weak_keys?, #weak_values?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Farce::Transaction::Wrapper
Instance Method Details
#compare_and_set(key, expected, replacement, mode: nil) ⇒ BasicObject
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/farce/transaction/tree_map.rb', line 48 def compare_and_set(key, expected, replacement, mode: nil) write do canonical = prepare(key) next compared(false) unless @working.key?(canonical) current = @working[canonical] matches = @manager ? matches?(current, expected, identity: false) : current == expected next compared(false) unless matches store_value(canonical, wrap(replacement, mode:)) true end end |
#first_key ⇒ BasicObject?
Return the smallest key according to the map's ordering.
13 |
# File 'lib/farce/transaction/tree_map.rb', line 13 def first_key = access { @working.first_key } |
#getkey(key) ⇒ BasicObject?
Return the stored key that matches a lookup key.
21 |
# File 'lib/farce/transaction/tree_map.rb', line 21 def getkey(key) = access { @working.getkey(prepare(key)) } |
#keys ⇒ Array<BasicObject>
Return the keys currently stored in the map. The result is frozen and ordered from smallest to largest key.
25 |
# File 'lib/farce/transaction/tree_map.rb', line 25 def keys = access { @working.each.map { |key, _| key }.freeze } |
#last_key ⇒ BasicObject?
Return the largest key according to the map's ordering.
17 |
# File 'lib/farce/transaction/tree_map.rb', line 17 def last_key = access { @working.last_key } |
#pop ⇒ Array(BasicObject, BasicObject)?
Remove and return the entry with the largest key according to the map's ordering.
29 |
# File 'lib/farce/transaction/tree_map.rb', line 29 def pop = write { public_pair(@working.pop) } |
#shift ⇒ Array(BasicObject, BasicObject)?
Remove and return the entry with the smallest key according to the map's ordering.
33 |
# File 'lib/farce/transaction/tree_map.rb', line 33 def shift = write { public_pair(@working.shift) } |
#swap(key, value, mode: nil) ⇒ BasicObject
37 38 39 40 41 42 43 44 |
# File 'lib/farce/transaction/tree_map.rb', line 37 def swap(key, value, mode: nil) write do canonical = prepare(key) previous = unwrap_stored(@working[canonical]) store_value(canonical, wrap(value, mode:)) previous end end |