@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
50 lines • 1.44 kB
JavaScript
export class Dict {
constructor(toNumber) {
this.toNumber = toNumber;
this.numEntries = 0;
this.dict = {};
}
betweenBoundsFirst(query) {
if (query.gte !== undefined) {
const k = this.toNumber(query.gte);
if (this.dict[k] !== undefined && this.dict[k].length > 0) {
return [
{
key: query.gte,
value: this.dict[k][this.dict[k].length - 1],
},
];
}
return [];
}
else if (query.lte !== undefined) {
const k = this.toNumber(query.lte);
if (this.dict[k] !== undefined && this.dict[k].length > 0) {
return [
{
key: query.lte,
value: this.dict[k][this.dict[k].length - 1],
},
];
}
return [];
}
return [];
}
deleteFirst(key) {
const k = this.toNumber(key);
if (this.dict[k] !== undefined) {
this.dict[k].pop();
this.numEntries--;
}
}
insert(key, value) {
const k = this.toNumber(key);
if (this.dict[k] === undefined) {
this.dict[k] = [];
}
this.dict[k].push(value);
this.numEntries++;
}
}
//# sourceMappingURL=dict.js.map