4

I'm looking at the augmented tree in the interval tree article, and looking at rbtrees.pl in the SWI-Prolog standard library. The article says:

An extra annotation is then added to every node, recording the maximum upper value among all the intervals from this node down. Maintaining this attribute involves updating all ancestors of the node from the bottom up whenever a node is added or deleted.

It's easy for me to see how to add this annotation. Suppose I want to store the interval 7-45. I use 7 as the key and for my value I use a structure with all my info, so something like interval(7-45, MaxBelow). But it is not clear to me how I would then “update all ancestors of the node” because after rb_insert/4. I don't see a way to get a list of all the nodes that got changed between the before and after trees (it would probably be odd and inefficient to generate such a list anyway).

Is there a way forward with this approach to build this structure with rbtrees.pl?

Incidentally, it's interesting to me that rb_empty uses an uninstantiated variable as the empty node; is there a reason for this?

Edit: it occurs to me I could examine the before-and-after trees and try unifying the branches before and after to find the path of where it has changed. Is that going to subvert the performance improvement I'm after?

Daniel Lyons
  • 22,421
  • 2
  • 50
  • 77
  • 1
    What about designing a corresponding library that permits arbitrary comparison? Thus, such a library could be pure, too? – false Dec 06 '15 at 10:13
  • that code supports Key-Value nodes; Values and Keys do not change; a node's annotation might get changed by a rotation operation during tree rebalancing; it seems to me you'll have to actually modify the library code throughout. – Will Ness Dec 06 '15 at 15:13

0 Answers0