Compare commits

...

4 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire c3b88d96b1
Merge 5f66b99434 into b6106883da 2024-05-02 20:40:23 +00:00
Tristan B. Velloza Kildaire 5f66b99434 Tree
- Documented
- Cleaned
2024-05-02 22:40:12 +02:00
Tristan B. Velloza Kildaire 51499dab47 Tree
- Documented
2024-05-02 22:34:03 +02:00
Tristan B. Velloza Kildaire 13145bd83a Tree
- Documented
2024-05-02 22:33:26 +02:00
1 changed files with 53 additions and 7 deletions

View File

@ -624,12 +624,20 @@ public template Always(T)
}
}
/**
* A touching stratergy
* that does nothing
*/
public template Nothing(T)
{
public void Nothing(Tree!(T) treeNode)
{
}
/**
* Consumes a tree node
* and does zilch with it
*
* Params:
* treeNode = the node
*/
public void Nothing(Tree!(T));
}
/**
@ -660,8 +668,6 @@ public template TouchStratergy(T)
public alias TouchStratergy = void delegate(Tree!(T) item);
}
// TODO: Technically this is a graph
public class Tree(T)
{
@ -751,7 +757,7 @@ public class Tree(T)
return false;
}
private static bool isTreeNodeType(E)()
{
return __traits(isSame, E, Tree!(T));
@ -762,6 +768,15 @@ public class Tree(T)
return __traits(isSame, E, T);
}
/**
* Returns a slice of the requested
* type. This is either `Tree!(T)`
* or `T` itself, therefore returning
* an array of either
*
* Returns: an array of the requested
* type of children
*/
public E[] opSlice(E)()
if(isTreeNodeType!(E) || isTreeValueType!(E))
{
@ -784,11 +799,33 @@ public class Tree(T)
}
}
/**
* Returns an array of all the childrens'
* associated values
*
* Returns: a `T[]`
*/
public T[] opSlice()
{
return opSlice!(T)();
}
/**
* Returns the element of the child
* at the given index.
*
* The type `E` can be specified
* as either `Tree!(T)` or `T`
* which will hence return a node
* from the children array at the
* given index of that tyope (either
* the child node or the child node's
* value).
*
* Params:
* idx = the index
* Returns: the type `E`
*/
public E opIndex(E)(size_t idx)
if(isTreeNodeType!(E) || isTreeValueType!(E))
{
@ -804,6 +841,15 @@ public class Tree(T)
}
}
/**
* Returns the value of
* the child node at
* the provided index
*
* Params:
* idx = the index
* Returns: the value
*/
public T opIndex(size_t idx)
{
return opIndex!(T)(idx);