Re: Nested set model with large gaps and spreads in the numbering

From: Kendall <kendallwillets_at_yahoooo.com>
Date: Mon, 16 Sep 2002 21:28:00 -0700
Message-ID: <pan.2002.09.16.21.27.56.597.2130_at_yahoooo.com>


In article <c0d87ec0.0209131524.42b8085b_at_posting.google.com>, "--CELKO--" <71062.1056_at_compuserve.com> wrote:

>>> I'm a bit confused about what this is trying to achieve, but it

> looks like a lot of work, so why not try this: .. <<
>

(OK, got it - just needed a reality check.)

> That is the standard way to close up all the gaps in a Nested Sets
> model. But what I want to do is keep the spread the same and close only
> the gaps. A spread is defined as (rgt -lft) -- the size of a given node
> and how much roo it has for children. A gap is the different between
> the (rgt) value of one and the (lft) value of its sibling on the
> immeidate left or right side.
>
> I want to retain the spread, but close the gaps by moving the nodes to
> the left. This will leave me with a single large gap on the right of
> each parent.

>

I guess I have misgivings about where the free space is needed - between the siblings would be one place, but you're squishing them together.

If you want to slide all the siblings on all the levels together, you're going to have to accumulate the offset starting from root. There's a proc at http://willets.org/superdfs.sql that does the same thing with no offset - it just calculates the preorder numbering by adding up the parent's lft and descendant counts across each level.

If you replace descendant counts with spreads you should be able to do the same thing. It's iterative, but I don't see an easy way out otherwise.

> In thought about doing this way, then moving all of the (rgt) values
> further to the right. But frankly, I have been working on my new book
> about "Trees in SQL" for several days straight and my brain is getting
> very tired.
>

This problem is akin to building balanced trees from random data - there's no way that's going to work every time. Received on Tue Sep 17 2002 - 06:28:00 CEST

Original text of this message