[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

54. Range Tables

A range table is a table that efficiently associates values with ranges of fixnums.

Note that range tables have a read syntax, like this:

 
#s(range-table type start-closed-end-open data ((-3 2) foo (5 20) bar))

This maps integers in the range [-3, 2) to foo and integers in the range [5, 20) to bar.

By default, range tables have a type of start-closed-end-open. (NOTE: This is a change from 21.4 and earlier, where there was no type and range tables were always closed on both ends.) This makes them work like text properties.

Function: range-table-p object

Return non-nil if object is a range table.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

54.1 Introduction to Range Tables

Function: make-range-table &optional type

Make a new, empty range table.

type is a symbol indicating how ranges are assumed to function at their ends. It can be one of

 
SYMBOL                                     RANGE-START         RANGE-END
------                                     -----------         ---------
`start-closed-end-open'  (the default)     closed              open
`start-closed-end-closed'                  closed              closed
`start-open-end-open'                      open                open
`start-open-end-closed'                    open                closed

A closed endpoint of a range means that the number at that end is included in the range. For an open endpoint, the number would not be included.

For example, a closed-open range from 5 to 20 would be indicated as ‘[5, 20)’ where a bracket indicates a closed end and a parenthesis an open end, and would mean ‘all the numbers between 5 and 20’, including 5 but not 20. This seems a little strange at first but is in fact extremely common in the outside world as well as in computers and makes things work sensibly. For example, if I say "there are seven days between today and next week today", I’m including today but not next week today; if I included both, there would be eight days. Similarly, there are 15 (= 20 - 5) elements in the range ‘[5, 20)’, but 16 in the range ‘[5, 20]’.

Function: copy-range-table range-table

This function returns a new range table which contains the same values for the same ranges as range-table. The values will not themselves be copied.



[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Aidan Kehoe on December 27, 2016 using texi2html 1.82.