\ AgView--aggregate view of some underlying set of data structures vandys
\ AgView is a generic class for holding a list of data structures, and
\ permitting the aggregate to be a polymorphic representation of the
\ member elements. XYZZY
only extensions definitions
Collection -> subclass: AgView ivars: intcell list endivars
AgView -> class -> :method new ( self -- agbt ) super-> new
List -> new over AgView>list ! method;
: ag>list ( agbt -- list ) AgView>list @ ;
AgView -> :method free ( self -- )
dup ag>list -> free super-> free method;
AgView -> :method agadd ( elem self -- ) ag>list -> add method;
AgView -> :method ! ( val key self -- ) ag>list -> last -> ! method;
AgView -> :method add ( elem self -- ) ag>list -> last -> add method;
: (.ag) ( 0 elem -- ) nip -> . ; scrLocal
AgView -> :method .elems ( self -- ) 0 ['] (.ag)
rot ag>list -> do method;
\ AgView--aggregate view of some underlying set of data structures vandys
variable (agCount) scrLocal
: (agSize) ( 0 bt -- ) nip -> size (agCount) +! ; scrLocal
AgView -> :method size ( self -- u ) (agCount) off ag>list
0 ['] (agSize) rot -> do (agCount) @ method;
AgView -> :method in? ( key self -- ? ) ag>list { key list }
list -> size 0 ?do i list @ { elem } key elem -> in? if
unloop true exit then
loop false method;
\ AgView key manipulation vandys
variable (agKey) scrLocal
: (agnextKey) ( key ag -- ) -> nextKey if (agKey) @ ?dup if min then
(agKey) ! then ; scrLocal
AgView -> :method nextKey ( key ag -- key' T | F ) ag>list
(agKey) off ['] (agnextKey) swap -> do
(agKey) @ ?dup 0<> method;
: (agtopKey) ( 0 bt -- ) nip
-> topKey (agKey) @ max (agKey) ! ; scrLocal
AgView -> :method topKey ( ag -- key ) ag>list
(agKey) off 0 ['] (agtopKey) rot -> do
(agKey) @ method;
AgView is an aggregate view of a List of some other data structure
:method new Allocate a new view, with an initially empty list
: ag>list Turn our instance pointer into the List of the elems
:method free Release list storage, then free ourselves via superclass
:method agadd Add an outer layer
:method ! Store key/value to outermost elem
:method add Store new member to outermost elem
Counter of size of each constituent
: (agSize) Iterator for accumulating size from a single B-tree
:method size Size of aggregate--only an approximation, since values
from inner members may "cover" the same value in an outer
Local tally of keys seen
: (agnextKey) Iterator for picking next highest key from the given one
:method nextKey Return next key available in ag
: (agtopKey) Iterator for finding highest key among all B-trees
:method topKey Return highest key among any member in our aggregate