struct
ContiguousArray
<
T
>
Inheritance |
ArrayLiteralConvertible, CollectionType, DebugPrintable, ExtensibleCollectionType, MutableCollectionType, MutableSliceable, Printable, RangeReplaceableCollectionType, Reflectable, SequenceType, Sliceable, _ArrayType, _CollectionType, _DestructorSafeContainer, _ExtensibleCollectionType, _SequenceType, _Sequence_Type, _Sliceable, __ArrayType
View Protocol Hierarchy →
|
---|---|
Associated Types |
The type of element stored by this
A type that can represent a sub-range of a ContiguousArray
Type alias inferred.
Type alias inferred.
Type alias inferred. |
Import |
|
Initializers
Construct an empty ContiguousArray
Declaration
init
()
Initialization from an existing buffer does not have "array.init" semantics because the caller may retain an alias to buffer.
Declaration
init
(
_
buffer
:
_ContiguousArrayBuffer
<
T
>
)
Construct from an arbitrary sequence with elements of type T
Declaration
init
<
S
:
SequenceType
where
T
==
T
>
(
_
s
:
S
)
Create an instance containing elements
.
Declaration
init
(
arrayLiteral
elements
:
T
...)
Construct a ContiguousArray of count
elements, each initialized to
repeatedValue
.
Declaration
init
(
count
:
Int
,
repeatedValue
:
T
)
Instance Variables
How many elements the ContiguousArray
can store without reallocation
Declaration
var
capacity
:
Int
{
get
}
A textual representation of self
, suitable for debugging.
Declaration
var
debugDescription
:
String
{
get
}
A "past-the-end" element index; the successor of the last valid subscript argument.
Declaration
var
endIndex
:
Int
{
get
}
The first element, or nil
if the array is empty
Declaration
var
first
:
T
? {
get
}
The last element, or nil
if the array is empty
Declaration
var
last
:
T
? {
get
}
Always zero, which is the index of the first element when non-empty.
Declaration
var
startIndex
:
Int
{
get
}
Subscripts
Declaration
subscript
(
index
:
Int
) -
>
T
Declaration
subscript
(
subRange
:
Range
<
Int
>
) -
>
ArraySlice
<
T
>
Instance Methods
Append newElement to the ContiguousArray
Complexity: amortized O(1) unless self
's storage is shared with another live array; O(count
) otherwise.
Declaration
mutating
func
append
(
newElement
:
T
)
Append the elements of newElements
to self
.
Complexity: O(length of result)
Declaration
mutating
func
extend
<
S
:
SequenceType
where
T
==
T
>
(
newElements
:
S
)
Return a ContiguousArray containing the elements x
of self
for which
includeElement(x)
is true
Declaration
func
filter
(
includeElement
: (
T
) -
>
Bool
) -
>
ContiguousArray
<
T
>
Return a ContiguousArray containing the results of calling
transform(x)
on each element x
of self
and flattening the result.
Declaration
func
flatMap
<
U
>
(
transform
: @
noescape
(
T
) -
>
ContiguousArray
<
U
>
) -
>
ContiguousArray
<
U
>
Return a generator over the elements.
Complexity: O(1)
Declaration
func
generate
() -
>
IndexingGenerator
<
ContiguousArray
<
T
>
>
Insert newElement
at index i
.
Requires: i <= count
Complexity: O(count
).
Declaration
mutating
func
insert
(
newElement
:
T
,
atIndex
i
:
Int
)
Interpose self
between each consecutive pair of elements
,
and concatenate the elements of the resulting sequence. For
example, [-1, -2].join([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
yields [1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]
Declaration
func
join
<
S
:
SequenceType
where
ContiguousArray
<
T
>
==
ContiguousArray
<
T
>
>
(
elements
:
S
) -
>
ContiguousArray
<
T
>
Return a ContiguousArray containing the results of calling
transform(x)
on each element x
of self
Declaration
func
map
<
U
>
(
transform
: (
T
) -
>
U
) -
>
ContiguousArray
<
U
>
Return the result of repeatedly calling combine
with an
accumulated value initialized to initial
and each element of
self
, in turn, i.e. return
combine(combine(...combine(combine(initial, self[0]),
self[1]),...self[count-2]), self[count-1])
.
Declaration
func
reduce
<
U
>
(
initial
:
U
,
combine
: @
noescape
(
U
,
T
) -
>
U
) -
>
U
Remove all elements.
Postcondition: capacity == 0
iff keepCapacity
is false
.
Complexity: O(count(self)
).
Declaration
mutating
func
removeAll
(
keepCapacity
:
Bool
=
default
)
Remove and return the element at index i
Invalidates all indices with respect to self
.
Complexity: O(count
).
Declaration
mutating
func
removeAtIndex
(
index
:
Int
) -
>
T
Remove an element from the end of the ContiguousArray in O(1). Requires: count > 0
Declaration
mutating
func
removeLast
() -
>
T
Replace the given subRange
of elements with newElements
.
Complexity: O(count(subRange)
) if subRange.endIndex
== self.endIndex
and isEmpty(newElements)
, O(N) otherwise.
Declaration
mutating
func
replaceRange
<
C
:
CollectionType
where
T
==
T
>
(
subRange
:
Range
<
Int
>
,
with
newElements
:
C
)
Reserve enough space to store minimumCapacity elements.
PostCondition: capacity >= minimumCapacity
and the array has
mutable contiguous storage.
Complexity: O(count
)
Declaration
mutating
func
reserveCapacity
(
minimumCapacity
:
Int
)
A ContiguousArray containing the elements of self
in reverse order
Declaration
func
reverse
() -
>
ContiguousArray
<
T
>
Sort self
in-place according to isOrderedBefore
. Requires:
isOrderedBefore
induces a strict weak ordering
over the elements.
Declaration
mutating
func
sort
(
isOrderedBefore
: (
T
,
T
) -
>
Bool
)
Return a copy of self
that has been sorted according to
isOrderedBefore
. Requires: isOrderedBefore
induces a
strict weak ordering
over the elements.
Declaration
func
sorted
(
isOrderedBefore
: (
T
,
T
) -
>
Bool
) -
>
ContiguousArray
<
T
>
Insert newElements
at index i
Invalidates all indices with respect to self
.
Complexity: O(count + count(newElements)
).
Declaration
mutating
func
splice
<
S
:
CollectionType
where
T
==
T
>
(
newElements
:
S
,
atIndex
i
:
Int
)
Call body(p)
, where p
is a pointer to the ContiguousArray
's
contiguous storage.
Often, the optimizer can eliminate bounds checks within an
array algorithm, but when that fails, invoking the
same algorithm on body
's argument lets you trade safety for
speed.
Declaration
func
withUnsafeBufferPointer
<
R
>
(
body
: @
noescape
(
UnsafeBufferPointer
<
T
>
) -
>
R
) -
>
R
Call body(p)
, where p
is a pointer to the ContiguousArray
's
mutable contiguous storage.
Often, the optimizer can eliminate bounds- and uniqueness-checks
within an array algorithm, but when that fails, invoking the
same algorithm on body
's argument lets you trade safety for
speed.
Declaration
mutating
func
withUnsafeMutableBufferPointer
<
R
>
(
body
: @
noescape
(
inout
UnsafeMutableBufferPointer
<
T
>
) -
>
R
) -
>
R
A fast, contiguously-stored array of
T
.Efficiency is equivalent to that of
Array
, unlessT
is aclass
or@objc
protocol
type, in which case usingContiguousArray
may be more efficient. Note, however, thatContiguousArray
does not bridge to Objective-C. SeeArray
, with whichContiguousArray
shares most properties, for more detail.