1 ! Copyright (C) 2008 William Schlieper <schlieper@unc.edu>
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: accessors kernel sequences arrays vectors sets assocs hashtables graph-theory namespaces fry ;
6 IN: graph-theory.sparse
8 TUPLE: sparse-graph alist ;
10 : <sparse-graph> ( -- sparse-graph )
11 H{ } clone sparse-graph boa ;
13 : >sparse-graph ( graph -- sparse-graph )
15 '[ dup _ adjlist 2array ] map >hashtable sparse-graph boa ;
17 INSTANCE: sparse-graph graph
19 M: sparse-graph vertices
22 M: sparse-graph adjlist
25 M: sparse-graph add-blank-vertex
26 alist>> V{ } clone -rot set-at ;
28 M: sparse-graph delete-blank-vertex
31 M: sparse-graph add-edge*
32 alist>> swapd at adjoin ;
34 M: sparse-graph delete-edge*
35 alist>> swapd at delete ;