This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MergeSortedSequence<First: Sequence, Second: Sequence>: Sequence where First.Element == Second.Element { | |
var first: First | |
var second: Second | |
var areInIncreasingOrder: (Element, Element) -> Bool | |
struct Iterator: IteratorProtocol { | |
var first: First.Iterator | |
var second: Second.Iterator | |
var areInIncreasingOrder: (Element, Element) -> Bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct OffsetIndexCollection<Base: RandomAccessCollection>: RandomAccessCollection { | |
var base: Base | |
var distance: Int | |
@inlinable @inline(__always) | |
var startIndex: Base.Index { | |
index(base.startIndex, offsetBy: distance) | |
} | |
@inlinable @inline(__always) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Float32 { | |
public static func gaussianRandomPair(using generator: inout some RandomNumberGenerator) -> (Float32, Float32) { | |
let u1 = Float.random(in: 0..<1, using: &generator) | |
let u2 = Float.random(in: 0..<1, using: &generator) | |
let r = sqrt(-2 * log(u1)) | |
let theta = 2 * Float.pi * u2 | |
let z0 = r * cos(theta) | |
let z1 = r * sin(theta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Accelerate | |
public struct Vector512Float32: VectorProtocol, Hashable { | |
public typealias Scalar = Float32 | |
public var components: [Scalar] | |
public init(components: [Scalar]) { | |
self.components = components | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import https://gist.github.com/JadenGeller/66585051f8de54d9f2a3df1acfd87c32#file-pinnedcollection-swift | |
import DequeModule | |
struct AdaptiveRangeBuffer<Index: Strideable, Element>: RandomAccessCollection, MutableCollection where Index.Stride == Int { | |
var storage: PinnedCollection<Deque<Element>, Index> | |
var defaultValue: (Index) -> Element | |
var willRemoveRange: (Slice<Self>) -> Void | |
init(indices: Range<Index>, defaultValue: @escaping (Index) -> Element, willRemoveRange: @escaping (Slice<Self>) -> Void = { _ in }) { | |
self.defaultValue = defaultValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PinnedCollection<Base: RandomAccessCollection, Index: Strideable>: RandomAccessCollection where Index.Stride == Int { | |
var reindexedBase: ReindexedCollection<Base, Index> | |
@inlinable @inline(__always) | |
var startIndex: Index { | |
reindexedBase.startIndex | |
} | |
@inlinable @inline(__always) | |
var endIndex: Index { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor RequestBatcher<Request, Response> { | |
var maxBatch: Int | |
var maxDelay: Duration | |
var priority: TaskPriority? | |
var dispatchBatch: ([Request]) async -> [Result<Response, Error>] | |
init(maxBatch: Int, maxDelay: Duration, dispatchBatch: @escaping ([Request]) async -> [Result<Response, Error>]) { | |
self.maxBatch = maxBatch | |
self.maxDelay = maxDelay | |
self.dispatchBatch = dispatchBatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol PipelineStep { | |
associatedtype Context | |
associatedtype Downstream: PipelineStep | |
func step(with context: Context) async throws -> Downstream | |
} | |
protocol IdleCheckablePipelinewStep: PipelineStep { | |
var isIdle: Bool { get } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct AnyEquatable: Equatable { | |
private let value: Any | |
private let equals: Any -> Bool | |
public init<E: Equatable>(_ value: E) { | |
self.value = value | |
self.equals = { ($0 as? E == value) ?? false } | |
} | |
} |