Index
An opaque CircularBuffer
index.
struct Index
You may get indices offset from other indices by using CircularBuffer.index(:offsetBy:)
, CircularBuffer.index(before:)
, or CircularBuffer.index(after:)
.
An opaque CircularBuffer
index.
struct Index
You may get indices offset from other indices by using CircularBuffer.index(:offsetBy:)
, CircularBuffer.index(before:)
, or CircularBuffer.index(after:)
.
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.
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: CircularBuffer<Element>.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: CircularBuffer<Element>.Index { get }
The position of the first element in a nonempty CircularBuffer
.
subscript(bounds: Range<CircularBuffer<Element>.Index>) -> CircularBuffer<Element>.SubSequence { get set }
subscript(position: CircularBuffer<Element>.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>) -> (IndexingIterator<CircularBuffer<Element>>, UnsafeMutableBufferPointer<Element>.Index)
func _failEarlyRangeCheck(_ index: CircularBuffer<Element>.Index, bounds: ClosedRange<CircularBuffer<Element>.Index>)
func _failEarlyRangeCheck(_ index: CircularBuffer<Element>.Index, bounds: Range<CircularBuffer<Element>.Index>)
func _failEarlyRangeCheck(_ range: Range<CircularBuffer<Element>.Index>, bounds: Range<CircularBuffer<Element>.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: CircularBuffer<Element>.Index, offsetBy distance: Int) -> CircularBuffer<Element>.Index
Returns the index offset by distance
from index
.
func index(after: CircularBuffer<Element>.Index) -> CircularBuffer<Element>.Index
Returns the position immediately after the given index.
func index(before: CircularBuffer<Element>.Index) -> CircularBuffer<Element>.Index
Returns the index before index
.
mutating func modify<Result>(_ index: CircularBuffer<Element>.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: CircularBuffer<Element>.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<CircularBuffer<Element>.Index>)
Removes the elements in the specified subrange from the circular buffer.
mutating func replaceSubrange<C>(_ subrange: Range<CircularBuffer<Element>.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.
typealias Element = Element
typealias Indices = DefaultIndices<CircularBuffer<Element>>
typealias RangeType<Bound> = Range<Bound> where Bound : Strideable, Bound.Stride : SignedInteger
typealias SubSequence = CircularBuffer<Element>
protocol Comparable : Equatable
A type that can be compared using the relational operators <
, <=
, >=
, and >
.
protocol Equatable
A type that can be compared for value equality.
protocol Sendable
A thread-safe type whose values can be shared across arbitrary concurrent contexts without introducing a risk of data races. Values of the type may have no shared mutable state, or they may protect that state with a lock or by forcing it to only be accessed from a specific actor.
static func < (lhs: CircularBuffer<Element>.Index, rhs: CircularBuffer<Element>.Index) -> Bool
static func == (lhs: CircularBuffer<Element>.Index, rhs: CircularBuffer<Element>.Index) -> Bool
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
static func ... (minimum: Self) -> PartialRangeFrom<Self>
Returns a partial range extending upward from a lower bound.
static func ... (maximum: Self) -> PartialRangeThrough<Self>
Returns a partial range up to, and including, its upper bound.
static func ... (minimum: Self, maximum: Self) -> ClosedRange<Self>
Returns a closed range that contains both of its bounds.
static func ..< (maximum: Self) -> PartialRangeUpTo<Self>
Returns a partial range up to, but not including, its upper bound.
static func ..< (minimum: Self, maximum: Self) -> Range<Self>
Returns a half-open range that contains its lower bound but not its upper bound.
static func <= (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.
static func > (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.
static func >= (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.