1 USING: arrays assocs kernel vectors sequences namespaces
2 random math.parser math fry ;
6 : set-assoc-stack ( value key seq -- )
7 dupd [ key? ] with find-last nip set-at ;
9 : at-default ( key assoc -- value/key )
10 dupd at [ nip ] when* ;
12 : replace-at ( assoc value key -- assoc )
13 [ dupd 1vector ] dip rot set-at ;
15 : peek-at* ( assoc key -- obj ? )
16 swap at* dup [ [ peek ] dip ] when ;
18 : peek-at ( assoc key -- obj )
21 : >multi-assoc ( assoc -- new-assoc )
22 [ 1vector ] assoc-map ;
24 : multi-assoc-each ( assoc quot -- )
25 [ with each ] curry assoc-each ; inline
27 : insert ( value variable -- ) namespace push-at ;
29 : generate-key ( assoc -- str )
30 [ 32 random-bits >hex ] dip
31 2dup key? [ nip generate-key ] [ drop ] if ;
33 : set-at-unique ( value assoc -- key )
34 dup generate-key [ swap set-at ] keep ;
36 : histogram ( assoc quot -- assoc' )
38 swap [ change-at ] 2curry assoc-each
41 : ?at ( obj assoc -- value/obj ? )
42 dupd at* [ [ nip ] [ drop ] if ] keep ;
44 : if-at ( obj assoc quot1 quot2 -- )
45 [ ?at ] 2dip if ; inline
47 : when-at ( obj assoc quot -- ) [ ] if-at ; inline
49 : unless-at ( obj assoc quot -- ) [ ] swap if-at ; inline