rangesets

Tony Balinski ajbj at free.fr
Mon Nov 6 14:50:39 CET 2006


Quoting "A.V.Kuznetsov" <kuzn at umps.mephi.ru>:

> Hi all,
>
> some rangeset internals are unclear for me.
> Rangesets are a dynamic objects and indexes of ranges are also dynamic.
> What method is used to maintain rangeset?
>
> a) Ranges are indexed in accordance to its positions.
> I.e range opening buffer is first, and range containing $text_length is
> last.
>
> b) Ranges are indexed in an order of its creation.
> I.e. index of first created range is 1 and so on.
>
> c) The following is possible in the case (b) only.
> Two rangesets contain some identical ranges and one rangeset
> is added to other. Are indexes of these ranges changed?
>
> Thanks for any clarification.

The short answer is (a).

If you think of a rangeset as a set of positions in the buffer, the behaviour
may become clearer. From this viewpoint, a range is a set of positions
containing no gaps: a range from p1 to p2 is the range of all positions
p where (p1 <= p < p2). For example, the rangeset A holding positions
  { 1,2,3, 7,8,9 }
has two ranges: [1-]4, [7-]10

After the call rangeset_add(A, 5, 6) we have
  { 1,2,3, 5, 7,8,9 }
or 3 ranges [1-]4, [5-]6, [7-]10

Now add another: rangeset_add(A, 5, 8):
  { 1,2,3, 5,6,7,8,9 }
or 2 ranges [1-]4, [5-]10

So you can see that, whenever you add a range, you may in fact reduce the
number of ranges in the set. So in a sense, ranges have no identity that
continues across rangeset manipulation calls.

Does that help?

Tony


More information about the Discuss mailing list