My alernative for nested datasets for arbitrary deep hierarchical datasets: good or bad?

When I recreate my CMS, I need an alternative to the traditional parent / child approach for managing the sitemap / page hierarchy. I remembered that some time ago I saw a model of a nested set, but I could not remember how it was called. So I came across a similar approach, which I want to evaluate and compare properties, making sure that I will not confuse the restrictions later, because I did not go with what has already been tested by time. So, please let me know if A) it has already been invented (what is it called ?!), B) there are fundamental flaws in the properties, or C) it is a good approach (please give a good justification!).

Consider this list:

  • the main
    • About us
    • Contact us
    • Products
      • clothing
      • Books
      • Electronics
    • Knowledge base
    • Other things

According to the nested set model, I believe that you keep the descriptors left / right for each node with a depth traversal:

Home 1-18 About Us 2-3 Contact Us 4-5 Products 6-13 Clothing 7-8 Books 9-10 Electronics 11-12 Knowledge Base 14-15 Other stuff 16-17 

And here is my “wrong way”, which I’m starting to like better:

 Home 1-9 About Us 2-2 Contact Us 3-3 Products 4-7 Clothing 5-5 Books 6-6 Electronics 7-7 Knowledge Base 8-8 Other stuff 9-9 

Instead of the left / right pair, I save the identifier and LAST_CONTAINED_ID. I found that many properties are the same (or very similar):

  • The root of the node is ID = 1
  • For "leaves", both properties are equal, but with branches - not
  • The total number of "trays" for any given node is LAST_CONTAINED_ID - ID
  • All contained nodes have identifier> container identifier, but <= container LAST_CONTAINED_ID
  • Ancestor nodes have the identifier <child identifier, as well as LAST_CONTAINED_ID> = child identifier
  • Depth is the SUM of the ancestor nodes

In addition, the identifier serves as a unique unique identifier (no spaces!). It was also easier for me to store DEPTH and PARENT links for simplicity, but this is almost the same for nested sets, too, from what I understand.

So, is this considered a nested set? And this is a general approach (but why haven't I heard about this before ...)? Is there a good reason why I should use a real nested set over this?

I welcome your thoughts.

+7
source share
1 answer

The only advantage it gives is the “no spaces” function, but to achieve this you had to change the logic applied to the right values. In the original model, you get the children from the “Products” by seeing all these values ​​6 <.. <13, but in your model you get these children by seeing the values ​​4 <.. <= 7. When considering the right values ​​that are different from the left values He becomes a little less elegant.
Another minor problem is that in the original, a jump from 12 to 14 emphasizes that you have changed the level, while in your model you will not receive such visual signals.
Therefore, if you are happy to use (<, <=) instead of (<, <), then it works. (Since it seems equivalent, I cannot say “good” or “bad”, but you have already pointed out the danger of implementing a path that traveled less.)

+4
source

All Articles