Use Map for node meta data.

This commit is contained in:
Oleksii Trekhleb
2018-05-31 07:59:20 +03:00
parent e572de63cb
commit 7a4265403c
5 changed files with 47 additions and 73 deletions

View File

@@ -3,14 +3,15 @@ import Comparator from '../../utils/comparator/Comparator';
export default class BinaryTreeNode {
/**
* @param {*} [value] - node value.
* @param {Object} meta - any meta information that needs to be attached to the node.
*/
constructor(value = null, meta = {}) {
constructor(value = null) {
this.left = null;
this.right = null;
this.parent = null;
this.value = value;
this.meta = meta;
// Any node related meta information may be stored here.
this.meta = new Map();
// This comparator is used to compare binary tree nodes with each other.
this.nodeComparator = new Comparator();
@@ -157,29 +158,6 @@ export default class BinaryTreeNode {
return traverse;
}
/**
* @param {string} property
* @param {*} value
* @return {BinaryTreeNode}
*/
setMeta(property, value) {
this.meta[property] = value;
return this;
}
/**
* @param property
* @return {*}
*/
getMeta(property) {
if (!this.meta || !Object.prototype.hasOwnProperty.call(this.meta, property)) {
return null;
}
return this.meta[property];
}
/**
* @return {string}
*/