binary-type-tree
Version:
Binary Trees written in TypeScript
49 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const avl_node_1 = require("../avl-node");
/**
* Tree class for the AVL Nodes
*/
class AVLTree extends avl_node_1.AVLNode {
/**
* Constructor of the AVLTree class
* @param options
*/
constructor(options) {
super(options);
this.options = options;
this.tree = new avl_node_1.AVLNode(options);
}
/**
* Insert a new AVL Node into the tree an maintain AVL balance.
* @param key
* @param value
*/
insert(key, value) {
const newTree = this.tree._insert(key, value);
// If newTree is undefined, that means its structure was not modified
if (newTree) {
this.tree = newTree;
}
}
/**
* Delete a key or value and maintain AVL balance.
* @param key
* @param value
*/
Delete(key, value) {
const newTree = this.tree._delete(key, value);
// if newTree is undefined, that means its structure was not modified
if (newTree) {
this.tree = newTree;
}
}
updateKey(key, newKey) {
const newTree = this.tree._updateKey(key, newKey);
if (newTree) {
this.tree = newTree;
}
}
}
exports.AVLTree = AVLTree;
//# sourceMappingURL=avlTree.js.map