@thi.ng/arrays
Version:
Array / Arraylike utilities
30 lines • 941 B
TypeScript
/**
* Inserts `x` into `buf` at index `i` and ensures that array length doesn't
* grow beyond max `k` items (default: unbounded).
*
* @remarks
* The function will have no effect iff `i<0` or `i>=k` or `k<1`. If
* `buf.length` is larger than `k`, only the index range `[i,k)` will be
* modified.
*
* In benchmarking with 4, 8, 16, 32, 64 element arrays, this function is
* consistently 7-16x faster than `Array.prototype.copyWithin()` and 1.5-2x
* faster than `Array.prototype.splice()` (for sizes < ~32). See
* `/bench/insert.ts`
*
* @param buf -
* @param x -
* @param i -
* @param k -
*/
export declare const insert: <T>(buf: T[], x: T, i: number, k?: number) => T[];
/**
* Same as {@link insert} but without any bounds/index checks.
*
* @param buf -
* @param x -
* @param i -
* @param k -
*/
export declare const insertUnsafe: <T>(buf: T[], x: T, i: number, k?: number) => T[];
//# sourceMappingURL=insert.d.ts.map