Bimap
public struct Bimap<Key, Value> : Hashable where Key : Hashable, Value : Hashable
extension Bimap: DictionaryProtocol
extension Bimap: CollectionWrapping
extension Bimap: ExpressibleByDictionaryLiteral
Dictionary-like structure which allows O(1) access from Key to Value as well as from Value
to Key.
-
Create an empty
Bimap.Declaration
Swift
@inlinable public init() -
Create an empty
Bimapreserving the amount of memory needed to store the givenminimumCapacityof key-value pairs.Declaration
Swift
@inlinable public init(minimumCapacity: Int) -
Create a
Bimapfrom a dictionary.Declaration
Swift
@inlinable public init(_ elements: Dictionary<Key, Value>) -
Create a
Bimapfrom the givensequenceof key-value pairs.Declaration
Swift
@inlinable public init<S>(_ sequence: S) where S : Sequence, S.Element == (Key, Value) -
Create a
Bimapfrom the givencollectionof key-value pairs.Declaration
Swift
@inlinable public init<C>(_ collection: C) where C : Collection, C.Element == (Key, Value)
-
Declaration
Swift
@inlinable public var count: Int { get }Return Value
The amount of key-value pairs contained herein.
-
Declaration
Swift
@inlinable public var isEmpty: Bool { get }Return Value
trueif there are no key-value pairs contained herein. Otherwise,false. -
Declaration
Swift
@inlinable public var keys: AnyCollection<Key> { get }Return Value
A collection of
Keyvalues. -
Declaration
Swift
@inlinable public var values: AnyCollection<Value> { get }Return Value
A collection of
Valuevalues.
-
Get and set the
Keyfor the givenvalue.Declaration
Swift
@inlinable public subscript(value value: Value) -> Key? { get set } -
Get and set the
Valuefor the givenkey.Declaration
Swift
@inlinable public subscript(key key: Key) -> Value? { get set }
-
Updates the current value to the given
valuefor the givenkey.Declaration
Swift
@discardableResult @inlinable public mutating func updateValue(_ value: Value, forKey key: Key) -> Value?Return Value
The previous value for the given
key, if it existed. Otherwise,nil. -
Updates the current key to the given
keyfor the givenvalue.Declaration
Swift
@discardableResult @inlinable public mutating func updateKey(_ key: Key, forValue value: Value) -> Key?Return Value
The previous key for the given
value, if it existed. Otherwise,nil. -
Removes the value for the given
key.Declaration
Swift
@discardableResult @inlinable public mutating func removeValue(forKey key: Key) -> Value?Return Value
The previous value for the given
key, if it existed. Otherwise,nil. -
Removes the key for the given
value.Declaration
Swift
@discardableResult @inlinable public mutating func removeKey(forValue value: Value) -> Key?Return Value
The previous key for the given
value, if it existed. Otherwise,nil. -
Removes all key-value pairs, without releasing memory.
Declaration
Swift
@inlinable public mutating func removeAll(keepCapacity capacity: Bool = true) -
Declaration
Swift
@inlinable public func filter(_ isIncluded: ((key: Key, value: Value)) throws -> Bool) rethrows -> BimapReturn Value
A
Bimapwith the keys and values filtered by the givenisIncluded. -
Gets and sets the value for the
key.Declaration
Swift
@inlinable public subscript(key: Key) -> Value? { get set } -
Reserves the amount of memory needed to store the given
minimumCapacityof key-value pairs.Declaration
Swift
@inlinable public mutating func reserveCapacity(_ minimumCapacity: Int)
-
Declaration
Swift
@inlinable public var base: [Key : Value] { get }Return Value
The
[Key: Value]base forCollectionoperations.
-
Constructs a bimap using a dictionary literal.
Declaration
Swift
@inlinable public init(dictionaryLiteral elements: (Key, Value)...) -
Declaration
Swift
public static func * <Other>(lhs: Bimap, rhs: Bimap<Value, Other>) -> Bimap<Key, Other> where Other : HashableReturn Value
A
Bimapbetweenlhs.Keyandrhs.Valueby using the output of one as the input of the other. -
Declaration
Swift
public func compose<Other>(with other: Bimap<Value, Other>) -> Bimap<Key, Other> where Other : HashableReturn Value
A
BimapbetweenKeyandother.Valueby using the output of oneBimapas the input of the other.
View on GitHub
Install in Dash
Bimap Structure Reference