Interval tree implementation in Prolog w / rbtrees.pl

I look at the added tree in the partition tree and look at rbtrees.pl in the standard SWI-Prolog library. The article says:

Then an additional annotation is added to each node, recording the maximum upper value among all intervals from this node down. Maintaining this attribute includes updating all node ancestors from the bottom up when a node is added or removed.

Itโ€™s easy for me to figure out how to add this annotation. Suppose I want to keep the interval 7-45. I use 7 as a key, and for my value I use a structure with all my information, so something like that interval(7-45, MaxBelow). But I donโ€™t understand how, then, would โ€œupdate all the ancestors of nodeโ€, because after rb_insert/4. I see no way to get a list of all the nodes that were changed between the trees before and after (in any case, it would probably be strange and inefficient to create such a list).

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

By the way, I am wondering what rb_emptyuses an unused variable as an empty node; is there any reason for this?

Edit : It seems to me that I could study the trees before and after and try to combine the branches before and after to find the path to where it changed. Will this undermine the performance improvement that I get after?

+4
source share

Source: https://habr.com/ru/post/1618712/


All Articles