1 ! Copyright (C) 2006, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs kernel namespaces sequences sets ;
8 : if-graph ( vertex edges graph quot -- )
10 [ graph swap with-variable ]
11 [ 2drop 2drop ] if ; inline
13 : nest ( key -- hash )
14 graph get [ drop H{ } clone ] cache ;
16 : add-vertex ( vertex edges graph -- )
17 [ [ dupd nest set-at ] with each ] if-graph ; inline
19 : (add-vertex) ( key value vertex -- )
22 : add-vertex* ( vertex edges graph -- )
24 swap [ (add-vertex) ] curry assoc-each
27 : remove-vertex ( vertex edges graph -- )
28 [ [ graph get at delete-at ] with each ] if-graph ; inline
30 : (remove-vertex) ( key value vertex -- )
31 rot graph get at delete-at drop ;
33 : remove-vertex* ( vertex edges graph -- )
35 swap [ (remove-vertex) ] curry assoc-each
40 : (closure) ( obj quot: ( elt -- assoc ) -- )
41 over previous get key? [
44 over previous get conjoin
46 [ nip (closure) ] curry assoc-each
47 ] if ; inline recursive
49 : closure ( obj quot -- assoc )
51 previous [ (closure) ] with-variable