From 17430d93146d162b99fec4954f843e4b9adce03f Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 16 Jun 2021 16:31:12 -0500 Subject: [PATCH 1/5] graph-store: first stab at reworking the scry format --- pkg/arvo/app/graph-store.hoon | 431 +++++----------------------------- 1 file changed, 57 insertions(+), 374 deletions(-) diff --git a/pkg/arvo/app/graph-store.hoon b/pkg/arvo/app/graph-store.hoon index 321e6302f0..6a7b3495aa 100644 --- a/pkg/arvo/app/graph-store.hoon +++ b/pkg/arvo/app/graph-store.hoon @@ -180,10 +180,7 @@ == :: ++ add-nodes - |= $: =time - =resource:store - nodes=(map index:store node:store) - == + |= [=time =resource:store nodes=(map index:store node:store)] ^- (quip card _state) |^ =/ [=graph:store mark=(unit mark:store)] @@ -618,392 +615,78 @@ ~/ %graph-store-peek |= =path ^- (unit (unit cage)) - |^ - ?> (team:title our.bowl src.bowl) - ?+ path (on-peek:def path) - [%x %graph-mark @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ result=(unit marked-graph:store) - (~(get by graphs) [ship term]) - ?~ result [~ ~] - ``noun+!>(`(unit mark)`q.u.result) - :: + ?+ path (on-peek:def path) [%x %keys ~] :- ~ :- ~ :- %graph-update-2 !>(`update:store`[now.bowl [%keys ~(key by graphs)]]) :: - [%x %tags ~] + [%x %tag-queries *] :- ~ :- ~ :- %graph-update-2 - !>(`update:store`[now.bowl [%tags ~(key by tag-queries)]]) + !> ^- update:store + :- now.bowl + ?+ t.t.path (on-peek:def t.t.path) + ~ [%tag-queries tag-queries] + [%tags ~] [%tags ~(key by tag-queries)] + == :: - [%x %tag-queries ~] - :- ~ :- ~ :- %graph-update-2 - !>(`update:store`[now.bowl [%tag-queries tag-queries]]) - :: - [%x %graph @ @ ~] + [%x %update-logs @ @ *] =/ =ship (slav %p i.t.t.path) =/ =term i.t.t.t.path - =/ result=(unit marked-graph:store) - (~(get by graphs) [ship term]) - ?~ result [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - [%add-graph [ship term] `graph:store`p.u.result q.u.result %.y] - :: - :: note: near-duplicate of /x/graph - :: - [%x %archive @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ result=(unit marked-graph:store) - (~(get by archive) [ship term]) - ?~ result - ~& no-archived-graph+[ship term] - [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - [%add-graph [ship term] `graph:store`p.u.result q.u.result %.y] - :: - [%x %export ~] - ``noun+!>(state) - :: - [%x %graph-subset @ @ @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ start=(unit atom) (rush i.t.t.t.t.path dem:ag) - =/ end=(unit atom) (rush i.t.t.t.t.t.path dem:ag) - =/ graph=(unit marked-graph:store) - (~(get by graphs) [ship term]) - ?~ graph [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - :+ %add-nodes - [ship term] - %- ~(gas by *(map index:store node:store)) - %+ turn (tap:orm `graph:store`(lot:orm p.u.graph start end)) - |= [=atom =node:store] - ^- [index:store node:store] - [~[atom] node] - :: - [%x %node-exists @ @ @ *] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ =index:store - (turn t.t.t.t.path (cury slav %ud)) - =/ node=(unit node:store) - (get-node ship term index) - ``noun+!>(`?`?=(^ node)) - :: - [%x %node @ @ @ *] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ =index:store - (turn t.t.t.t.path (cury slav %ud)) - =/ node=(unit node:store) (get-node ship term index) - ?~ node [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - :+ %add-nodes - [ship term] - (~(gas by *(map index:store node:store)) [index u.node] ~) - :: - [%x %node-siblings ?(%older %younger) @ @ @ *] - |^ - =/ older ?=(%older i.t.t.path) - =/ =ship (slav %p i.t.t.t.path) - =/ =term i.t.t.t.t.path - =/ count (slav %ud i.t.t.t.t.t.path) - =/ =index:store - (turn t.t.t.t.t.t.path (cury slav %ud)) - =/ parent=index:store - (scag (dec (lent index)) index) - =/ graph - (get-node-children ship term parent) - ?~ graph [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - :+ %add-nodes - [ship term] - %- ~(gas by *(map index:store node:store)) - %+ turn - ?: older - (tab:orm u.graph `(rear index) count) - :: TODO time complexity not desirable for %younger case - :: - %+ slag (safe-sub (lent -) count) - %- tap:orm - %+ lot:orm u.graph - [~ `(snag (dec (lent index)) index)] - |= [=atom =node:store] - ^- [index:store node:store] - [(snoc parent atom) node] + =/ update-log + (~(get by update-logs) [ship term]) + ?~ update-log [~ ~] + :- ~ :- ~ :- %noun + !> + ?+ t.t.t.t.path (on-peek:def t.t.t.t.path) + ~ `update-log:store`u.update-log :: - ++ safe-sub - |= [a=@ b=@] - ^- @ - ?: (gte b a) - 0 - (sub a b) - -- + [%latest ~] + ^- (unit time) + %+ biff update-log + |= =update-log:store + =/ result=(unit [=time =update:store]) + (pry:orm-log:store update-log) + (bind result head) + :: + [%subset @ @ ~] + ^- update-log:store + =* start i.t.t.t.t.t.path + =* end i.t.t.t.t.t.t.path + %^ lot:orm-log + u.update-log + (slaw %da start) + (slaw %da end) + == :: - [%x %shallow-children @ @ *] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ =index:store - (turn t.t.t.t.path (cury slav %ud)) - =/ children - (get-node-children ship term index) - ?~ children [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :+ now.bowl %add-nodes - :- [ship term] - %- ~(gas by *(map index:store node:store)) - %+ turn (tap:orm u.children) - |= [=atom =node:store] - ^- [index:store node:store] - :- (snoc index atom) - node(children [%empty ~]) - :: - [%x ?(%newest %oldest) @ @ @ *] - =/ newest ?=(%newest i.t.path) - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ count=@ud - (slav %ud i.t.t.t.t.path) - =/ =index:store - (turn t.t.t.t.t.path (cury slav %ud)) - =/ children - (get-node-children ship term index) - ?~ children [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - :+ %add-nodes - [ship term] - %- ~(gas by *(map index:store node:store)) - %+ turn - %+ scag count - ?: newest - (tap:orm u.children) - (bap:orm u.children) - |= [=atom =node:store] - ^- [index:store node:store] - [(snoc index atom) node] - :: - [%x %node-children-subset @ @ @ @ @ *] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ start=(unit atom) (rush i.t.t.t.t.path dem:ag) - =/ end=(unit atom) (rush i.t.t.t.t.t.path dem:ag) - =/ =index:store - (turn t.t.t.t.t.t.path |=(=cord (slav %ud cord))) - =/ node=(unit node:store) (get-node ship term index) - ?~ node [~ ~] - ?- -.children.u.node - %empty [~ ~] - %graph + [%x %graph @ @ *] + =/ =ship (slav %p i.t.t.path) + =/ =term i.t.t.t.path + =/ marked-graph=(unit marked-graph:store) + (~(get by graphs) [ship term]) + ?~ marked-graph [~ ~] + =* graph p.u.marked-graph + =* mark q.u.marked-graph + ?+ t.t.t.t.path (on-peek:def t.t.t.t.path) + ~ + :- ~ :- ~ :- %graph-update-2 + !>(`update:store`[now.bowl [%add-graph [ship term] graph mark %.y]]) + :: + [%mark ~] + ``noun+!>(`(unit ^mark)`mark) + :: + [%subset @ @ ~] + =/ start=(unit atom) (rush i.t.t.t.t.t.path dem:ag) + =/ end=(unit atom) (rush i.t.t.t.t.t.t.path dem:ag) :- ~ :- ~ :- %graph-update-2 !> ^- update:store - :- now.bowl - :+ %add-nodes - [ship term] + :^ now.bowl %add-nodes [ship term] %- ~(gas by *(map index:store node:store)) - %+ turn (tap:orm `graph:store`(lot:orm p.children.u.node end start)) - |= [=atom =node:store] - ^- [index:store node:store] - [(snoc index atom) node] + %+ turn (tap:orm (lot:orm graph start end)) + |=([=atom =node:store] [atom^~ node]) == - :: - [%x %deep-nodes-older-than @ @ @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ count=(unit atom) (rush i.t.t.t.t.path dem:ag) - =/ start=(unit atom) (rush i.t.t.t.t.t.path dem:ag) - ?: ?=(~ count) - [~ ~] - =/ result=(unit marked-graph:store) - (~(get by graphs) [ship term]) - ?~ result - [~ ~] - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - :- now.bowl - :+ %add-nodes - [ship term] - =* a u.count - =/ b=(list (pair atom node:store)) - (tab:orm p.u.result start u.count) - =| c=index:store - =| d=(map index:store node:store) - =| e=@ud - =- d - |- ^- [e=@ud d=(map index:store node:store)] - ?: ?|(?=(~ b) =(e a)) - [e d] - =* atom p.i.b - =* node q.i.b - =. c (snoc c atom) - ?- -.children.node - %empty - $(b t.b, e +(e), d (~(put by d) c node), c (snip c)) - :: - %graph - =/ f $(b (tab:orm p.children.node ~ (sub a e))) - ?: =(e.f a) f - %_ $ - b t.b - e +(e.f) - d (~(put by d.f) c node(children [%empty ~])) - c (snip c) - == - == - :: - [%x %firstborn @ @ @ *] - |^ - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ =index:store - (turn t.t.t.t.path (cury slav %ud)) - ?> ?=(^ index) - =/ result=(unit marked-graph:store) - (~(get by graphs) [ship term]) - ?~ result - [~ ~] - %- (bond |.(`(unit (unit cage))`[~ ~])) - %+ biff - (collect-parents p.u.result index ship term) - (corl some collect-firstborn) - :: - ++ collect-parents - |= [=graph:store =index:store =ship =term] - ^- %- unit - [node:store index:store (map index:store node:store) ^ship ^term] - =| =(map index:store node:store) - =| =node:store - =| ind=index:store - =/ len (lent index) - |- - ?: (gte (lent ind) len) - `[node ind map ship term] - ?> ?=(^ index) - =* atom i.index - ?. (has:orm graph atom) - ~ - =: node (got:orm graph atom) - ind (snoc ind atom) - == - ?: ?=(%empty -.children.node) - ?. (gte (lent ind) len) - ~ - :- ~ - :* node ind - (~(put by map) ind node) - ship term - == - %_ $ - index t.index - graph p.children.node - map (~(put by map) ind node(children empty+~)) - == - :: - ++ collect-firstborn - |= [=node:store =index:store mp=(map index:store node:store) =ship =term] - ^- (unit (unit cage)) - ?: ?=(%empty -.children.node) - :- ~ :- ~ :- %graph-update-2 - !> ^- update:store - [now.bowl [%add-nodes [ship term] mp]] - =/ item=[k=atom v=node:store] - (need (ram:orm p.children.node)) - =. index (snoc index k.item) - $(mp (~(put by mp) index v.item(children empty+~)), node v.item) - -- - :: - [%x %update-log-subset @ @ @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ start=(unit time) (slaw %da i.t.t.t.t.path) - =/ end=(unit time) (slaw %da i.t.t.t.t.t.path) - =/ update-log=(unit update-log:store) (~(get by update-logs) [ship term]) - ?~ update-log [~ ~] - :: orm-log is ordered backwards, so swap start and end - ``noun+!>(`update-log:store`(lot:orm-log u.update-log end start)) - :: - [%x %update-log @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ update-log=(unit update-log:store) (~(get by update-logs) [ship term]) - ?~ update-log [~ ~] - ``noun+!>(`update-log:store`u.update-log) - :: - [%x %peek-update-log @ @ ~] - =/ =ship (slav %p i.t.t.path) - =/ =term i.t.t.t.path - =/ m-update-log=(unit update-log:store) - (~(get by update-logs) [ship term]) - :- ~ :- ~ :- %noun - !> ^- (unit time) - %+ biff m-update-log - |= =update-log:store - =/ result=(unit [=time =update:store]) - (pry:orm-log:store update-log) - (bind result head) - == - :: - ++ get-node-children - |= [=ship =term =index:store] - ^- (unit graph:store) - ?: ?=(~ index) - =/ graph - (~(get by graphs) [ship term]) - ?~ graph ~ - `p.u.graph - =/ node - (get-node ship term index) - ?~ node ~ - ?: ?=(%empty -.children.u.node) - ~ - `p.children.u.node - :: - ++ get-node - |= [=ship =term =index:store] - ^- (unit node:store) - =/ parent-graph=(unit marked-graph:store) - (~(get by graphs) [ship term]) - ?~ parent-graph ~ - =/ node=(unit node:store) ~ - =/ =graph:store p.u.parent-graph - |- - ?~ index - node - ?~ t.index - (get:orm graph i.index) - =. node (get:orm graph i.index) - ?~ node ~ - ?- -.children.u.node - %empty ~ - %graph $(graph p.children.u.node, index t.index) - == - -- -:: -++ on-arvo - |= [=wire =sign-arvo] - ^- (quip card _this) - ?+ wire (on-arvo:def wire sign-arvo) - :: - :: old wire, do nothing - [%graph *] [~ this] - [%validator @ ~] [~ this] - [%try-rejoin @ *] [~ this] == :: +++ on-arvo on-arvo:def ++ on-agent on-agent:def ++ on-leave on-leave:def ++ on-fail on-fail:def From 5a9b76f349b842fa639fbf16a62db14f980c682c Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 17 Jun 2021 12:17:36 -0500 Subject: [PATCH 2/5] graph-store: reworked most of %graph and %node scries --- pkg/arvo/app/graph-store.hoon | 84 +++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/pkg/arvo/app/graph-store.hoon b/pkg/arvo/app/graph-store.hoon index 6a7b3495aa..338bd754e9 100644 --- a/pkg/arvo/app/graph-store.hoon +++ b/pkg/arvo/app/graph-store.hoon @@ -616,6 +616,8 @@ |= =path ^- (unit (unit cage)) ?+ path (on-peek:def path) + [%x %export ~] ``noun+!>(state) + :: [%x %keys ~] :- ~ :- ~ :- %graph-update-2 !>(`update:store`[now.bowl [%keys ~(key by graphs)]]) @@ -624,10 +626,21 @@ :- ~ :- ~ :- %graph-update-2 !> ^- update:store :- now.bowl - ?+ t.t.path (on-peek:def t.t.path) + ?+ t.t.path (on-peek:def path) ~ [%tag-queries tag-queries] [%tags ~] [%tags ~(key by tag-queries)] == + :: + [%x %archive @ @ ~] + =/ =ship (slav %p i.t.t.path) + =/ =term i.t.t.t.path + =/ marked-graph=(unit marked-graph:store) + (~(get by graphs) [ship term]) + ?~ marked-graph [~ ~] + =* graph p.u.marked-graph + =* mark q.u.marked-graph + :- ~ :- ~ :- %graph-update-2 + !>(`update:store`[now.bowl [%add-graph [ship term] graph mark %.y]]) :: [%x %update-logs @ @ *] =/ =ship (slav %p i.t.t.path) @@ -637,7 +650,7 @@ ?~ update-log [~ ~] :- ~ :- ~ :- %noun !> - ?+ t.t.t.t.path (on-peek:def t.t.t.t.path) + ?+ t.t.t.t.path (on-peek:def path) ~ `update-log:store`u.update-log :: [%latest ~] @@ -666,7 +679,7 @@ ?~ marked-graph [~ ~] =* graph p.u.marked-graph =* mark q.u.marked-graph - ?+ t.t.t.t.path (on-peek:def t.t.t.t.path) + ?+ t.t.t.t.path (on-peek:def path) ~ :- ~ :- ~ :- %graph-update-2 !>(`update:store`[now.bowl [%add-graph [ship term] graph mark %.y]]) @@ -683,6 +696,71 @@ %- ~(gas by *(map index:store node:store)) %+ turn (tap:orm (lot:orm graph start end)) |=([=atom =node:store] [atom^~ node]) + :: + [%node *] + |^ + =* pax t.t.t.t.t.path + ?+ pax (on-peek:def path) + [%index ?(%lone %kith) ^] + =/ =index:store + (turn t.t.pax (cury slav %ud)) + =/ node (get-node graph index) + ?~ node [~ ~] + :- ~ :- ~ :- %graph-update-2 + !> ^- update:store + :^ now.bowl %add-nodes [ship term] + %- ~(gas by *(map index:store node:store)) + :_ ~ + :- index + ?: ?=(%kith i.t.pax) u.node + u.node(children [%empty ~]) + :: + [%exists ^] + =/ =index:store + (turn t.pax (cury slav %ud)) + =/ node (get-node graph index) + ``noun+!>(`?`?=(^ node)) + :: + [%children ?(%lone %kith) @ @ ^] + =/ =index:store + (turn t.t.t.t.pax (cury slav %ud)) + =/ start=(unit atom) (rush i.t.t.path dem:ag) + =/ end=(unit atom) (rush i.t.t.t.path dem:ag) + =/ node (get-node graph index) + ?~ node [~ ~] + :- ~ :- ~ :- %graph-update-2 + !> ^- update:store + :^ now.bowl %add-nodes [ship term] + %- ~(gas by *(map index:store node:store)) + ?: ?=(%empty -.children.u.node) + ~ + =* children p.children.u.node + %+ turn + %- tap:orm + ?: ?=(%all i.t.t.pax) children + (lot:orm children end start) + |= [=atom =node:store] + ^- [index:store node:store] + :- (snoc index atom) + ?: ?=(%kith i.t.pax) node + node(children [%empty ~]) + :: + ::[%siblings ?(%older %younger %newest %oldest) @ *] + == + :: + ++ get-node + |= [=graph:store =index:store] + ^- (unit node:store) + =| node=(unit node:store) + |- + ?~ index node + ?~ t.index (get:orm graph i.index) + =. node (get:orm graph i.index) + ?~ node ~ + ?: ?=(%empty -.children.u.node) + ~ + $(graph p.children.u.node, index t.index) + -- == == :: From f944fd1d8fed5a3e3aa8581d08a6f8f63599ef3b Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 17 Jun 2021 16:53:42 -0500 Subject: [PATCH 3/5] graph-store: finish specifying new scry api --- pkg/arvo/app/graph-store.hoon | 156 +++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 20 deletions(-) diff --git a/pkg/arvo/app/graph-store.hoon b/pkg/arvo/app/graph-store.hoon index 338bd754e9..0e22088d89 100644 --- a/pkg/arvo/app/graph-store.hoon +++ b/pkg/arvo/app/graph-store.hoon @@ -657,9 +657,7 @@ ^- (unit time) %+ biff update-log |= =update-log:store - =/ result=(unit [=time =update:store]) - (pry:orm-log:store update-log) - (bind result head) + (bind (pry:orm-log:store update-log) head) :: [%subset @ @ ~] ^- update-log:store @@ -687,20 +685,31 @@ [%mark ~] ``noun+!>(`(unit ^mark)`mark) :: - [%subset @ @ ~] - =/ start=(unit atom) (rush i.t.t.t.t.t.path dem:ag) - =/ end=(unit atom) (rush i.t.t.t.t.t.t.path dem:ag) + [%subset ?(%lone %kith) @ @ ~] + =/ start=(unit atom) (rush i.t.t.t.t.t.t.path dem:ag) + =/ end=(unit atom) (rush i.t.t.t.t.t.t.t.path dem:ag) :- ~ :- ~ :- %graph-update-2 !> ^- update:store :^ now.bowl %add-nodes [ship term] %- ~(gas by *(map index:store node:store)) %+ turn (tap:orm (lot:orm graph start end)) - |=([=atom =node:store] [atom^~ node]) + |= [=atom =node:store] + ^- [index:store node:store] + :- atom^~ + ?: ?=(%kith i.t.t.t.t.t.path) + node + node(children [%empty ~]) :: [%node *] |^ =* pax t.t.t.t.t.path ?+ pax (on-peek:def path) + [%exists ^] + =/ =index:store + (turn t.pax (cury slav %ud)) + =/ node (get-node graph index) + ``noun+!>(`?`?=(^ node)) + :: [%index ?(%lone %kith) ^] =/ =index:store (turn t.t.pax (cury slav %ud)) @@ -710,16 +719,9 @@ !> ^- update:store :^ now.bowl %add-nodes [ship term] %- ~(gas by *(map index:store node:store)) - :_ ~ - :- index + :_ ~ :- index ?: ?=(%kith i.t.pax) u.node u.node(children [%empty ~]) - :: - [%exists ^] - =/ =index:store - (turn t.pax (cury slav %ud)) - =/ node (get-node graph index) - ``noun+!>(`?`?=(^ node)) :: [%children ?(%lone %kith) @ @ ^] =/ =index:store @@ -735,17 +737,90 @@ ?: ?=(%empty -.children.u.node) ~ =* children p.children.u.node - %+ turn - %- tap:orm - ?: ?=(%all i.t.t.pax) children - (lot:orm children end start) + %+ turn (tap:orm (lot:orm children end start)) |= [=atom =node:store] ^- [index:store node:store] :- (snoc index atom) ?: ?=(%kith i.t.pax) node node(children [%empty ~]) :: - ::[%siblings ?(%older %younger %newest %oldest) @ *] + [%siblings ?(%older %newer %oldest %newest) ?(%lone %kith) @ ^] + =/ =index:store + (turn t.t.t.t.t.pax (cury slav %ud)) + =/ parent=index:store (snip index) + =/ count (slav %ud i.t.t.t.pax) + =/ node (get-node graph parent) + ?~ node [~ ~] + :- ~ :- ~ :- %graph-update-2 + !> ^- update:store + :^ now.bowl %add-nodes [ship term] + %- ~(gas by *(map index:store node:store)) + ?: ?=(%empty -.children.u.node) + ~ + =* children p.children.u.node + %+ turn + ?- i.t.pax + %oldest (scag count (bap:orm children)) + %older (tab:orm children `(rear index) count) + %newest (scag count (tap:orm children)) + :: + %newer + %+ slag (safe-sub (lent -) count) + (tap:orm (lot:orm children ~ `(rear index))) + == + |= [=atom =node:store] + ^- [index:store node:store] + :- (snoc parent atom) + ?: ?=(%kith i.t.t.pax) node + node(children [%empty ~]) + :: + [%firstborn ^] + |^ + =/ =index:store + (turn t.pax (cury slav %ud)) + %- (bond |.(`(unit (unit cage))`[~ ~])) + %+ biff + (collect-parents graph index) + (corl some collect-firstborn) + :: + ++ collect-parents + |= [=graph:store =index:store] + ^- (unit [node:store index:store (map index:store node:store)]) + =| =(map index:store node:store) + =| =node:store + =| ind=index:store + =/ len (lent index) + |- + ?: (gte (lent ind) len) + `[node ind map] + ?> ?=(^ index) + =* atom i.index + ?. (has:orm graph atom) + ~ + =: node (got:orm graph atom) + ind (snoc ind atom) + == + ?: ?=(%empty -.children.node) + ?. (gte (lent ind) len) + ~ + `[node ind (~(put by map) ind node)] + %_ $ + index t.index + graph p.children.node + map (~(put by map) ind node(children empty+~)) + == + :: + ++ collect-firstborn + |= [=node:store =index:store =(map index:store node:store)] + ^- (unit (unit cage)) + ?: ?=(%empty -.children.node) + :- ~ :- ~ :- %graph-update-2 + !>(`update:store`[now.bowl [%add-nodes [ship term] map]]) + =/ item=[k=atom v=node:store] + (need (ram:orm p.children.node)) + =. index (snoc index k.item) + $(map (~(put by map) index v.item(children empty+~)), node v.item) + -- == :: ++ get-node @@ -760,7 +835,48 @@ ?: ?=(%empty -.children.u.node) ~ $(graph p.children.u.node, index t.index) + :: + ++ safe-sub + |= [a=@ b=@] + ^- @ + ?:((gte b a) 0 (sub a b)) -- + :: + [%depth-first @ @ ~] + =/ count=(unit atom) (rush i.t.t.t.t.path dem:ag) + =/ start=(unit atom) (rush i.t.t.t.t.t.path dem:ag) + ?: ?=(~ count) + [~ ~] + :- ~ :- ~ :- %graph-update-2 + !> ^- update:store + :^ now.bowl %add-nodes [ship term] + =* a u.count + =/ b=(list (pair atom node:store)) + (tab:orm graph start u.count) + =| c=index:store + =| d=(map index:store node:store) + =| e=@ud + =- d + |- ^- [e=@ud d=(map index:store node:store)] + ?: ?|(?=(~ b) =(e a)) + [e d] + =* atom p.i.b + =* node q.i.b + =. c (snoc c atom) + ?- -.children.node + %empty + $(b t.b, e +(e), d (~(put by d) c node), c (snip c)) + :: + %graph + =/ f $(b (tab:orm p.children.node ~ (sub a e))) + ?: =(e.f a) f + %_ $ + b t.b + e +(e.f) + d (~(put by d.f) c node(children [%empty ~])) + c (snip c) + == + == == == :: From f3c7fbfa3a0697ec905773e2db0a6dd335014123 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 7 Jul 2021 14:17:07 -0500 Subject: [PATCH 4/5] graph-store: generalize scry api in siblings and children to allow fetching outer graph, fix lib/graph and hark-graph-hook --- pkg/arvo/app/graph-store.hoon | 49 +++++++++++++++++++++---------- pkg/arvo/app/hark-graph-hook.hoon | 2 +- pkg/arvo/lib/graph.hoon | 20 ++++--------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/pkg/arvo/app/graph-store.hoon b/pkg/arvo/app/graph-store.hoon index 0e22088d89..974c8bddcb 100644 --- a/pkg/arvo/app/graph-store.hoon +++ b/pkg/arvo/app/graph-store.hoon @@ -642,7 +642,7 @@ :- ~ :- ~ :- %graph-update-2 !>(`update:store`[now.bowl [%add-graph [ship term] graph mark %.y]]) :: - [%x %update-logs @ @ *] + [%x %update-log @ @ *] =/ =ship (slav %p i.t.t.path) =/ =term i.t.t.t.path =/ update-log @@ -723,20 +723,26 @@ ?: ?=(%kith i.t.pax) u.node u.node(children [%empty ~]) :: - [%children ?(%lone %kith) @ @ ^] - =/ =index:store - (turn t.t.t.t.pax (cury slav %ud)) + [%children ?(%lone %kith) @ @ *] =/ start=(unit atom) (rush i.t.t.path dem:ag) =/ end=(unit atom) (rush i.t.t.t.path dem:ag) + =/ =index:store + (turn t.t.t.t.pax (cury slav %ud)) =/ node (get-node graph index) - ?~ node [~ ~] + ?: ?& ?=(~ node) + ?=(^ index) + == + [~ ~] + =/ children=graph:store + ?~ node + graph + ?: ?=(%empty -.children.u.node) + ~ + p.children.u.node :- ~ :- ~ :- %graph-update-2 !> ^- update:store :^ now.bowl %add-nodes [ship term] %- ~(gas by *(map index:store node:store)) - ?: ?=(%empty -.children.u.node) - ~ - =* children p.children.u.node %+ turn (tap:orm (lot:orm children end start)) |= [=atom =node:store] ^- [index:store node:store] @@ -744,20 +750,31 @@ ?: ?=(%kith i.t.pax) node node(children [%empty ~]) :: - [%siblings ?(%older %newer %oldest %newest) ?(%lone %kith) @ ^] - =/ =index:store - (turn t.t.t.t.t.pax (cury slav %ud)) - =/ parent=index:store (snip index) + [%siblings ?(%older %newer %oldest %newest) ?(%lone %kith) @ *] =/ count (slav %ud i.t.t.t.pax) + =/ =index:store + (turn t.t.t.t.pax (cury slav %ud)) + =/ parent=index:store (snip index) =/ node (get-node graph parent) - ?~ node [~ ~] + ?: ?| ?& ?=(~ node) + ?=(^ parent) + == + :: + ?& ?=(^ parent) + ?| ?=(%oldest i.t.pax) + ?=(%newest i.t.pax) + == == == + [~ ~] + =/ children=graph:store + ?~ node + graph + ?: ?=(%empty -.children.u.node) + ~ + p.children.u.node :- ~ :- ~ :- %graph-update-2 !> ^- update:store :^ now.bowl %add-nodes [ship term] %- ~(gas by *(map index:store node:store)) - ?: ?=(%empty -.children.u.node) - ~ - =* children p.children.u.node %+ turn ?- i.t.pax %oldest (scag count (bap:orm children)) diff --git a/pkg/arvo/app/hark-graph-hook.hoon b/pkg/arvo/app/hark-graph-hook.hoon index 7285f7ce8b..a6a2fedb1b 100644 --- a/pkg/arvo/app/hark-graph-hook.hoon +++ b/pkg/arvo/app/hark-graph-hook.hoon @@ -285,7 +285,7 @@ ^- $-(indexed-post:graph-store (unit notif-kind:hook)) =+ %^ scry [our now]:bowl ,mark=(unit mark) - /gx/graph-store/graph-mark/(scot %p entity.rid)/[name.rid]/noun + /gx/graph-store/graph/(scot %p entity.rid)/[name.rid]/mark/noun ?~ mark |=(=indexed-post:graph-store ~) (scry-notif-conversion [our now]:bowl q.byk.bowl u.mark) diff --git a/pkg/arvo/lib/graph.hoon b/pkg/arvo/lib/graph.hoon index e578eee7b1..4a76cdd1aa 100644 --- a/pkg/arvo/lib/graph.hoon +++ b/pkg/arvo/lib/graph.hoon @@ -96,22 +96,12 @@ ?> ?=(%add-graph -.q.update) graph.q.update :: -++ gut-younger-node-siblings - |= [res=resource =index:store] - ^- (map index:store node:store) - =+ %+ scry-for ,=update:store - %+ weld - /node-siblings/younger/(scot %p entity.res)/[name.res]/all - (turn index (cury scot %ud)) - ?> ?=(%add-nodes -.q.update) - nodes.q.update -:: ++ got-node |= [res=resource =index:store] ^- node:store =+ %+ scry-for ,=update:store %+ weld - /node/(scot %p entity.res)/[name.res] + /graph/(scot %p entity.res)/[name.res]/node/index/kith (turn index (cury scot %ud)) ?> ?=(%add-nodes -.q.update) ?> ?=(^ nodes.q.update) @@ -122,7 +112,7 @@ ^- ? %+ scry-for ,? %+ weld - /node-exists/(scot %p entity.res)/[name.res] + /graph/(scot %p entity.res)/[name.res]/node/exists (turn index (cury scot %ud)) :: ++ get-update-log @@ -134,13 +124,13 @@ ++ peek-update-log |= res=resource ^- (unit time) - (scry-for (unit time) /peek-update-log/(scot %p entity.res)/[name.res]) + (scry-for (unit time) /update-log/(scot %p entity.res)/[name.res]/latest) :: ++ get-update-log-subset |= [res=resource start=@da] ^- update-log:store %+ scry-for update-log:store - /update-log-subset/(scot %p entity.res)/[name.res]/(scot %da start)/'~' + /update-log/(scot %p entity.res)/[name.res]/subset/(scot %da start)/'~' :: ++ get-keys ^- resources @@ -183,5 +173,5 @@ :: ++ get-mark |= res=resource - (scry-for ,(unit mark) /graph-mark/(scot %p entity.res)/[name.res]) + (scry-for ,(unit mark) /graph/(scot %p entity.res)/[name.res]/mark) -- From 177cae936d7fe4730bfdbd07eb79c45e90146649 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 8 Jul 2021 18:26:25 -0500 Subject: [PATCH 5/5] graph api npm: updated endpoints --- pkg/npm/api/graph/lib.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/npm/api/graph/lib.ts b/pkg/npm/api/graph/lib.ts index dd4dbcca13..4a097d9f50 100644 --- a/pkg/npm/api/graph/lib.ts +++ b/pkg/npm/api/graph/lib.ts @@ -383,7 +383,8 @@ export const getNewest = ( index = '' ): Scry => ({ app: 'graph-store', - path: `/newest/${ship}/${name}/${count}${encodeIndex(index)}` + path: `/graph/${ship}/${name}/node/siblings` + + `/newest/lone/${count}${encodeIndex(index)}` }); /** @@ -402,7 +403,7 @@ export const getOlderSiblings = ( index: string ): Scry => ({ app: 'graph-store', - path: `/node-siblings/older/${ship}/${name}/${count}${encodeIndex(index)}` + path: `/graph/${ship}/${name}/node/siblings/older/lone/${count}${encodeIndex(index)}` }); /** @@ -421,7 +422,7 @@ export const getYoungerSiblings = ( index: string ): Scry => ({ app: 'graph-store', - path: `/node-siblings/younger/${ship}/${name}/${count}${encodeIndex(index)}` + path: `/graph/${ship}/${name}/node/siblings/newer/lone/${count}${encodeIndex(index)}` }); /** @@ -433,7 +434,7 @@ export const getYoungerSiblings = ( */ export const getShallowChildren = (ship: string, name: string, index = '') => ({ app: 'graph-store', - path: `/shallow-children/${ship}/${name}${encodeIndex(index)}` + path: `/graph/${ship}/${name}/node/children/lone/~/~/${encodeIndex(index)}` }); @@ -454,7 +455,9 @@ export const getDeepOlderThan = ( start?: string ) => ({ app: 'graph-store', - path: `/deep-nodes-older-than/${ship}/${name}/${count}/${start ? decToUd(start) : 'null'}` + path: `/graph/${ship}/${name}/node/siblings` + + `/${start ? 'older' : 'oldest'}` + + `/kith/${count}/${start ? decToUd(start) : '~'}` }); @@ -472,7 +475,7 @@ export const getFirstborn = ( index: string ): Scry => ({ app: 'graph-store', - path: `/firstborn/${ship}/${name}${encodeIndex(index)}` + path: `/graph/${ship}/${name}/node/firstborn${encodeIndex(index)}` }); /** @@ -489,7 +492,7 @@ export const getNode = ( index: string ): Scry => ({ app: 'graph-store', - path: `/node/${ship}/${name}${encodeIndex(index)}` + path: `/graph/${ship}/${name}/node/index/kith${encodeIndex(index)}` }); /**