mirror of https://github.com/deavmi/niknaks
Compare commits
2 Commits
7adea716c4
...
9339b87ab3
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 9339b87ab3 | |
Tristan B. Velloza Kildaire | 36531eae70 |
|
@ -668,26 +668,67 @@ public class Tree(T)
|
||||||
private T value;
|
private T value;
|
||||||
private Tree!(T)[] children;
|
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(T value)
|
||||||
{
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new tree without
|
||||||
|
* associating any value with
|
||||||
|
* itself
|
||||||
|
*/
|
||||||
this()
|
this()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the tree node's
|
||||||
|
* associated value
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* value = the valye
|
||||||
|
*/
|
||||||
public void setValue(T value)
|
public void setValue(T value)
|
||||||
{
|
{
|
||||||
this.value = 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)
|
public void appendNode(Tree!(T) node)
|
||||||
{
|
{
|
||||||
this.children ~= 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)
|
public bool removeNode(Tree!(T) node)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
@ -710,12 +751,7 @@ public class Tree(T)
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public T opIndex(size_t idx)
|
|
||||||
// {
|
|
||||||
// return idx < this.children.length ? this.children[idx].getValue() : T.init;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static bool isTreeNodeType(E)()
|
private static bool isTreeNodeType(E)()
|
||||||
{
|
{
|
||||||
return __traits(isSame, E, Tree!(T));
|
return __traits(isSame, E, Tree!(T));
|
||||||
|
|
Loading…
Reference in New Issue