mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 22:33:06 +03:00
graph-store: first pass at writing %add-nodes poke
This commit is contained in:
parent
83ec7eae24
commit
e52779a356
@ -21,6 +21,7 @@
|
||||
++ on-load
|
||||
|= old=vase
|
||||
^- (quip card _this)
|
||||
::[~ this]
|
||||
[~ this(state !<(state-0 old))]
|
||||
::
|
||||
++ on-poke
|
||||
@ -37,7 +38,138 @@
|
||||
++ graph-action
|
||||
|= =action:store
|
||||
^- (quip card _state)
|
||||
[~ state]
|
||||
|^
|
||||
?- -.action
|
||||
%add-graph (add-graph +.action)
|
||||
%remove-graph (remove-graph +.action)
|
||||
%add-nodes (add-nodes +.action)
|
||||
%remove-nodes (remove-nodes +.action)
|
||||
%add-signatures (add-signatures +.action)
|
||||
%remove-signatures (remove-signatures +.action)
|
||||
%add-tag (add-tag +.action)
|
||||
%remove-tag (remove-tag +.action)
|
||||
==
|
||||
::
|
||||
++ add-graph
|
||||
|= [=resource:store =graph:store]
|
||||
^- (quip card _state)
|
||||
?< (~(has by graphs) resource)
|
||||
:- (give [/all /keys ~] [%add-graph resource graph])
|
||||
state(graphs (~(put by graphs) resource graph))
|
||||
::
|
||||
++ remove-graph
|
||||
|= =resource:store
|
||||
^- (quip card _state)
|
||||
?> (~(has by graphs) resource)
|
||||
:- (give [/all /keys ~] [%remove-graph resource])
|
||||
state(graphs (~(del by graphs) resource))
|
||||
::
|
||||
++ add-nodes
|
||||
|= nodes=(map resource:store (map index:store node:store))
|
||||
^- (quip card _state)
|
||||
=/ resource-list ~(tap by nodes)
|
||||
|^
|
||||
?~ resource-list
|
||||
:_ state
|
||||
(give [/all]~ [%add-nodes nodes])
|
||||
=* resource -.i.resource-list
|
||||
=* indexed-nodes +.i.resource-list
|
||||
=/ graph=(unit graph) (~(get by graphs) resource)
|
||||
?~ graph
|
||||
~| "graph {<resource>} does not exist to add a node to!"
|
||||
$(resource-list t.resource-list)
|
||||
%_ $
|
||||
resource-list t.resource-list
|
||||
graphs
|
||||
%+ ~(put by graphs)
|
||||
resource
|
||||
(add-node-list resource u.graph ~(tap by indexed-nodes))
|
||||
==
|
||||
::
|
||||
++ add-node-list
|
||||
|= $: =resource:store
|
||||
=graph:store
|
||||
node-list=(list [index:store node:store])
|
||||
==
|
||||
^- graph:store
|
||||
|-
|
||||
?~ node-list graph
|
||||
=* index -.i.node-list
|
||||
=* node +.i.node-list
|
||||
%_ $
|
||||
node-list t.node-list
|
||||
graph (add-node-at-index graph index node)
|
||||
==
|
||||
::
|
||||
++ add-node-at-index
|
||||
|= [=graph:store =index:store =node:store]
|
||||
^- graph:store
|
||||
?~ index graph
|
||||
=* atom i.index
|
||||
:: last index in list
|
||||
?~ t.index (put:orm graph atom node)
|
||||
:: multiple indices left in list
|
||||
:: TODO: replace normal map function with ordered-map version
|
||||
:: of get. look at find-ducts in behn
|
||||
=/ parent=(unit node) (~(get by graph) atom)
|
||||
?~ parent
|
||||
~| "{<atom>} does not exist to add a node to!"
|
||||
graph
|
||||
?+ -.children.u.parent
|
||||
:: replace empty graph with graph containing one child
|
||||
%^ put:orm
|
||||
graph
|
||||
atom
|
||||
%_ u.parent
|
||||
children
|
||||
[%graph $(graph (gas:orm ~ ~), index t.index) now.bowl]
|
||||
==
|
||||
::
|
||||
%graph
|
||||
:: recurse into children
|
||||
%^ put:orm
|
||||
graph
|
||||
atom
|
||||
%_ u.parent
|
||||
p.children $(graph p.children.u.parent, index t.index)
|
||||
q.children now.bowl
|
||||
==
|
||||
==
|
||||
::
|
||||
++ orm ((ordered-map atom:store node:store) lth)
|
||||
--
|
||||
::
|
||||
++ remove-nodes
|
||||
|= uids=(set uid:store)
|
||||
^- (quip card _state)
|
||||
[~ state]
|
||||
::
|
||||
++ add-signatures
|
||||
|= [=uid:store =signatures:store]
|
||||
^- (quip card _state)
|
||||
[~ state]
|
||||
::
|
||||
++ remove-signatures
|
||||
|= [=uid:store =signatures:store]
|
||||
^- (quip card _state)
|
||||
[~ state]
|
||||
::
|
||||
++ add-tag
|
||||
|= [=term =resources:store]
|
||||
^- (quip card _state)
|
||||
[~ state]
|
||||
::
|
||||
++ remove-tag
|
||||
|= [=term =resources:store]
|
||||
^- (quip card _state)
|
||||
[~ state]
|
||||
::
|
||||
::
|
||||
++ give
|
||||
|= [paths=(list path) =update:store]
|
||||
^- (list card)
|
||||
[%give %fact paths [%graph-update !>(update)]]~
|
||||
--
|
||||
--
|
||||
::
|
||||
++ on-watch
|
||||
|
33
pkg/arvo/lib/graph-store.hoon
Normal file
33
pkg/arvo/lib/graph-store.hoon
Normal file
@ -0,0 +1,33 @@
|
||||
/- sur=graph-store, pos=post, res=resource
|
||||
^?
|
||||
=< [sur .]
|
||||
=< [pos .]
|
||||
=< [res .]
|
||||
=, sur
|
||||
=, pos
|
||||
=, res
|
||||
|%
|
||||
++ enjs
|
||||
=, enjs:format
|
||||
|%
|
||||
++ update
|
||||
|= upd=^update
|
||||
^- json
|
||||
|^ (frond %graph-update (pairs ~[(encode upd)]))
|
||||
::
|
||||
++ encode
|
||||
|= upd=^update
|
||||
^- [cord json]
|
||||
[*cord *json]
|
||||
--
|
||||
--
|
||||
::
|
||||
++ dejs
|
||||
=, dejs:format
|
||||
|%
|
||||
++ action
|
||||
|= =json
|
||||
^- ^action
|
||||
!!
|
||||
--
|
||||
--
|
@ -14,7 +14,7 @@
|
||||
tag-queries=(map term resources)
|
||||
==
|
||||
::
|
||||
+$ graph ((mop atom node) lte)
|
||||
+$ graph ((mop atom node) lth)
|
||||
+$ internal-graph
|
||||
$~ [%not-loaded ~]
|
||||
$% ::
|
||||
@ -29,7 +29,7 @@
|
||||
$% [%add-graph =resource =graph]
|
||||
[%remove-graph =resource]
|
||||
::
|
||||
[%add-nodes nodes=(map uid node)]
|
||||
[%add-nodes nodes=(map resource (map index node))]
|
||||
[%remove-nodes uids=(set uid)]
|
||||
::
|
||||
[%add-signatures =uid =signatures]
|
||||
|
@ -4,7 +4,11 @@
|
||||
+$ index (list atom)
|
||||
+$ uid [=resource =index]
|
||||
::
|
||||
+$ hash @ux
|
||||
+$ hash
|
||||
$% [%sha256 p=@ux]
|
||||
[%murmur3 p=@ux]
|
||||
==
|
||||
::
|
||||
+$ signature @ux
|
||||
+$ signatures (set signature)
|
||||
+$ post
|
||||
|
@ -4,7 +4,8 @@
|
||||
::
|
||||
+$ entity
|
||||
$@ ship
|
||||
$% [%ships ships=(set ship)]
|
||||
$% [%empty ~]
|
||||
:: [%ships ships=(set ship)]
|
||||
:: [%ring ...]
|
||||
==
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user