Col-E / ExtraCollections

Extra useful collection types and utilities
MIT License
6 stars 1 forks source link

Custom collection type: Trees #4

Closed Col-E closed 2 years ago

Col-E commented 2 years ago

Idea:

interface Tree<T> {
    T data();
    Tree<T> parent();
    List<Tree<T>> children();
}

May want a keyed variant too:

interface KeyedTree<K, T> extends Tree<T> {
    Map<K, Tree<T>> keyedChildren();
}

Assuming both are implemented, having an add(...) type would be nice on the core Tree type. But this would mean the keyed type would then have to derive K from T if it wanted to adapt to a put(...) sort of operation....


What degree of detail in offered implementations should be offered? For instance, some types of trees: https://www.educative.io/blog/data-structures-trees-java

Col-E commented 2 years ago

https://github.com/Col-E/ExtraCollections/commit/a813bf87f50c1a9ebe7df1ba2ba6ed0a3ed76fc0