Its been a year since I started with my contributions to the Scala community, in particular to Typelevel / Dogs. I have worked on different parts of the project including testing it and benchmarking it, yet I most proud of implementing Discrete Interval Encoding Tree in a pure functional fashion. We call it Diet.
Diet is quite interesting since it stores ranges of a type A and can operate on those ranges in a very smart way. A problem with this particular data structure is that even thought it is not that complicated, people have hard times understanding it. With Dogs we have done some work on documenting the libraries, yet, Diet (and others) are sometimes hard to explain.
RefTree is a project I came across recently for visualizing data structures and it is helping us now to write a cleaner documentation.
Using RefTree we can visualize data structures in a really easy way. Let’s explore this project a bit.
If you look at the demo and examples you will find visualizations like these ones.
First, let’s add some libs to our sbt file.
Notice we are also including dogs.
Let’s do some imports and create an instance of Diagram which is required to create the visualizations.
The options we used for creating a Diagram are self describing.
Let’s build a empty Diet and then visualize it.
In here we defined a way to covert Diet[A] to RefTree and use it for rendering empty. This will create the following image.
Let’s add values to our empty Diet and render it again.
We can now create a Diet of a single node and remove a subrange.
This will give us back and animation representing the transformations on d
A more interesting example could be the following.
Just notice that we are using Utils.iterate which is a function from RefTree to construct data structures easily. The result will be the following animation.
Personally, I believe this library (RefTree) has a lot of potential and use cases. We are already adding animations to Dogs documentation to make the data structures we built easier to understand and use.
Although the RefTree API is still young, it works quite well and its maintainer was of a lot of help while we built our demo.
Thank you, @nickstanch for this awesome lib.