Skip to content

Instantly share code, notes, and snippets.

@okram
Last active July 9, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okram/40d3ed2e8cf06e05507d775e6520b0c2 to your computer and use it in GitHub Desktop.
Save okram/40d3ed2e8cf06e05507d775e6520b0c2 to your computer and use it in GitHub Desktop.
// kv-ADT
[define,kvstore<=kv{*},kv:('k'->obj,'v'->obj)]
// tp3-ADT
[define,graph:('V'->vertex{*},'E'->edge{*}),
vertex:('id'->obj,'label'->str,'properties'->property{*},'outE'->edge{*},'inE'->edge{*}),
edge:('id'->obj,'label'->str,'properties'->property{*},'outV'->vertex,'inV'->vertex),
property:([is,!['id'|'label']]->obj)]
// functor from kv-ADT to tp3-ADT
[define,graph<=kvstore-<('V'->.0[is,.k.0=='vertex'],
'E'->.0[is,.k.0=='edge']),
vertex<=kv:('k'->(is=='vertex',obj),'v'->(str->obj))<x>-<
('id' -> .k.1,
'label' -> [.v.label|.k.0],
'properties' -> .v,
'inE' -> g.E[is,.v.link.1==x.k.1],
'outE' -> g.E[is,.v.link.0==x.k.1]),
edge<=kv:('k'->(is=='edge',obj),'v'->('link'->(obj,obj),str->obj{*}))<x>-<
('id' -> .k.1,
'label' -> [.v.label|.k.0],
'outV' -> g.V[is,.k.1==x.v.link.0],
'inV' -> g.V[is,.k.1==x.v.link.1]),
kvstore<=-<(db),g<=_,db<=_]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment