Iterator
An iterator over the bytes viewed by a raw buffer pointer.
@frozen struct Iterator
An iterator over the bytes viewed by a raw buffer pointer.
@frozen struct Iterator
import Swift
@frozen struct UnsafeRawBufferPointer
A nonowning collection interface to the bytes in a region of memory.
init(_ bytes: UnsafeRawBufferPointer)
Creates a new buffer over the same memory as the given buffer.
init<T>(_ buffer: UnsafeBufferPointer<T>) where T : ~Copyable
Creates a raw buffer over the contiguous bytes in the given typed buffer.
init<T>(_ buffer: UnsafeMutableBufferPointer<T>) where T : ~Copyable
Creates a raw buffer over the contiguous bytes in the given typed buffer.
init(_ bytes: UnsafeMutableRawBufferPointer)
Creates a new buffer over the same memory as the given buffer.
init(rebasing slice: Slice<UnsafeRawBufferPointer>)
Creates a raw buffer over the same memory as the given raw buffer slice, with the indices rebased to zero.
init(rebasing slice: Slice<UnsafeMutableRawBufferPointer>)
Creates a raw buffer over the same memory as the given raw buffer slice, with the indices rebased to zero.
init(start: UnsafeRawPointer?, count: Int)
Creates a buffer over the specified number of contiguous bytes starting at the given pointer.
var baseAddress: UnsafeRawPointer? { get }
A pointer to the first byte of the buffer.
var count: Int { get }
The number of bytes in the buffer.
var debugDescription: String { get }
A textual representation of the buffer, suitable for debugging.
var endIndex: UnsafeRawBufferPointer.Index { get }
The “past the end” position—that is, the position one greater than the last valid subscript argument.
var indices: UnsafeRawBufferPointer.Indices { get }
var startIndex: UnsafeRawBufferPointer.Index { get }
Always zero, which is the index of the first byte in a nonempty buffer.
subscript(bounds: Range<Int>) -> UnsafeRawBufferPointer.SubSequence { get }
Accesses the bytes in the specified memory region.
subscript(i: Int) -> UnsafeRawBufferPointer.Element { get }
Accesses the byte at the given offset in the memory region as a UInt8
value.
func assumingMemoryBound<T>(to: T.Type) -> UnsafeBufferPointer<T> where T : ~Copyable
Returns a typed buffer to the memory referenced by this buffer, assuming that the memory is already bound to the specified type.
@discardableResult func bindMemory<T>(to type: T.Type) -> UnsafeBufferPointer<T> where T : ~Copyable
Binds this buffer’s memory to the specified type and returns a typed buffer of the bound memory.
func deallocate()
Deallocates the memory block previously allocated at this buffer pointer’s base address.
func load<T>(fromByteOffset offset: Int = 0, as type: T.Type) -> T
Returns a new instance of the given type, read from the buffer pointer’s raw memory at the specified byte offset.
func loadUnaligned<T>(fromByteOffset offset: Int = 0, as type: T.Type) -> T
func loadUnaligned<T>(fromByteOffset offset: Int = 0, as type: T.Type) -> T where T : BitwiseCopyable
Returns a new instance of the given type, constructed from the raw memory at the specified offset.
func makeIterator() -> UnsafeRawBufferPointer.Iterator
Returns an iterator over the bytes of this sequence.
func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<UnsafeRawBufferPointer.Element>) throws -> R) rethrows -> R?
func withMemoryRebound<T, E, Result>(to type: T.Type, _ body: (UnsafeBufferPointer<T>) throws(E) -> Result) throws(E) -> Result where E : Error, T : ~Copyable, Result : ~Copyable
Executes the given closure while temporarily binding the buffer to instances of type T
.
typealias Element = UInt8
typealias Index = Int
typealias Indices = Range<Int>
typealias SubSequence = Slice<UnsafeRawBufferPointer>
protocol BitwiseCopyable
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol IteratorProtocol<Element>
A type that supplies the values of a sequence one at a time.
protocol Sequence<Element>
A type that provides sequential, iterated access to its elements.
mutating func next() -> UInt8?
Advances to the next byte and returns it, or nil
if no next byte exists.
var lazy: LazySequence<Self> { get }
A sequence containing the same elements as this sequence, but on which some operations, such as map
and filter
, are implemented lazily.
var underestimatedCount: Int { get }
A value less than or equal to the number of elements in the sequence, calculated nondestructively.
func allSatisfy(_ predicate: (Self.Element) throws -> Bool) rethrows -> Bool
Returns a Boolean value indicating whether every element of a sequence satisfies a given predicate.
func compactMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult]
Returns an array containing the non-nil
results of calling the given transformation with each element of this sequence.
func contains(_ element: Self.Element) -> Bool
Returns a Boolean value indicating whether the sequence contains the given element.
func contains(where predicate: (Self.Element) throws -> Bool) rethrows -> Bool
Returns a Boolean value indicating whether the sequence contains an element that satisfies the given predicate.
func count<E>(where predicate: (Self.Element) throws(E) -> Bool) throws(E) -> Int where E : Error
Returns the number of elements in the sequence that satisfy the given predicate.
func drop(while predicate: (Self.Element) throws -> Bool) rethrows -> DropWhileSequence<Self>
Returns a sequence by skipping the initial, consecutive elements that satisfy the given predicate.
func dropFirst(_ k: Int = 1) -> DropFirstSequence<Self>
Returns a sequence containing all but the given number of initial elements.
func dropLast(_ k: Int = 1) -> [Self.Element]
Returns a sequence containing all but the given number of final elements.
func elementsEqual<OtherSequence>(_ other: OtherSequence) -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.
func elementsEqual<OtherSequence>(_ other: OtherSequence, by areEquivalent: (Self.Element, OtherSequence.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence
Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements in the same order, using the given predicate as the equivalence test.
func enumerated() -> EnumeratedSequence<Self>
Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero and x represents an element of the sequence.
func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> [Self.Element]
Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.
func first(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the first element of the sequence that satisfies the given predicate.
func flatMap<SegmentOfResult>(_ transform: (Self.Element) throws -> SegmentOfResult) rethrows -> [SegmentOfResult.Element] where SegmentOfResult : Sequence
Returns an array containing the concatenated results of calling the given transformation with each element of this sequence.
func forEach(_ body: (Self.Element) throws -> Void) rethrows
Calls the given closure on each element in the sequence in the same order as a for
-in
loop.
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence) -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<
) to compare elements.
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence, by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.
func makeIterator() -> Self
Returns an iterator over the elements of this sequence.
func map<T, E>(_ transform: (Self.Element) throws(E) -> T) throws(E) -> [T] where E : Error
Returns an array containing the results of mapping the given closure over the sequence’s elements.
@warn_unqualified_access func max() -> Self.Element?
Returns the maximum element in the sequence.
@warn_unqualified_access func max(by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the maximum element in the sequence, using the given predicate as the comparison between elements.
@warn_unqualified_access func min() -> Self.Element?
Returns the minimum element in the sequence.
@warn_unqualified_access func min(by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the minimum element in the sequence, using the given predicate as the comparison between elements.
func prefix(_ maxLength: Int) -> PrefixSequence<Self>
Returns a sequence, up to the specified maximum length, containing the initial elements of the sequence.
func prefix(while predicate: (Self.Element) throws -> Bool) rethrows -> [Self.Element]
Returns a sequence containing the initial, consecutive elements that satisfy the given predicate.
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Self.Element) throws -> Result) rethrows -> Result
Returns the result of combining the elements of the sequence using the given closure.
func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, Self.Element) throws -> ()) rethrows -> Result
Returns the result of combining the elements of the sequence using the given closure.
func reversed() -> [Self.Element]
Returns an array containing the elements of this sequence in reverse order.
func shuffled() -> [Self.Element]
Returns the elements of the sequence, shuffled.
func shuffled<T>(using generator: inout T) -> [Self.Element] where T : RandomNumberGenerator
Returns the elements of the sequence, shuffled using the given generator as a source for randomness.
func sorted() -> [Self.Element]
Returns the elements of the sequence, sorted.
func sorted(by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> [Self.Element]
Returns the elements of the sequence, sorted using the given predicate as the comparison between elements.
func split(maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true, whereSeparator isSeparator: (Self.Element) throws -> Bool) rethrows -> [ArraySlice<Self.Element>]
Returns the longest possible subsequences of the sequence, in order, that don’t contain elements satisfying the given predicate. Elements that are used to split the sequence are not returned as part of any subsequence.
func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) -> [ArraySlice<Self.Element>]
Returns the longest possible subsequences of the sequence, in order, around elements equal to the given element.
func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix) -> Bool where PossiblePrefix : Sequence, Self.Element == PossiblePrefix.Element
Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.
func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix, by areEquivalent: (Self.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool where PossiblePrefix : Sequence
Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test.
func suffix(_ maxLength: Int) -> [Self.Element]
Returns a subsequence, up to the given maximum length, containing the final elements of the sequence.
func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<Self.Element>) throws -> R) rethrows -> R?
func flatMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult]