IMO, it's a dangerous thing to hold VISUAL information in a data structure in a database. Seems shortsighted.
IMO, it's a dangerous thing to hold VISUAL information in a data structure in a database. Seems shortsighted.
What's the response here? "No, that can't possibly be true"?
You Aren't Gonna Need It is a celebrated building heuristic for a reason. You Should Always Assume You Need It simply isn't true.
I'm not talking about learning how to balance a binary tree in the most efficient way possible. I'm talking about the basic ops of breadth- and depth-first traversals of arbitrary trees.
I feel like we live in an era of software development that took a stupid meme about "inverting a binary tree" as a job interview question and--not knowing anything about trees--turned it into received wisdom that "trees are hard".
But they just aren't. And yet so many people live in fear of them and go to great lengths to avoid having to learn how to use them.
So I think the easiest way would be to store as order/indent first and later migrate to parent/child when you implement features that need it.
The only change I'd do is to define "indent" more abstractly as the item's depth in the tree and not literally the number of spaces you want to render. That makes it a lot easier to spot invalid data, makes later migration easier - and also gives you more UI flexibility, because it allows you to change the rendering method or make it configurable per user (nested <ul>'s/<ol>'s, tabs, 8 spaces, 4 spaces, 1 space, etc)
struct item_t {
char key[255];
char display_value[255];
}
And your key has consistent path separators like a/b/cThen looking up parents and children is incredibly easy. At worst it's a linear scan of the array, but if it's in order you can even just look at previous items in the list until you're at the parent.