Skip to content

UnorderedSparseSet

ctreffs edited this page Oct 7, 2020 · 4 revisions

UnorderedSparseSet

An (unordered) sparse set.

public struct UnorderedSparseSet<Element, Key: Hashable & Codable>
  • Element: the element (instance) to store.

  • Key: the unique, hashable datastructure to use as a key to retrieve an element from the sparse set.

See https://github.com/bombela/sparseset/blob/master/src/lib.rs for a reference implementation.

Inheritance

Equatable, Sequence

Initializers

init()

public init()

Properties

count

var count: Int

isEmpty

var isEmpty: Bool

first

var first: Element?

Methods

contains(_:)

@inlinable public func contains(_ key: Key) -> Bool

insert(_:at:)

Inset an element for a given key into the set in O(1). Elements at previously set keys will be replaced.

@discardableResult public func insert(_ element: Element, at key: Key) -> Bool

Parameters

  • element: the element
  • key: the key

Returns

true if new, false if replaced.

get(at:)

Get the element for the given key in O(1).

@inlinable public func get(at key: Key) -> Element?

Parameters

  • key: the key

Returns

the element or nil of key not found.

get(unsafeAt:)

@inlinable public func get(unsafeAt key: Key) -> Element

remove(at:)

Removes the element entry for given key in O(1).

@discardableResult public func remove(at key: Key) -> Element?

Parameters

  • key: the key

Returns

removed value or nil if key not found.

removeAll(keepingCapacity:)

@inlinable public func removeAll(keepingCapacity: Bool = false)

makeIterator()

public func makeIterator() -> ElementIterator
Clone this wiki locally