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.

Initializers

  • Create an empty Bimap.

    Declaration

    Swift

    @inlinable
    public init()
  • Create an empty Bimap reserving the amount of memory needed to store the given minimumCapacity of key-value pairs.

    Declaration

    Swift

    @inlinable
    public init(minimumCapacity: Int)
  • Create a Bimap from a dictionary.

    Declaration

    Swift

    @inlinable
    public init(_ elements: Dictionary<Key, Value>)
  • Create a Bimap from the given sequence of key-value pairs.

    Declaration

    Swift

    @inlinable
    public init<S>(_ sequence: S) where S : Sequence, S.Element == (Key, Value)
  • Create a Bimap from the given collection of key-value pairs.

    Declaration

    Swift

    @inlinable
    public init<C>(_ collection: C) where C : Collection, C.Element == (Key, Value)

Computed Properties

  • 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

    true if there are no key-value pairs contained herein. Otherwise, false.

  • Declaration

    Swift

    @inlinable
    public var keys: AnyCollection<Key> { get }

    Return Value

    A collection of Key values.

  • Declaration

    Swift

    @inlinable
    public var values: AnyCollection<Value> { get }

    Return Value

    A collection of Value values.

Subscripts

  • Get and set the Key for the given value.

    Declaration

    Swift

    @inlinable
    public subscript(value value: Value) -> Key? { get set }
  • Get and set the Value for the given key.

    Declaration

    Swift

    @inlinable
    public subscript(key key: Key) -> Value? { get set }

Instance Methods

  • Updates the current value to the given value for the given key.

    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 key for the given value.

    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 -> Bimap

    Return Value

    A Bimap with the keys and values filtered by the given isIncluded.

  • 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 minimumCapacity of key-value pairs.

    Declaration

    Swift

    @inlinable
    public mutating func reserveCapacity(_ minimumCapacity: Int)

CollectionWrapping

  • Declaration

    Swift

    @inlinable
    public var base: [Key : Value] { get }

    Return Value

    The [Key: Value] base for Collection operations.

ExpressibleByDictionaryLiteral Protocol Conformance

  • 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 : Hashable

    Return Value

    A Bimap between lhs.Key and rhs.Value by 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 : Hashable

    Return Value

    A Bimap between Key and other.Value by using the output of one Bimap as the input of the other.