Paste: AdjList

Author: Rich
Mode: factor
Date: Tue, 17 Feb 2009 00:59:22
Plain Text |
TUPLE: adjacency-list
{ vertices array } ;

: <adjacency-list> ( n -- adjacency-list )
    -1 nil cons <array> adjacency-list boa ;

:: add-edge ( from to adjacency-list -- adjacency-list )
    from adjacency-list vertices>> array-nth
    dup car -1 =
    [ drop to nil cons from adjacency-list vertices>> set-array-nth ]
    [ to nil cons lappend ]
    if ;

Annotation: new add-edge

Author: Rich
Mode: factor
Date: Tue, 17 Feb 2009 01:07:41
Plain Text |
:: add-edge ( from to adjacency-list -- adjacency-list )
    from adjacency-list vertices>> array-nth
    dup car -1 =
    [ drop to nil cons ]
    [ to nil cons lappend ]
    if 
    from adjacency-list vertices>> set-array-nth 
    adjacency-list ;

New Annotation

Summary:
Author:
Mode:
Body: