I have a tree structure that consists of dozens of types of nodes (each type of node inherits from a NodeBase class).
I would like to perform searches on the tree to return a reference to a specific node. For example, suppose there is some Company tree, which contains Department nodes amongst other types of nodes. Department nodes consist of Employee nodes. It is assumed that an employee must be part of a department, and can be in exactly one department.
Currently, it is designed so that each node has a list of child nodes of type NodeBase. A tree can become quite large, with hundreds of thousands of nodes at times. Insertion/deletion operations are seldom used, while search operations should not take "too long" for these big trees.
Suppose I want to get a reference to an employee node whose employee ID field equals some string that I provide. I don't know which department the employee is in, so I'd have to perform a search through all of the nodes hoping to find a match. Not all nodes have an employee ID field; departments, for example, do not have them.
I am not sure what is the best way to implement the search functionality, given this tree structure design.
There are probably better ways to design how the data is stored in the first place (eg: using a database?) but currently I am stuck with a tree.
Companynode would ever haveDepartmentchild nodes), so if I ever need to search for a department, I don't need to search beyond the departments themselves. Maybe this will help decide what kind of implementation would be good.