The element type stored in the queue.
Readonly[unscopables]Required by the Array<T> contract. Marks with as unscopable so that
with inside a with statement does not shadow the method.
Optional[iterator]?: booleanOptional Readonly[unscopables]?: booleanIs an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optionalat?: booleanOptionalconcat?: booleanOptionalcopyWithin?: booleanOptionalentries?: booleanOptionalevery?: booleanOptionalfill?: booleanOptionalfilter?: booleanOptionalfind?: booleanOptionalfindIndex?: booleanOptionalfindLast?: booleanOptionalfindLastIndex?: booleanOptionalflat?: booleanOptionalflatMap?: booleanOptionalforEach?: booleanOptionalincludes?: booleanOptionalindexOf?: booleanOptionaljoin?: booleanOptionalkeys?: booleanOptionallastIndexOf?: booleanOptionallength?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
Optionalmap?: booleanOptionalpop?: booleanOptionalpush?: booleanOptionalreduce?: booleanOptionalreduceRight?: booleanOptionalreverse?: booleanOptionalshift?: booleanOptionalslice?: booleanOptionalsome?: booleanOptionalsort?: booleanOptionalsplice?: booleanOptionaltoLocaleString?: booleanOptionaltoReversed?: booleanOptionaltoSorted?: booleanOptionaltoSpliced?: booleanOptionaltoString?: booleanOptionalunshift?: booleanOptionalvalues?: booleanOptionalwith?: booleanSets the logical length of the queue, truncating or extending it.
Setting length translates to items.length = value + headIndex so
internal accounting stays consistent.
The new logical length.
Iterates over the logical elements of the queue in order, skipping the
internal "ghost" slots before headIndex.
Returns the element at the given index, supporting negative indices.
Negative indices count from the end (-1 is the last element) and
bypass the headIndex offset so they always refer to the tail of the
logical sequence.
Zero-based (or negative) index.
The element, or undefined if out of range.
Compacts the internal storage by discarding the ghost slots that
accumulate after repeated shift() calls.
This is done automatically when headIndex exceeds 100 000, but you
can call it explicitly if memory pressure is a concern.
Returns a new FastQueue that is the concatenation of this queue and items.
Each item in items may be a single element T or a ConcatArray<T>
(e.g. another array or FastQueue).
A new FastQueue<T>.
Concatenates another FastQueue onto this one and returns a new FastQueue.
Convenience wrapper around concat for FastQueue-to-FastQueue merges.
The queue to append.
A new FastQueue<T>.
Copies a segment of the queue to a different position within the same queue.
All indices are logical (zero-based).
Zero-based index where the copied section will be pasted.
Zero-based index of the section start to copy from.
Optionalend: numberZero-based index of the section end (exclusive).
this for chaining.
Returns an ArrayIterator of [index, value] pairs for the logical elements.
Returns true if every element satisfies predicate.
Short-circuits on the first failing element. The type-guard overload
narrows this to S[] when it returns true.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
OptionalthisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Fills elements from start (inclusive) to end (exclusive) with value.
Indices are logical (zero-based); negative values are not supported.
Value to fill with.
Optionalstart: numberStart index (default 0).
Optionalend: numberEnd index (default this.length).
this for chaining.
Returns a new FastQueue containing only elements for which predicate returns truthy.
The type-guard overload narrows the element type to S.
A new FastQueue<S> or FastQueue<T>.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
OptionalthisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns the first element for which predicate returns truthy, or undefined.
The type-guard overload narrows the return type to S.
Returns the first element for which predicate returns truthy, or undefined.
The type-guard overload narrows the return type to S.
Returns the last element for which predicate returns truthy, or undefined.
The type-guard overload narrows the return type to S.
Returns the last element for which predicate returns truthy, or undefined.
The type-guard overload narrows the return type to S.
Maps each element through callback and flattens the result one level deep.
A new flattened FastQueue<U>.
Returns the element at index without going through the Proxy.
Equivalent to queue[index] but useful when the proxy is disabled or
when you want an explicit method call for clarity.
Zero-based logical index.
The element, or undefined if index is out of range.
Returns true if searchElement is present in the queue.
Value to search for.
OptionalfromIndex: numberOptional starting index (default 0).
Returns the index of the first occurrence of value, or -1 if not found.
The value to search for.
Optionalindex: numberOptional starting position (default 0).
Zero-based logical index, or -1.
Joins all logical elements into a string with separator between each pair.
String placed between elements (default ',').
The joined string.
Returns the index of the last occurrence of value, or -1 if not found.
The value to search for.
Optionalindex: numberOptional starting position for the backward search.
Zero-based logical index, or -1.
Creates a new FastQueue with the results of calling callback on every element.
Indices passed to callback are zero-based logical indices.
A new FastQueue<U>.
Removes and returns the last element of the queue.
The last element, or undefined if the queue is empty.
Appends one or more elements to the end of the queue.
Elements to append.
The new logical length of the queue.
Reduces the queue to a single value, processing elements left-to-right.
When called without initialValue the first element is used as the seed
and processing starts at index 1.
The accumulated result.
Reduces the queue to a single value, processing elements left-to-right.
When called without initialValue the first element is used as the seed
and processing starts at index 1.
The accumulated result.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Reduces the queue to a single value, processing elements right-to-left.
The accumulated result.
Reduces the queue to a single value, processing elements right-to-left.
The accumulated result.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Reverses the queue in place and returns this.
Only the logical elements (from headIndex onward) are reversed;
ghost slots are not touched.
this.
Removes and returns the first element of the queue in O(1) time.
After removal, headIndex is incremented rather than copying elements.
Ghost slots are cleaned up automatically when headIndex exceeds 100 000.
The first element, or undefined if the queue is empty.
Returns a section of the queue as a new FastQueue.
Negative indices are supported: -1 refers to the last element.
Optionalstart: numberZero-based start index (inclusive, default 0).
Optionalend: numberZero-based end index (exclusive, default this.length).
A new FastQueue<T> with fresh backing storage.
Removes and/or inserts elements at start.
Zero-based logical index at which to start changing the queue.
OptionaldeleteCount: numberNumber of elements to remove.
Elements to insert in place of the removed elements.
An array of the removed elements.
Returns a plain Array<T> containing the logical elements from start
(inclusive) to end (exclusive).
Zero-based start index (default 0).
Zero-based end index (default this.length).
A plain Array<T> — never a FastQueue.
Returns a new FastQueue with the elements in reverse order.
The original queue is not modified.
A new reversed FastQueue<T>.
Returns a new sorted FastQueue without modifying the original.
A new FastQueue<T> in sorted order.
Returns a new FastQueue with a splice applied, without modifying the original.
Zero-based logical start index.
Number of elements to remove.
Elements to insert.
A new FastQueue<T>.
Copies an array and removes elements while returning the remaining elements.
The zero-based location in the array from which to start removing elements.
OptionaldeleteCount: numberThe number of elements to remove.
A copy of the original array with the remaining elements.
Inserts one or more elements at the beginning of the queue.
If headIndex >= elements.length, elements are written into the ghost
slots in-place without allocation. Otherwise, a new array is created.
Elements to prepend, in order.
The new logical length.
Returns an ArrayIterator over the logical element values.
Returns a new FastQueue with the element at index replaced by value.
The original queue is not modified.
Zero-based logical index.
Replacement value.
A new FastQueue<T>.
StaticcopyCreates a FastQueue from a copy of array.
The queue owns its own storage; mutations do not affect the original.
The array to copy.
OptionaluseProxy: boolean = trueOptional parameter that determines whether to apply the index-offset proxy.
OptionalcompactingSize: number = COMPACTING_SIZEOptional parameter that determines the number of shifts before compacting the array.
A new FastQueue<T> with independent storage.
StaticemptyCreates an empty FastQueue<T>.
OptionaluseProxy: boolean = trueOptional parameter that determines whether to apply the index-offset proxy.
OptionalcompactingSize: number = COMPACTING_SIZEOptional parameter that determines the number of shifts before compacting the array.
A new empty FastQueue<T>.
StaticfromCreates a FastQueue that wraps array directly — no copy is made.
Pass useProxy = false only when you know you will never use bracket
notation to read or write elements.
The array to wrap.
OptionaluseProxy: boolean = trueOptional parameter that determines whether to apply the index-offset proxy.
OptionalcompactingSize: number = COMPACTING_SIZEOptional parameter that determines the number of shifts before compacting the array.
A new FastQueue<T> backed by array.
An O(1)-shift queue that fully satisfies the
Array<T>interface.A standard
Array.shift()is O(n) because one slot must copy down every remaining element.FastQueueavoids that by tracking aheadIndexoffset into the underlying storage array: shifting simply increments the pointer. All logical indices presented to callers are zero-based and automatically translated to internal indices via+ headIndex.A
Proxywrapper is returned from the constructor so that bracket notation (queue[i]) also respects the offset. Method bodies are bound to the raw (self) instance to bypass the proxy on every internal property access, preserving the O(1) benefit.Because
FastQueue<T>implementsArray<T>, it can be used anywhere an array is expected — including D3's.data()call,Array.isArraychecks (via the iterator protocol), and TypeScript overload resolution.Example