1 ! Copyright (C) 2006, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs kernel namespaces sequences ;
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 ] curry* each ] if-graph ; inline
19 : remove-vertex ( vertex edges graph -- )
20 [ [ graph get at delete-at ] curry* each ] if-graph ; inline
24 : (closure) ( obj quot -- )
25 over previous get key? [
28 over dup previous get set-at
30 [ nip (closure) ] curry assoc-each
33 : closure ( obj quot -- assoc )
35 previous [ (closure) ] with-variable