UNPKG

@thi.ng/vector-pools

Version:

Data structures for managing & working with strided, memory mapped vectors

57 lines (56 loc) 1.08 kB
import { AVecList } from "./alist.js"; class VecArrayList extends AVecList { items; /** * * @param buffer - * @param capacity - * @param size - * @param cstride - * @param estride - * @param start - */ constructor(buffer, capacity, size, start = 0, cstride = 1, estride = size, factory) { super(buffer, capacity, size, cstride, estride, start, factory); this.items = []; } *[Symbol.iterator]() { yield* this.items; } get length() { return this.items.length; } add() { const v = this.alloc(); if (v) { this.items.push(v); } return v; } insert(i) { if (!this.length && i !== 0) return; const v = this.alloc(); if (v) { this.items.splice(i, 0, v); } return v; } remove(v) { const idx = this.items.indexOf(v); if (idx >= 0) { this.freeIDs.push(v.offset); this.items.splice(idx, 1); return true; } return false; } has(v) { return this.items.indexOf(v) >= 0; } nth(n) { return this.items[n]; } } export { VecArrayList };