/** * Depth-first pre-order strategy (https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)). * * @type {string} */ export declare const TRAVERSAL_DF_PRE = "DF-pre-order"; /** * @param {Function} callback A callback which will be called on each visited node. * @param {*} context A context to pass through. * @returns {boolean} */ export declare function depthFirstPreOrder(this: TreeNode, callback: Function, context: unknown): unknown; /** * Depth-first post-order strategy (https://en.wikipedia.org/wiki/Tree_traversal#Post-order_(NLR)). * * @type {string} */ export declare const TRAVERSAL_DF_POST = "DF-post-order"; /** * Breadth-first traversal strategy (https://en.wikipedia.org/wiki/Tree_traversal#Breadth-first_search_/_level_order). * * @type {string} */ export declare const TRAVERSAL_BF = "BF"; /** * @template T */ export default class TreeNode> { /** * A tree data. * * @type {object} */ data: T; /** * A parent node. * * @type {TreeNode} */ parent: TreeNode | null; /** * A tree leaves. * * @type {TreeNode[]} */ childs: TreeNode[]; /** * Initializes the tree node with the provided data object. */ constructor(data: T); /** * Adds a node to tree leaves. Added node is linked with the parent node through "parent" property. * * @param {TreeNode} node A TreeNode to add. */ addChild(node: TreeNode): void; /** * @memberof TreeNode# * @function cloneTree * * Clones a tree structure deeply. * * For example, for giving a tree structure: * .--(B1)--. * .-(C1) .-(C2)-.----. * (D1) (D2) (D3) (D4) * * Cloning a tree starting from C2 node creates a mirrored tree structure. * .-(C2')-.-----. * (D2') (D3') (D4') * * The cloned tree can be safely modified without affecting the original structure. * After modification, the clone can be merged with a tree using the "replaceTreeWith" method. * * @param {TreeNode} [nodeTree=this] A TreeNode to clone. * @returns {TreeNode} */ cloneTree(nodeTree?: TreeNode): TreeNode; /** * Replaces the current node with a passed tree structure. * * @param {TreeNode} nodeTree A TreeNode to replace with. */ replaceTreeWith(nodeTree: TreeNode): void; /** * Traverses the tree structure through node childs. The walk down traversing supports * a three different strategies. * - Depth-first pre-order strategy (https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)); * - Depth-first post-order strategy (https://en.wikipedia.org/wiki/Tree_traversal#Post-order_(NLR)); * - Breadth-first traversal strategy (https://en.wikipedia.org/wiki/Tree_traversal#Breadth-first_search_/_level_order). * * @param {Function} callback The callback function which will be called for each node. * @param {string} [traversalStrategy=DEFAULT_TRAVERSAL_STRATEGY] Traversing strategy. */ walkDown(callback: (node: TreeNode) => unknown, traversalStrategy?: string): void; /** * Traverses the tree structure through node parents. * * @param {Function} callback The callback function which will be called for each node. */ walkUp(callback: (this: TreeNode, node: TreeNode) => boolean | void): void; }