Class SimpleTreeBase<TKey, TValue>
- Namespace
- Dynamicweb.Core
- Assembly
- Dynamicweb.Core.dll
Base implementation of a generic tree, that does not expose it's internal workings or nodes.
public class SimpleTreeBase<TKey, TValue> where TKey : IEquatable<TKey> where TValue : class
Type Parameters
TKey
- Key type in tree
TValue
- Object type in the tree
- Inheritance
-
SimpleTreeBase<TKey, TValue>
- Inherited Members
Constructors
SimpleTreeBase(TKey, bool)
Creates an empty tree.
public SimpleTreeBase(TKey key, bool makeDummyRoot = false)
Parameters
key
TKey- Id of tree
makeDummyRoot
bool- Defines if a dummy root should be created (this root has id 0)
Properties
Id
Id of tree.
public TKey Id { get; }
Property Value
- TKey
- id
IsDummyRoot
Indicates if the root of the tree is a dummy root.
The purpose of the dummy root is to allow the use of a treestructure that does not actually contain a root element,
but instead multiple roots. All these roots will then use the dummyroot for purposes of the tree datastructure.
protected bool IsDummyRoot { get; set; }
Property Value
Methods
AddChild(SimpleTreeNode)
Adds the node as a child to this node.
protected void AddChild(SimpleTreeBase<TKey, TValue>.SimpleTreeNode node)
Parameters
node
SimpleTreeBase<TKey, TValue>.SimpleTreeNode
GetAll()
Gets all nodes in tree.
public IEnumerable<TValue> GetAll()
Returns
- IEnumerable<TValue>
- allNodes
GetAncestors(TKey, bool)
Yields the ancestors of specified node.
public IEnumerable<TValue> GetAncestors(TKey nodeId, bool includingSelf = true)
Parameters
nodeId
TKey- Id of node
includingSelf
bool- Specifies if the node should be included in the result as the youngest
Returns
- IEnumerable<TValue>
- ancestors
Remarks
Oldest ancestors are at the front of the list, youngest at the back.
GetChildren(TKey, bool)
Gets all children of the specified node.
public IEnumerable<TValue> GetChildren(TKey nodeId, bool isRecursive = false)
Parameters
nodeId
TKey- Id of the parent of the nodes to fetch
isRecursive
bool- Include all children of children recursively
Returns
- IEnumerable<TValue>
GetNode(TKey)
Gets the node matching the id.
protected SimpleTreeBase<TKey, TValue>.SimpleTreeNode GetNode(TKey key)
Parameters
key
TKey- Id of node to fetch
Returns
- SimpleTreeBase<TKey, TValue>.SimpleTreeNode
- node
GetRoot()
Root of tree.
public TValue GetRoot()
Returns
- TValue
- root
MakeSubTree(TKey, TKey, bool)
Makes a subtree from the specified location in the tree.
public SimpleTreeBase<TKey, TValue> MakeSubTree(TKey treeId, TKey key, bool isShallow)
Parameters
treeId
TKey- Id of newly created tree
key
TKey- Subtree starting location
isShallow
bool- Defines if a deep clone of the tree should be performed, for use when the subtree needs to modify the parent of nodes
Returns
- SimpleTreeBase<TKey, TValue>
- subTree
MakeSubTree(TKey, bool)
Makes a subtree from the specified location in the tree.
public SimpleTreeBase<TKey, TValue> MakeSubTree(TKey key, bool isShallow = true)
Parameters
key
TKey- subtree starting location
isShallow
bool- Defines if a deep clone of the tree should be performed, for use when the subtree needs to have modified the parent of nodes
Returns
- SimpleTreeBase<TKey, TValue>
SetRoot(TKey, TValue, bool)
Sets the root node. If another rootnode exists, this node is made into a child of the new root.
public void SetRoot(TKey elementId, TValue element, bool isRootPartOfTree = false)
Parameters
elementId
TKey- id of root
element
TValue- element in root. May be null.
isRootPartOfTree
bool- specifies if the root should be included in lookup inside the tree
SetRoot(SimpleTreeNode)
Sets the root of the tree.
protected void SetRoot(SimpleTreeBase<TKey, TValue>.SimpleTreeNode node)
Parameters
node
SimpleTreeBase<TKey, TValue>.SimpleTreeNode- Node
TryFill(Dictionary<TKey, TKey>, Dictionary<TKey, TValue>)
Inserts all elements provided in the tree such that they are children as specified.
public void TryFill(Dictionary<TKey, TKey> parentIdByNodeId, Dictionary<TKey, TValue> nodesById)
Parameters
parentIdByNodeId
Dictionary<TKey, TKey>- Dictionary of parents for nodes to be filled into the tree
nodesById
Dictionary<TKey, TValue>- Dictionary of nodes and their Ids to be filled into the tree
TryGetNode(TKey)
[Obsolete("Use GetNode(key) instead.", true)]
protected SimpleTreeBase<TKey, TValue>.SimpleTreeNode TryGetNode(TKey key)
Parameters
key
TKey
Returns
- SimpleTreeBase<TKey, TValue>.SimpleTreeNode
TryGetValue(TKey)
[Obsolete("Use TryGetValue(key, out value) instead.", true)]
public TValue TryGetValue(TKey key)
Parameters
key
TKey
Returns
- TValue
TryGetValue(TKey, out TValue)
Tries to get the node with the given key.
public bool TryGetValue(TKey key, out TValue value)
Parameters
key
TKey- node id
value
TValue- node value
Returns
- bool
- node
Remarks
O(1) lookup
TryRemoveNode(TKey)
Removes the node from the tree.
public bool TryRemoveNode(TKey nodeId)
Parameters
nodeId
TKey- Id of node to remove from tree
Returns
- bool
- success
TryReplaceNode(TKey, TValue)
Tries to replace the node content.
public bool TryReplaceNode(TKey key, TValue item)
Parameters
key
TKey- Id of node that needs to have it's content replaced.
item
TValue- New content
Returns
TrySetNode(TKey, TKey, TValue)
Tries to ensure that the tree contains a node with the specified parent and key.
public bool TrySetNode(TKey parentKey, TKey childKey, TValue child)
Parameters
parentKey
TKey- id of node that should be the parent
childKey
TKey- id of inserted node
child
TValue- element contained in node