\ Set aggregation vandys
\ Much like an "AgBtree" creates an aggregate view of a list of B-trees,
\ an "AgSet" creates an aggregate view of a list of sets.
only extensions definitions
AgView -> subclass: AgSet
\ Set aggregation vandys
variable doFn scrLocal variable aglist scrLocal variable idx scrLocal
: already? ( key -- ? ) idx @ 0 ?do dup i aglist @ -> @
-> in? if unloop drop true exit then
loop drop false ; scrLocal
: (do) ( arg key -- ) dup already? if 2drop exit then
doFn @execute ; scrLocal
AgSet -> :method do ( arg 'fn self -- ) swap doFn !
ag>list dup aglist ! -> size 0 ?do
( arg ) dup i dup idx ! aglist @ -> @ ( arg arg set )
['] (do) swap -> do loop drop method;
\ Set aggregation; testing vandys
false [if] \ Testing
Set -> new constant s1 Set -> new constant s2
AgSet -> new constant as s1 as -> agadd s2 as -> agadd
1 s1 -> add 2 s1 -> add 3 s1 -> add
100 s2 -> add 101 s2 -> add 102 s2 -> add
200 as -> add
300 s1 set! 300 s2 set!
12321 constant KEY
: andy ( arg key -- ) . KEY - abort" Key mismatch" ;
: t1 KEY ['] andy as1 agsetDo ;
as -> free
[then] \ Testing
vandys
An AgSet is an aggregate view of a List of Set's
User 'fn, list of ag elems, and current index in list
: already? Tell if the given key has been fed to the 'fn
already due to its presence in an outer set of the aggregate
: (do) Iterator; call user 'fn unless they've already
seen this key
:method do Iterate all keys in all sets in the aggregate view
TBD: As in agbt, one can wonder if we should shoot for greater efficiency
by running parallel iterations across all the sets. This is harder than
in the B-tree case, because there is no ordering of the keys