ubIter ... +UB

2 min read
+UB - префиксный класс для +Aux, поддерживающий индекс UB-Tree вместо прямых значений. Это обеспечивает эффективный диапазонный доступ к многомерным данным. Поддерживаются только положительные числовые ключи.
(class +Pos +Entity)
(rel x (+UB +Aux +Ref +Number) (y z))
(rel y (+Number))
(rel z (+Number))
: (scan (tree 'x '+Pos))
(288362200753438306 . {13}) {13}
(348187139486943716 . {16}) {16}
(605261596962573238 . {11}) {11}
(638523558602802506 . {7}) {7} # UBKEY of (453062 450921 613956)
(654697989157410399 . {12}) {12}
...
: (show '{7})
{7} (+Pos)
x 453062
y 450921
z 613956
-> {7}
# Discrete queries work the same way as without the +UB prefix
: (db 'x '+Pos 453062 'y 450921 'z 613956)
-> {7}
: (aux 'x '+Pos 453062 450921 613956)
-> {7}
: (? (db x +Pos (453062 450921 613956) @Pos))
@Pos={7}
-> NIL
# Range queries work efficiently with 'collect'. Note that though also Pilog
queries can handle UB-trees, they may do so sub-optimally for certain ranges.
: (collect 'x '+Pos (200000 200000 200000) (899999 899999 899999))
-> ({7} {14} {17} {15})
ubIter - эффективно выполняет итерации по дереву +UB базы данных, применяя fun
ко всем значениям. dim
— это количество измерений ключа, lst1
и lst2
указывают диапазон ключей. collect использует ubIter внутренне для запросов UB-tree.
(ubIter 'tree 'dim 'fun 'lst1 'lst2)
: (ubIter (tree 'x '+Pos) 3 show (200000 200000 200000) (899999 899999 899999))
{7} (+Pos)
z 613956
y 450921
x 453062
{14} (+Pos)
z 771372
y 262217
x 862358
{17} (+Pos)
z 676836
y 529576
x 398229
{15} (+Pos)
z 889332
y 691799
x 265381
-> NIL
0
Subscribe to my newsletter
Read articles from Sergey Shishkin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sergey Shishkin
Sergey Shishkin
Всегда чему-то учусь!