RangeType
CircularBuffer.swift:116typealias RangeType<Bound> = Range<Bound> where Bound : Strideable, Bound.Stride : SignedInteger
typealias RangeType<Bound> = Range<Bound> where Bound : Strideable, Bound.Stride : SignedInteger
import NIOCore
The core abstractions that make up SwiftNIO.
struct CircularBuffer<Element>
An automatically expanding ring buffer implementation backed by a ContiguousArray
. Even though this implementation will automatically expand if more elements than initialCapacity
are stored, it’s advantageous to prevent expansions from happening frequently. Expansions will always force an allocation and a copy to happen.
@frozen struct Range<Bound> where Bound : Comparable
A half-open interval from a lower bound up to, but not including, an upper bound.
protocol Strideable<Stride> : Comparable
A type representing continuous, one-dimensional values that can be offset and measured.
associatedtype Stride : Comparable, SignedNumeric
A type that represents the distance between two values.
protocol SignedInteger : BinaryInteger, SignedNumeric
An integer type that can represent both positive and negative values.
init()
Allocates an empty buffer.
init(arrayLiteral elements: Element...)
init(initialCapacity: Int)
Allocates a buffer that can hold up to initialCapacity
elements and initialise an empty ring backed by the buffer. When the ring grows to more than initialCapacity
elements the buffer will be expanded.
var capacity: Int { get }
The total number of elements that the ring can contain without allocating new storage.
var count: Int { get }
Returns the number of element in the ring.
var description: String { get }
Returns a human readable description of the ring.
var endIndex: Index { get }
The CircularBuffer
’s “past the end” position—that is, the position one greater than the last valid subscript argument.
var first: Element? { get }
The first Element
of the CircularBuffer
(or nil
if empty).
var isEmpty: Bool { get }
Returns whether the ring is empty.
var startIndex: Index { get }
The position of the first element in a nonempty CircularBuffer
.
subscript(bounds: Range<Index>) -> SubSequence { get set }
subscript(position: Index) -> Element { get set }
Accesses the element at the specified index.
subscript(offset offset: Int) -> Element { get set }
Return element offset
from first element.
func _copyContents(initializing buffer: UnsafeMutableBufferPointer<Element>) -> (Iterator, UnsafeMutableBufferPointer<Element>.Index)
func _failEarlyRangeCheck(_ index: Index, bounds: ClosedRange<Index>)
func _failEarlyRangeCheck(_ index: Index, bounds: Range<Index>)
func _failEarlyRangeCheck(_ range: Range<Index>, bounds: Range<Index>)
mutating func append(_ value: Element)
Append an element to the end of the ring buffer.
func distance(from start: CircularBuffer<Element>.Index, to end: CircularBuffer<Element>.Index) -> Int
func index(_ i: Index, offsetBy distance: Int) -> Index
Returns the index offset by distance
from index
.
func index(after: Index) -> Index
Returns the position immediately after the given index.
func index(before: Index) -> Index
Returns the index before index
.
mutating func modify<Result>(_ index: Index, _ modifyFunc: (inout Element) throws -> Result) rethrows -> Result
Modify the element at index
.
mutating func popFirst() -> Element?
Removes and returns the first element of the CircularBuffer
.
mutating func popLast() -> Element?
Removes and returns the last element of the CircularBuffer
.
mutating func prepend(_ value: Element)
Prepend an element to the front of the ring buffer.
@discardableResult mutating func remove(at position: Index) -> Element
Removes & returns the item at position
from the buffer
mutating func removeAll(keepingCapacity: Bool = false)
Removes all members from the circular buffer whist keeping the capacity.
@discardableResult mutating func removeFirst() -> Element
Removes and returns the first element of the CircularBuffer
.
mutating func removeFirst(_ k: Int)
Removes the specified number of elements from the beginning of the CircularBuffer
.
@discardableResult mutating func removeLast() -> Element
Removes and returns the last element of the CircularBuffer
.
mutating func removeLast(_ k: Int)
Removes the specified number of elements from the end of the CircularBuffer
.
mutating func removeSubrange(_ bounds: Range<Index>)
Removes the elements in the specified subrange from the circular buffer.
mutating func replaceSubrange<C>(_ subrange: Range<Index>, with newElements: C) where Element == C.Element, C : Collection
Replaces the specified subrange of elements with the given CircularBuffer
.
mutating func reserveCapacity(_ minimumCapacity: Int)
Prepares the CircularBuffer
to store the specified number of elements.
struct Index
An opaque CircularBuffer
index.
typealias Element = Element
typealias Indices = DefaultIndices<CircularBuffer<Element>>
typealias SubSequence = CircularBuffer<Element>