RangeReplaceableCollectionType

protocol RangeReplaceableCollectionType

A collection that supports replacement of an arbitrary subRange of elements with the elements of another collection.

Inheritance CollectionType, ExtensibleCollectionType, SequenceType, _CollectionType, _ExtensibleCollectionType, _SequenceType, _Sequence_Type View Protocol Hierarchy →
Associated Types
Generator : GeneratorType

A type that provides the sequence's iteration interface and encapsulates its iteration state.

Index : ForwardIndexType

A type that represents a valid position in the collection.

Valid indices consist of the position of every element and a "past the end" position that's not valid for use as a subscript.

_Element

A type that represents a valid position in the collection.

Valid indices consist of the position of every element and a "past the end" position that's not valid for use as a subscript.

Import import Swift

Initializers

init() Required

Create an empty instance

Declaration

init()

Declared In

_ExtensibleCollectionType

Instance Variables

var endIndex: Index Required

The collection's "past the end" position.

endIndex is not a valid argument to subscript, and is always reachable from startIndex by zero or more applications of successor().

Declaration

var endIndex: Index { get }

Declared In

_CollectionType
var startIndex: Index Required

The position of the first element in a non-empty collection.

Identical to endIndex in an empty collection.

Declaration

var startIndex: Index { get }

Declared In

_CollectionType

Subscripts

subscript(_: Self.Index) Required

Declaration

subscript(position: Self.Index) -> Self.Generator.Element { get }

Declared In

CollectionType
subscript(_: Index) Required

Declaration

subscript(_i: Index) -> _Element { get }

Declared In

_CollectionType

Instance Methods

mutating func append(_:) Required

Append x to self.

Applying successor() to the index of the new element yields self.endIndex.

Complexity: amortized O(1).

Declaration

mutating func append(x: Self.Generator.Element)

Declared In

_ExtensibleCollectionType
mutating func extend(_:) Required

Append the elements of newElements to self.

Complexity: O(length of result)

A possible implementation:

reserveCapacity(count(self) + underestimateCount(newElements))
for x in newElements {
  self.append(x)
}

Declaration

mutating func extend<S : SequenceType where Self.Generator.Element == Self.Generator.Element>(newElements: S)

Declared In

_ExtensibleCollectionType
func generate() Required

Return a generator over the elements of this sequence.

Complexity: O(1)

Declaration

func generate() -> Generator

Declared In

SequenceType, _Sequence_Type
mutating func insert(_:atIndex:) Required

Insert newElement at index i.

Invalidates all indices with respect to self.

Complexity: O(count(self)).

Can be implemented as:

Swift.insert(&self, newElement, atIndex: i)

Declaration

mutating func insert(newElement: Self.Generator.Element, atIndex i: Self.Index)
mutating func removeAll(_:) Required

Remove all elements

Invalidates all indices with respect to self.

keepCapacity, if true, is a non-binding request to avoid releasing storage, which can be a useful optimization when self is going to be grown again.

Complexity: O(count(self)).

Can be implemented as:

Swift.removeAll(&self, keepCapacity: keepCapacity)

Declaration

mutating func removeAll(#keepCapacity: Bool)
mutating func removeAtIndex(_:) Required

Remove the element at index i

Invalidates all indices with respect to self.

Complexity: O(count(self)).

Can be implemented as:

Swift.removeAtIndex(&self, i)

Declaration

mutating func removeAtIndex(i: Self.Index) -> Self.Generator.Element
mutating func removeRange(_:) Required

Remove the indicated subRange of elements

Invalidates all indices with respect to self.

Complexity: O(count(self)).

Can be implemented as:

Swift.removeRange(&self, subRange)

Declaration

mutating func removeRange(subRange: Range<Self.Index>)
mutating func replaceRange(_:with:) Required

Replace the given subRange of elements with newElements.

Invalidates all indices with respect to self.

Complexity: O(count(subRange)) if subRange.endIndex == self.endIndex and isEmpty(newElements), O(count(self) + count(newElements)) otherwise.

Declaration

mutating func replaceRange<C : CollectionType where Self.Generator.Element == Self.Generator.Element>(subRange: Range<Self.Index>, with newElements: C)
mutating func reserveCapacity(_:) Required

A non-binding request to ensure n elements of available storage.

This works as an optimization to avoid multiple reallocations of linear data structures like Array. Conforming types may reserve more than n, exactly n, less than n elements of storage, or even ignore the request completely.

Declaration

mutating func reserveCapacity(n: Self.Index.Distance)

Declared In

_ExtensibleCollectionType
mutating func splice(_:atIndex:) Required

Insert newElements at index i

Invalidates all indices with respect to self.

Complexity: O(count(self) + count(newElements)).

Can be implemented as:

Swift.splice(&self, newElements, atIndex: i)

Declaration

mutating func splice<S : CollectionType where Self.Generator.Element == Self.Generator.Element>(newElements: S, atIndex i: Self.Index)