Published
Edited
Mar 10, 2020
1 fork
5 stars
Insert cell
Insert cell
class ABP {
constructor(v = 0, n = 100) {
this.A = new Int32Array(n);
this.B = new Int32Array(n);
this.S = new Int32Array(n);
this.v = v;
this.n = n;
this.top = 0;
}
defined(i) {
return (i < this.n && this.B[i] >= 0 && this.B[i] < this.top && this.S[this.B[i]] == i)
}
define (i) {
this.B[i] = this.top;
this.S[this.top++] = i;
}
set (i, x) {
this.A[i] = x;
if (!this.defined(i)) this.define(i);
}
get (i) {
if (this.defined(i)) return this.A[i];
return this.v
}
}
Insert cell
{
let a = new ABP(-99, 10);
for (let [i,x] of [[3,21], [7,45], [1,-8]]) a.set(i,x)
let r = [];
for (let i = 0; i < a.n; i++) r.push([i,a.get(i)])
return r
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more