Created
May 19, 2018 00:04
-
-
Save ixv/bdff882863ff089cae1bd8ad5ff36e76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/? 310 | |
!: | |
:: | |
:: make a new empty graph like so: | |
:: `(graph @ @)`[~ ~] | |
:: | |
|% | |
++ graph | |
|* {a/mold b/mold} | |
$: nod/(map id/@ {dat/a adj/(set @)}) :: nodes | |
edg/(map id/@ {from/@ to/@ dat/b}) :: edges | |
== | |
:: | |
++ ge | |
|_ g/(graph) | |
+- add-node | |
|* {i/@ a/*} | |
^+ g | |
:- | |
(~(put by nod.g) i [a (sy ~)]) | |
edg.g | |
+- del-node | |
|= a/@ | |
^+ g | |
=+ b=(~(get by nod.g) a) | |
?~ b | |
g | |
?: =(~(wyt in adj.u.b) 0) | |
[(~(del by nod.g) a) edg.g] | |
=+ c=(~(tap in adj.u.b)) | |
=+ e=g | |
=+ i=0 | |
|- | |
=+ d=(snag i c) | |
=. e (~(del-edge ge e) d) | |
?. =((lent c) +(i)) | |
$(i +(i)) | |
[(~(del by nod.e) a) edg.e] | |
+- add-edge | |
|* {id/@ from/@ to/@ dat/*} | |
^+ g | |
=+ b=(~(add-adj ge g) from id) | |
=. b (~(add-adj ge b) to id) | |
:- | |
nod.b | |
(~(put by edg.b) id [from to dat]) | |
+- del-edge | |
|= a/@ | |
^+ g | |
=+ b=(~(get by edg.g) a) | |
?~ b | |
g | |
=+ c=(del-adj from.u.b a) | |
=. c (~(del-adj ge c) to.u.b a) | |
:- | |
nod.c | |
(~(del by edg.g) a) | |
+- add-adj | |
|= {n/@ e/@} | |
^+ g | |
=+ a=(~(get by nod.g) n) | |
?~ a | |
!! | |
=+ new=[dat.u.a (~(put in adj.u.a) e)] | |
[(~(put by nod.g) n new) edg.g] | |
+- del-adj | |
|= {n/@ e/@} | |
^+ g | |
=+ a=(~(get by nod.g) n) | |
?~ a | |
!! | |
=+ new=[dat.u.a (~(del in adj.u.a) e)] | |
[(~(put by nod.g) n new) edg.g] | |
-- | |
-- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment