import { Maybe } from "purify-ts/Maybe"; import { PureWeakMap } from "./puremap"; import { TreeVisitor } from "../visitors"; /** * This class generates a tree map which is simply a representation of the * parent and child relationships in a given structure. We don't traverse the * tree here, that is handled `TreeVisitor` instance. We just record events * that occur as the tree is traverse and cache that information for easy * retrieval later. */ export declare class TreeMap { protected visitor: TreeVisitor; /** * Use a synchronous `TreeVisitor` to create the map. It would be ideal if this * could (at some point) be made part of the constructor. But, unfortunately, * the current API makes it difficult to deal with synchrnous and asynchrnous * mapping. This is a potential are of improvement. * * @param visitor * @returns */ static create(visitor: TreeVisitor): TreeMap; /** * Because the `AsyncTreeVisitor` is operating asynchronously, we use a * static method that returns a `Promise` to a constructoed `TreeMap` once the * traversal is complete. * * As part of this process, each node in the tree will be given a unique * identifier. * * TODO: I'm reconsidering the wisdom of supporting this. It seems to me that * perhaps a better approach would be to have an async step that builds a * complete tree in memory rather than making the tree building itself async. * The effect would be that we wouldn't need to treat async as a special case. * * TODO: Make this a method of the Visitor? * * @param visitor * @returns */ /** A method to clear the existing map in preparation for rewalking the tree. */ protected clear(from: T): void; /** * Trigger rewalking of the tree. */ rewalk(from: T): void; /** * Maps a node's id to the parents id (if the parent exists). */ protected parentMap: PureWeakMap; /** * Maps a node's id to the ids of all its children. */ protected childMap: PureWeakMap; /** * The set of nodes in the tree */ protected nodeSet: Set; /** * A constructor that is only invoked by the `TreeMap.create` method. * @param visitor */ protected constructor(visitor: TreeVisitor); get nodes(): Set; /** Id of the root node */ get root(): T; /** Determine if a given (potential) node is in this tree */ contains(n: T): boolean; /** * Returns the parent node (if it exsts) of the given node id. * @param n * @returns */ parent(n: T): Maybe; /** * Return the children of this node. * @param n * @returns */ children(n: T): T[]; }