Bag
public struct Bag<T> : CustomDebugStringConvertible
Data structure that represents a bag of elements typed T.
Single element can be stored multiple times.
Time and space complexity of insertion an deletion is O(n).
It is suitable for storing small number of elements.
-
Type of identifier for inserted elements.
Declaration
Swift
public typealias KeyType = BagKey -
Creates new empty
Bag.Declaration
Swift
public init() -
Inserts
valueinto bag.Declaration
Swift
public mutating func insert(element: T) -> BagKeyParameters
elementElement to insert.
Return Value
Key that can be used to remove element from bag.
-
Declaration
Swift
public var count: IntReturn Value
Number of elements in bag.
-
Removes all elements from bag and clears capacity.
Declaration
Swift
public mutating func removeAll() -
Removes element with a specific
keyfrom bag.Declaration
Swift
public mutating func removeKey(key: BagKey) -> T?Parameters
keyKey that identifies element to remove from bag.
Return Value
Element that bag contained, or nil in case element was already removed.
-
A textual representation of
self, suitable for debugging.Declaration
Swift
public var debugDescription : String
-
Enumerates elements inside the bag.
Declaration
Swift
public func forEach(@noescape action: (T) -> Void)Parameters
actionEnumeration closure.
-
Dispatches
eventto app observers contained inside bag.Declaration
Swift
public func on(event: Event<T.E>)Parameters
actionEnumeration closure.
Bag Struct Reference