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 : struct, IEquatable<TKey> where TValue : class
Type Parameters
TKeyKey type in tree
TValueObject type in the tree
- Inheritance
-
SimpleTreeBase<TKey, TValue>
- Derived
- Inherited Members
Constructors
SimpleTreeBase(TKey, bool)
Creates an empty tree.
public SimpleTreeBase(TKey key, bool makeDummyRoot = false)
Parameters
keyTKeyId of tree
makeDummyRootboolDefines 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.
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
nodeSimpleTreeBase<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
nodeIdTKeyId of node
includingSelfboolSpecifies 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
nodeIdTKeyId of the parent of the nodes to fetch
isRecursiveboolInclude 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
keyTKeyId of node to fetch
Returns
- SimpleTreeBase<TKey, TValue>.SimpleTreeNode
node
GetRoot()
Root of tree.
public TValue? GetRoot()
Returns
- TValue
root
MakeSubTree(TKey, bool)
Makes a subtree from the specified location in the tree.
public SimpleTreeBase<TKey, TValue> MakeSubTree(TKey key, bool isShallow = true)
Parameters
keyTKeysubtree starting location
isShallowboolDefines 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>
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
treeIdTKeyId of newly created tree
keyTKeySubtree starting location
isShallowboolDefines 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
SetRoot(SimpleTreeNode)
Sets the root of the tree.
protected void SetRoot(SimpleTreeBase<TKey, TValue>.SimpleTreeNode node)
Parameters
nodeSimpleTreeBase<TKey, TValue>.SimpleTreeNodeNode
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
elementIdTKeyid of root
elementTValueelement in root. May be null.
isRootPartOfTreeboolspecifies if the root should be included in lookup inside the tree
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
parentIdByNodeIdDictionary<TKey, TKey>Dictionary of parents for nodes to be filled into the tree
nodesByIdDictionary<TKey, TValue>Dictionary of nodes and their Ids to be filled into the tree
TryGetValue(TKey, out TValue?)
Tries to get the node with the given key.
public bool TryGetValue(TKey key, out TValue? value)
Parameters
keyTKeynode id
valueTValuenode value
Returns
- bool
node
Remarks
O(1) lookup
TryRemoveNode(TKey)
Removes the node from the tree.
public bool TryRemoveNode(TKey nodeId)
Parameters
nodeIdTKeyId 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
keyTKeyId of node that needs to have it's content replaced.
itemTValueNew 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
parentKeyTKeyid of node that should be the parent
childKeyTKeyid of inserted node
childTValueelement contained in node