Compare commits

...

2 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 9339b87ab3 Tree
- CLeaned up
2024-05-02 22:23:36 +02:00
Tristan B. Velloza Kildaire 36531eae70 Tree
- Added some docs
2024-05-02 22:17:51 +02:00
1 changed files with 42 additions and 6 deletions

View File

@ -668,26 +668,67 @@ public class Tree(T)
private T value;
private Tree!(T)[] children;
/**
* Constructs a new tree with
* the given value to set
*
* Params:
* value = the value of
* this tree node
*/
this(T value)
{
this.value = value;
}
/**
* Creates a new tree without
* associating any value with
* itself
*/
this()
{
}
/**
* Sets the tree node's
* associated value
*
* Params:
* value = the valye
*/
public void setValue(T value)
{
this.value = value;
}
/**
* Appends another tree node
* to the array of children
* of this node's
*
* Params:
* node = the tree node
* to append
*/
public void appendNode(Tree!(T) node)
{
this.children ~= node;
}
/**
* Removes a given tree node
* from th array of children
* of thie node's
*
* Params:
* node = the tree node to
* remove
* Returns: `true` if the node
* was found and then removed,
* otherwise `false`
*/
public bool removeNode(Tree!(T) node)
{
bool found = false;
@ -710,12 +751,7 @@ public class Tree(T)
return false;
}
// public T opIndex(size_t idx)
// {
// return idx < this.children.length ? this.children[idx].getValue() : T.init;
// }
private static bool isTreeNodeType(E)()
{
return __traits(isSame, E, Tree!(T));