[ < ] [ > ] [ << ] [ 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.

 54.1 Introduction to Range Tables Range tables efficiently map ranges of integers to values. 54.2 Working With Range Tables Range table functions.

 [ < ] [ > ] [ << ] [ 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.

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

## 54.2 Working With Range Tables

Function: get-range-table pos range-table &optional default
This function finds value for position pos in range-table. If there is no corresponding value, return default (defaults to `nil`).

NOTE: If you are working with ranges that are closed at the start and open at the end (the default), and you put a value for a range with start equal to end, `get-range-table` will not return that value! You would need to set end one greater than start.

Function: put-range-table start end value range-table
This function sets the value for range (start, end) to be value in range-table.

NOTE: Unless you are working with ranges that are closed at both ends, nothing will happen if start equals end.

Function: remove-range-table start end range-table
This function removes the value for range (start, end) in range-table.

Function: clear-range-table range-table
This function flushes range-table.

Function: map-range-table function range-table
This function maps function over entries in range-table, calling it with three args, the beginning and end of the range and the corresponding value.

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

This document was generated by XEmacs Webmaster on August, 3 2012 using texi2html