Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a number of useful functions #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gampleman
Copy link

I've added a number of useful functions. I appreciate that perhaps it would be slightly easier to review each in isolation, but I didn't quite have the time to slice everything up. So perhaps this can be a place to discuss the merits of the added functions and maybe another PR can than add whatever seems reasonable.

This adds:

  1. mapWithContextBottomUp, mapAccumulateWithContextBottomUp, mapWithContextTopDown, mapAccumulateWithContextTopDown. These are very useful ways to map a tree, because in many applications of tree you need to have some information about the relationships of a node, not just it's label to create the proper transformation (for instance, one can use these to define ways to sum up quantitative information from the leaves into parent nodes, etc.). Once you add this context, the exact order in which the operation is performed becomes rather paramount.

  2. depth is similar to count, but counts the number of levels in a tree. Very handy for drawing tree based visualisations, since this allows you to estimate how big to draw every layer of the tree to fit the whole thing in a fixed area.

  3. leaves is somewhat similar to flatten in that it returns a list, but in this case it only returns the leaves of the tree. My personal usecase is that for some treemaps you only really want to draw the leaf nodes, as the structure of the tree is implied by their layout.

  4. links is again super useful for drawing trees, as generally this makes is the basis of drawing all the squiggly lines that actually connect the nodes. Another usecase is for laying out trees, as you can feed this into a many-body force simulation to lay out a force based tree layout.

  5. findBfs finding stuff in trees is a pretty common usecase in trees... I names it explicitly with the idea that a future findDfs could be added.

  6. sortWith adds a simple way to change the order of the nodes within the rosetree. Again very useful for drawing trees, as many tree layout algorithms tend to provide more pleasing results when the nodes are sorted. I suppose that a sort and sortBy variant could easily be provided, but they are rather trivially derived, so I didn't bother for now.

- depth
- leaves
- links
- context maps (bottom up and top down, with and without accumulator)
- findBfs
- sortWith
@gampleman gampleman mentioned this pull request Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant