of numbers over a Float64Array ring buffer: eight
bytes per slot and no per-element allocation. NaN and -0 are stored as
given.
@throws ― {DequeInvalidInputError} With code INVALID_CAPACITY when
options.capacity is not Infinity or a positive safe integer no larger than
DEQUE_MAX_CAPACITY (Infinity is accepted), INVALID_VALUE when
options.items holds anything but numbers, or MAX_CAPACITY_EXCEEDED
when options.items holds more elements than the runtime will allocate
storage for.
of numbers over a Float64Array ring buffer: eight
bytes per slot and no per-element allocation. NaN and -0 are stored as
given.
@throws ― {DequeInvalidInputError} With code INVALID_CAPACITY when
options.capacity is not Infinity or a positive safe integer no larger than
DEQUE_MAX_CAPACITY (Infinity is accepted), INVALID_VALUE when
options.items holds anything but numbers, or MAX_CAPACITY_EXCEEDED
when options.items holds more elements than the runtime will allocate
storage for.
float64ArrayDeque({
DequeOptions<number>.capacity?: number |undefined
The most elements the deque holds. A push onto a full deque evicts the
element at the opposite end and returns it, which makes a bounded deque a
sliding window. Must be Infinity or a positive safe integer no larger
than
DEQUE_MAX_CAPACITY
. Omit it, or pass Infinity, for a deque
that grows without bound; that is the value
Deque.capacity
reports.
capacity: 3 })
let
let sum:number
sum=0
function
functionobserve(value:number):number
observe(
value: number
value:number):number {
let sum:number
sum+=
value: number
value
const
constevicted:number|undefined
evicted=
constwindow:Deque<number>
window.
Deque<number>.pushBack: (value:number) => number |undefined
Add an element at the back. O(1) amortized.
@returns ― The element evicted from the front when the deque was at
capacity; otherwise undefined.
@throws ― {DequeInvalidInputError} With code INVALID_VALUE when the layout
cannot store the value, or MAX_CAPACITY_EXCEEDED when growing would pass
DEQUE_MAX_CAPACITY or the runtime refuses the allocation. The
deque is unchanged after either.
pushBack(
value: number
value) // undefined until the window is full
if (
constevicted:number|undefined
evicted!==
var undefined
undefined) {
let sum:number
sum-=
constevicted:number
evicted
}
return
let sum:number
sum/
constwindow:Deque<number>
window.
Deque<number>.size: number
Number of elements held. O(1). The deque is empty when this is 0.
of numbers over a Float64Array ring buffer: eight
bytes per slot and no per-element allocation. NaN and -0 are stored as
given.
@throws ― {DequeInvalidInputError} With code INVALID_CAPACITY when
options.capacity is not Infinity or a positive safe integer no larger than
DEQUE_MAX_CAPACITY (Infinity is accepted), INVALID_VALUE when
options.items holds anything but numbers, or MAX_CAPACITY_EXCEEDED
when options.items holds more elements than the runtime will allocate
storage for.
float64ArrayDeque } from'knotkit/deque'
import {
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in
of numbers over a Float64Array ring buffer: eight
bytes per slot and no per-element allocation. NaN and -0 are stored as
given.
@throws ― {DequeInvalidInputError} With code INVALID_CAPACITY when
options.capacity is not Infinity or a positive safe integer no larger than
DEQUE_MAX_CAPACITY (Infinity is accepted), INVALID_VALUE when
options.items holds anything but numbers, or MAX_CAPACITY_EXCEEDED
when options.items holds more elements than the runtime will allocate
storage for.
float64ArrayDeque({
DequeOptions<number>.capacity?: number |undefined
The most elements the deque holds. A push onto a full deque evicts the
element at the opposite end and returns it, which makes a bounded deque a
sliding window. Must be Infinity or a positive safe integer no larger
than
DEQUE_MAX_CAPACITY
. Omit it, or pass Infinity, for a deque
that grows without bound; that is the value
Deque.capacity
reports.
capacity: 3 })
let
let sum:number
sum=0
function
functionobserve(value:number):number
observe(
value: number
value:number):number {
let sum:number
sum+=
value: number
value
const
constevicted:number|undefined
evicted=
constwindow:Deque<number>
window.
Deque<number>.pushBack: (value:number) => number |undefined
Add an element at the back. O(1) amortized.
@returns ― The element evicted from the front when the deque was at
capacity; otherwise undefined.
@throws ― {DequeInvalidInputError} With code INVALID_VALUE when the layout
cannot store the value, or MAX_CAPACITY_EXCEEDED when growing would pass
DEQUE_MAX_CAPACITY or the runtime refuses the allocation. The
deque is unchanged after either.
pushBack(
value: number
value) // undefined until the window is full
if (
constevicted:number|undefined
evicted!==
var undefined
undefined) {
let sum:number
sum-=
constevicted:number
evicted
}
return
let sum:number
sum/
constwindow:Deque<number>
window.
Deque<number>.size: number
Number of elements held. O(1). The deque is empty when this is 0.
size
}
// 50,000 observations: the values 0 to 99, repeated 500 times, in shuffled order.
Return a uniformly shuffled copy of values using Fisher-Yates.
Runs in O(values.length) time and uses O(values.length) space for the copy.
The input is never mutated.
@throws ― {PrngInvalidInputError} With code INVALID_SOURCE_VALUE when the
random source returns a value outside [0, 1).
shuffled(
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in