sschuldenzucker
Hey all, I’m building my own little app (side project) and I’m looking for a tree data structure. I’m honestly wondering if I’m overlooking something but I couldn’t find a library that’s right for me.
The whole thing should be “generic” (think, like a DOM), i.e., like this:
- Arbitrary number of children per node.
- Children are ordered.
- Easy to traverse. E.g. there should be “get sibling right after this”, “get parent” etc.
- Effiiciently find child by node ID (no zipper; I wanna build a microservice that manages the tree)
I could use a digraph from Erlang but it’s actually too flexible for my use case and would require a wrapper around it to make sure nobody’s creating a loop.
In particular 5. seems hard to satisfy with the libraries I found.
Do you guys agree that there’s currently no library that does this? Any advice on how I would build this without going crazy?
Thanks a lot!
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
Not sure I’m following the problem here - you can pass
:acyclicto:digraph.new/1and the library will handle enforcing that restriction.I only see 4 numbered bullet points, did something get lost in editing?
“Generic” is hard. Different implementations are going to have seriously different performance (both time and space) for specific operations.
For instance, a tree implemented as a closure table can answer queries like “what are all the descendants of this node” very efficiently. But moving a subtree in that implementation is very slow, because it needs to touch many rows for each element of the subtree.
An adjacency-list representation (aka “put a
parent_idcolumn on the record”) has the opposite properties: moving an entire subtree only needs to update theparent_idon the subtree’s root, but checking for descendants requires recursive CTEs or other SQL trickery.sschuldenzucker
Hey, thx for the pointers.
Regarding
:acyclic: This would definitely make it better but acyclic digraphs can still have undirected cycles (two nodes pointing to the same child), so it’s not enough. I guess you can get around that by restricting the access methods a bit more (e.g., don’t allow adding edges, just moving nodes).Oh, and in a digraph, the children of a node (aka. the edges going out of a node) are not ordered, right?
Regarding 5., this should’ve been 4. (no zippers).
Regarding “generic”, of course you’re right. I think for my use case, local operations (what’s the parent / next sibling / children / etc.; move this subtree somewhere else) should be enough. So adjacency lists are probably the way to go.
I suppose all of these things are not fundamentally hard, was just wondering if someone already did it.
petrus-jvrensburg
Would the Postgres Ltree datatype help?
sschuldenzucker
NB I’ve built something based on IDs (essentially doing the usual pointer rotations in a set of maps). Will publish something not too far out.
user20230119
Did you publish something?