sonic-forest
Version:
High-performance (binary) tree and sorted map implementation (AVL, Splay, Radix, Red-Black)
27 lines (26 loc) • 835 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BinaryRadixTree = void 0;
const BinaryTrieNode_1 = require("./BinaryTrieNode");
const Slice_1 = require("./Slice");
const binaryRadix_1 = require("./binaryRadix");
class BinaryRadixTree extends BinaryTrieNode_1.BinaryTrieNode {
constructor() {
super(new Slice_1.Slice(new Uint8Array(), 0, 0), undefined);
this.size = 0;
}
set(key, value) {
this.size += (0, binaryRadix_1.insert)(this, key, value);
}
get(key) {
const node = (0, binaryRadix_1.find)(this, key);
return node && node.v;
}
delete(key) {
const removed = (0, binaryRadix_1.remove)(this, key);
if (removed)
this.size--;
return removed;
}
}
exports.BinaryRadixTree = BinaryRadixTree;