moczarr.ranges
Interval substrate for the MOC-backed lazy index — numpy-only, no I/O.
The lazy index (phase 5, espg/moczarr#1) holds open_hive's row domain as
a set of intervals instead of a materialized morton coordinate. zagg
leaves are dense within a shard, so the domain is pure arithmetic: shard word
→ one contiguous subtree run at cell_order, AOI intersection → interval
intersection. No cell arrays are read to know the coordinate.
Rank space, not word space (the phase-5 probe finding): packed morton
words at a fixed cell order are NOT unit-stride across a shard subtree —
mortie packs the base+digit field MSB-aligned with an order marker in the
low bits, so consecutive rank tails differ by a large power-of-two stride.
But word >> shift (the base+digit field alone) IS unit-stride: it is a
global rank coordinate K at the cell order, contiguous across
rank-consecutive shard subtrees (verified across sibling and parent-crossing
boundaries) and monotonic everywhere words are. Base blocks are mutually
contiguous in K — mortie packs +1..+6 into blocks 1..6 and
-1..-6 into blocks 7..12 densely, with only block 0 unused — so
_coalesce may merge intervals straight across a base or hemisphere seam
(the +6/-1 boundary merges into one interval; pinned in
tests/test_ranges.py). Correctness rests on that adjacency-merging being
safe, not on any inter-base gap existing. All intervals here therefore live
in K space, inclusive [lo, hi]; words convert at the boundaries via
word = (K << shift) | marker. The
(shift, marker) pair is derived empirically from mortie's own packing at
construction (two morton_word calls, cached) — never hardcoded — and
subtree spans are re-checked against 4**depth, so packing drift raises
instead of mis-ranking.
Single cell order by construction (a store's cell coordinate is one order); mixed-order domains (pyramids, zagg#262) are the named phase-5 seam — intervals-per-order is the natural extension, gated with issue #8 on mortie#116.
MortonRanges
A sorted disjoint interval set over morton cells at one fixed order.
The four ops the lazy index needs — membership, rank, positional take,
interval intersect — are all searchsorted/cumsum arithmetic on the
(n, 2) K-space intervals array. The concatenated ascending run of
all covered cells is the domain: rank maps words to domain
positions, take maps positions back, fabricate materializes the
whole thing (the only op that allocates O(size)).
Source code in src/moczarr/ranges.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
size
property
Number of cells in the domain.
equals(other)
Same domain: same cell order and identical intervals.
Source code in src/moczarr/ranges.py
382 383 384 385 386 387 388 | |
fabricate()
Materialize the whole domain as ascending packed words (uint64).
The one O(size) allocation; byte-equal to the coordinate the eager opener builds (the phase-5 money property).
Source code in src/moczarr/ranges.py
370 371 372 373 374 375 376 377 378 | |
from_cell_words(words, cell_order=None)
classmethod
Run-detect an explicit strictly-ascending cell-word array.
The materialized→lazy direction (MortonMocIndex.from_variables).
cell_order defaults to the order the words themselves carry;
mixed orders or a non-ascending array raise (mirroring aoi_mask's
raise-on-ambiguity discipline).
Source code in src/moczarr/ranges.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
from_root_coverage(envelope, cell_order)
classmethod
The domain a root "ranges" envelope declares, at cell_order.
One interval per envelope range, WITHOUT the O(covered shards)
expansion of :func:moczarr.coverage.ranges_words: consecutive-rank
shard subtrees are contiguous in K space, so [lo_shard, hi_shard]
maps to [first cell of lo, last cell of hi] directly. Same
validation posture as ranges_words — malformed ranges raise (a
corrupt cache must never yield a plausible partial domain) — plus
the span re-check as the packing-drift guard.
Source code in src/moczarr/ranges.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
from_shards(shard_words, cell_order)
classmethod
Subtree runs of shard words: one interval per shard at cell_order.
Shards may sit at any order <= cell_order (each word carries its
own); duplicates and rank-adjacent shards merge. Every subtree span
is re-checked against 4**depth (the packing-drift guard).
Source code in src/moczarr/ranges.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
intersect(aoi)
The sub-domain an AOI morton cover keeps — aoi_mask in interval space.
Source code in src/moczarr/ranges.py
264 265 266 | |
intersection(other)
Set intersection with another interval set at the same order.
Source code in src/moczarr/ranges.py
268 269 270 271 | |
member(words)
Boolean mask: which words the domain contains (order marker included).
Source code in src/moczarr/ranges.py
308 309 310 311 | |
rank(words, missing=None)
Positions of words in the ascending domain (int64).
Non-members raise KeyError by default; missing=<fill> maps
them to that value instead (the reindex posture).
Source code in src/moczarr/ranges.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
subset(indexer)
The sub-domain at positional indexer (slice or integer array).
A unit-step slice clips intervals in position space (no
materialization). Integer arrays must be strictly increasing after
negative-wrap — an interval set has no reordering freedom — so a
non-monotonic or duplicated indexer raises ValueError (the index
layer degrades to dropping the lazy index in that case).
Source code in src/moczarr/ranges.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
take(positions)
Words at domain positions (uint64); negatives wrap, OOB raises.
Source code in src/moczarr/ranges.py
332 333 334 335 336 337 338 339 340 341 | |
union(other)
Set union with another interval set at the same order.
Source code in src/moczarr/ranges.py
273 274 275 276 | |