Pf::BidiMap(K, V)
Inherits Enumerable / Struct / Value / Object
A thread-safe, persistent, unordered bidirectional map.
See also: Map.
Constructors
Returns a map with mappings from an enumerable of key-value pairs.
Returns a new empty BidiMap.
bidi = Pf::BidiMap(String, Int32).new
bidi.empty? # => true
Class methods
Instance methods
Returns a copy of self that contains the mapping of key to
value. and of value to key.
Supports value equality.
bidi = Pf::BidiMap(String, Int32).new
bidi.assoc("hello", 100) # => Pf::BidiMap{"hello" <=> 100}
Returns a copy of self which is guaranteed not to have a mapping
with the given key.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.dissoc_by_key(:foo) # => Pf::BidiMap{:bar <=> 200}
Returns a copy of self which is guaranteed not to have a mapping
with the given value.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.dissoc_by_value(200) # => Pf::BidiMap{:foo <=> 100}
Returns true if this map contains a mapping with the given value.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.has_key_for?(100) # => true
bidi.has_key_for?(200) # => true
bidi.has_key_for?(300) # => false
Returns true if this map contains a mapping with the given key.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.has_value_for?(:foo) # => true
bidi.has_value_for?(:bar) # => true
bidi.has_value_for?(:baz) # => false
Returns the key mapped to the given value. If there is no such
key raises KeyError.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.key_for(100) # => :foo
bidi.key_for(200) # => :bar
bidi.key_for(300) # raises KeyError
Returns the key mapped to the given value, or nil if there is no such key.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.key_for?(100) # => :foo
bidi.key_for?(200) # => :bar
bidi.key_for?(300) # => nil
Returns true if self and other refer to the same map in memory.
Due to the way BidiMap is implemented, this method can be used
as a cheap way to detect changes.
bidi1 = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi2 = bidi1.assoc(:foo, 100)
bidi1.same?(bidi2) # => true
Returns the value mapped to the given key. If there is no such
value raises KeyError.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.value_for(:foo) # => 100
bidi.value_for(:bar) # => 200
bidi.value_for(:baz) # raises KeyError
Returns the value mapped to the given key, or nil if there is no such value.
bidi = Pf::BidiMap.assoc(:foo, 100).assoc(:bar, 200)
bidi.value_for?(:foo) # => 100
bidi.value_for?(:bar) # => 200
bidi.value_for?(:baz) # => nil