how is TreeNodeCollection.Find implemented?

  • Thread starter Thread starter engelit.junk
  • Start date Start date
E

engelit.junk

Hi,

If you look at TreeNodeCollection.Find Method, you'll see:

Finds the tree nodes with specified key, optionally searching subnodes.

public TreeNode[] Find (
string key,
bool searchAllChildren
)

My question is - how is the find impelmented? is there a hash that
holds the keys or does the Find method really go over each node and
search for the key?

Thanks
Engel
 
Hi,

If you look at TreeNodeCollection.Find Method, you'll see:

Finds the tree nodes with specified key, optionally searching subnodes.

public TreeNode[] Find (
string key,
bool searchAllChildren
)

My question is - how is the find impelmented?

For all such questions, you can discover the answer yourself using Lutz
Roeder's Reflector (google result 1 for 'reflector'), which is
basically a .NET disassembler: point it at System.Windows.Forms.dll
and...
is there a hash that
holds the keys or does the Find method really go over each node and
search for the key?

public TreeNode[] Find(string key, bool searchAllChildren)
{
ArrayList list1 = this.FindInternal(key, searchAllChildren, this,
new ArrayList());
TreeNode[] nodeArray1 = new TreeNode[list1.Count];
list1.CopyTo(nodeArray1, 0);
return nodeArray1;
}

private ArrayList FindInternal(string key, bool searchAllChildren,
TreeNodeCollection treeNodeCollectionToLookIn, ArrayList
foundTreeNodes)
{
if ((treeNodeCollectionToLookIn == null) || (foundTreeNodes ==
null))
{
return null;
}
for (int num1 = 0; num1 < treeNodeCollectionToLookIn.Count;
num1++)
{
if ((treeNodeCollectionToLookIn[num1] != null) &&
WindowsFormsUtils.SafeCompareStrings(treeNodeCollectionToLookIn[num1].Name,
key, true))
{
foundTreeNodes.Add(treeNodeCollectionToLookIn[num1]);
}
}
if (searchAllChildren)
{
for (int num2 = 0; num2 < treeNodeCollectionToLookIn.Count;
num2++)
{
if (((treeNodeCollectionToLookIn[num2] != null) &&
(treeNodeCollectionToLookIn[num2].Nodes != null)) &&
(treeNodeCollectionToLookIn[num2].Nodes.Count > 0))
{
foundTreeNodes = this.FindInternal(key,
searchAllChildren, treeNodeCollectionToLookIn[num2].Nodes,
foundTreeNodes);
}
}
}
return foundTreeNodes;
}
 
Back
Top