itacart.intervals

Intervals: a region as sorted ranges of integers, with set operations.

The Multi-Order Coverage maps of the IVOA store a region of the HEALPix sky as a list of half-open ranges of cell numbers at one depth, and do union, intersection and difference on those lists by merging them. This module does the same for ITACaRT, on the integers of itacart.integer_index.

An interval list is a list of (start, stop) pairs of integers, sorted, disjoint and with no two touching, every integer of one resolution: the depth of the list, which the integers carry with them. A cell coarser than the depth stands for its descendants at the depth, and away from the domain border those are a single range, because the integers of a cell’s descendants are consecutive. The overlap of two parcels, or of an obstacle and a flight corridor, is then one intersection of two lists, in time linear in their lengths.

The semantics is the region’s, and a region in this package is physical. A cell whose outer side has been carried onto the domain border has children spelled under the next column’s prefix, outside the range its own integers span, and the range would also hold addresses past the border that name no cell. Such a cell is expanded through its physical children, as itacart.get_children() gives them, down to the depth. Everywhere else the range is exact: a cell that does not absorb the border has exactly its lexical descendants as children, at every depth.

The depth is chosen, as a coverage map’s is, and it is not fixed at 13. The border family thins with depth but does not end, so a cell that absorbs the border has one absorbing descendant per row at every resolution below it – a thousand at resolution 7 under a resolution-1 cell, a million at resolution 13. Pinning every list to resolution 13 would turn one border cell into a million ranges. The default depth is the finest resolution the index holds, which keeps the cost proportional to the region’s own boundary at its own resolution. Two lists of different depths are brought to the finer one before they are combined, which is exact, because a coarser list names whole cells.

Back from intervals to an index, the answer is what itacart.compact_cells() writes, so its TreeBlob is the one itacart.serialize_to_blob() writes for the region. That holds for every index whose cells do not overlap; an index that writes a cell and, under another column’s prefix, a child of it, compacts with the child kept and comes back from its intervals without it.

Functions

cells_to_intervals

The region an index names, as an interval list.

intervals_contain

Whether every position of the second list is in the first.

intervals_count

How many cells of the list's depth the list covers.

intervals_difference

Every position of the first list that is not in the second.

intervals_intersection

Every position in both lists, by one merge of the two.

intervals_overlap

Whether the two lists share a position.

intervals_to_cells

The index of the region an interval list covers.

intervals_union

Every position in either list.