Skip to content

Commit

Permalink
wip: partially update diary for backlog windowing
Browse files Browse the repository at this point in the history
Here we update /app/diary's update processing logic to match the recent
changes made to the diff type, and account for the
not-yet-fully-implemented backlog windowing system.

As always, uncompiled & untested, be forewarned.
  • Loading branch information
Fang- committed Aug 24, 2023
1 parent 558b3c5 commit d52657f
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 49 deletions.
63 changes: 33 additions & 30 deletions desk/app/diary.hoon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/- d=diary, g=groups, ha=hark
/- meta
/- e=epic
/+ default-agent, verb, dbug
/+ default-agent, verb, dbug, sparse
/+ not=notes
/+ qup=quips
/+ epos-lib=saga
Expand Down Expand Up @@ -251,6 +251,7 @@
::
[%diary ship=@ name=@ rest=*]
=/ =ship (slav %p ship.pole)
?> =(our ship)
di-abet:(di-watch:(di-abed:di-core ship name.pole) rest.pole)
::
[%said host=@ name=@ %note time=@ quip=?(~ [@ ~])]
Expand Down Expand Up @@ -485,6 +486,7 @@
::
=/ =update:d [now.bowl command]
=. log.diary (put:log-on:d log.diary update)
=. di-core (di-give-ui update)
(di-give-updates update)
:: only accept commands for diaries we own
::
Expand Down Expand Up @@ -834,14 +836,16 @@
out
(~(put in out) [ship path])
::
++ di-give-ui
|= =update:d
(give %fact ~[/ui] act:mar:d !>([flag diff.update]))
::
++ di-give-updates
|= =update:d
^+ di-core
=/ paths=(set path)
%- ~(gas in *(set path))
(turn ~(tap in di-subscriptions) tail)
=. paths (~(put in paths) (snoc di-area %ui))
=. cor (give %fact ~[/ui] act:mar:d !>([flag diff.update]))
=/ cag=cage [upd:mar:d !>(update)]
=. cor
(give %fact ~(tap in paths) cag)
Expand Down Expand Up @@ -901,33 +905,32 @@
|= update:d
?> di-from-host
^+ di-core
=. di-core (di-give-updates time diff)
?- -.diff
%sort di-core(sort.diary sort.diff)
%view di-core(view.diary view.diff)
%order di-core(arranged-notes.diary notes.diff)
%create di-core(perm.diary [writers group]:create.diff)
::
%notes
=. notes.diary (reduce:di-notes time [id delta]:diff)
=. cor (give-brief flag di-brief)
=/ cons=(list (list content:ha))
(hark:di-notes our.bowl +.diff)
=. cor
%- emil
%+ turn cons
|= cs=(list content:ha)
(pass-hark (di-spin /note/(rsh 4 (scot %ui id.diff)) cs ~))
di-core
=. di-core (di-give-ui time diff)
=^ miss global.diary
(apply-diffs:diary global.diary diff)
=. diffs.future.local.diary
%+ roll miss
|= [[=id:notes:d =diff:notes:d] =_diffs.future.local.diary]
:: if the item affected by the diff is not in the window we care about,
:: then ignore it. otherwise, put it in the pending diffs set.
::
?. (~(has as:sparse window.future.local.diary) id)
diffs
(~(put ju diffs) id diff)
:: emit notifications if we need to
::
?(%add-writers %del-writers)
=* writers writers.perm.diary
=. writers
?- -.diff
%add-writers (~(uni in writers) sects.diff)
%del-writers (~(dif in writers) sects.diff)
==
di-core
==
|-
?~ diff di-core
=* dd=diff:diary i.diff
?. ?=(%notes -.dd) $(diff t.diff)
=. cor (give-brief flag di-brief)
=/ cons=(list (list content:ha))
(hark:di-notes our.bowl +.dd)
=. cor
%- emil
%+ turn cons
|= cs=(list content:ha)
(pass-hark (di-spin /note/(rsh 4 (scot %ui id.dd)) cs ~))
$(diff t.diff)
--
--
89 changes: 89 additions & 0 deletions desk/lib/sparse.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
:: sparse sets: sets of numbers, minimally specified
::
:: provides types & utilities for working with sparse sets of numbers,
:: implemented as ordered lists ($sass) of number ranges ($span).
::
:: TODO path to full genericity:
:: 1. use a single comparator everywhere (lte?)
:: 2. don't assume we're working on numbers
:: 3. type constructors, wet gates, comparator arg
:: 4. rewrite in terms of trees for performance
:: 5. jet it
::
|%
+$ span [fro=@ til=@] :: range (inclusive)
+$ sass (list span) :: sparse set
::
++ fat :: inside or next to?
|= [span a=@]
&((lte (dec fro) a) (lte a +(til)))
::
::TODO optimize, can we do just three of these?
++ lap :: have overlap?
|= [a=span b=span]
?| (fat a fro.b)
(fat a til.b)
(fat b fro.a)
(fat b til.a)
==
::
++ wed :: merge
|= [a=span b=span]
^- span
[(min fro.a fro.b) (max til.a til.b)]
::
++ cut :: remove b from a
|= [a=span b=span]
^- sass
?: =(a b) ~
?: (lth til.b fro.a)
[a]~ :: no overlap (early)
?: (lte fro.b fro.a)
?: (lth til.b til.a)
[+(til.b) til.a]~ :: head overlap
~ :: full overlap
?: (lth til.b til.a)
:~ [fro.a (dec fro.b)] :: middle overlap
[+(til.b) til.a]
==
?: (lte fro.b til.a)
[fro.a (dec fro.b)]~ :: tail overlap
[a]~ :: no overlap (late)
::
++ as :: sass engine
|_ a=sass
++ put :: insert
|= b=$@(@ span)
=? b ?=(@ b) [b b]
?> ?=(^ b)
|- ^+ a
?> (lte fro.b til.b)
?~ a [b]~
?: (gth fro.i.a til.b)
[b a]
?: (lap i.a b)
$(b (wed i.a b), a t.a)
[i.a $(a t.a)]
::
++ has :: existence check
|= b=@
^- ?
?~ a |
?: (lth b fro.i.a) |
?: (lte b til.i.a) &
$(a t.a)
::
++ del :: remove
|= b=$@(@ span)
=? b ?=(@ b) [b b]
?> ?=(^ b)
|- ^+ a
?> (lte fro.b til.b)
?~ a ~
?: (gth fro.i.a til.b)
a
?: (lap i.a b)
(welp (cut i.a b) $(a t.a))
[i.a $(a t.a)]
--
--
39 changes: 20 additions & 19 deletions desk/sur/diary.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
::
:: $window: sparse set of time ranges
::
::TODO populate this
+$ window (list [from=time to=time])
::
:: .window: time range for requested notes that we haven't received
Expand All @@ -95,35 +96,35 @@
=future
==
::
:: $diff: can be applied to global
:: $diffs: can be applied to global
::
+$ diffs (list diff)
+$ diff
%- list
$% [%notes =id:notes =diff:notes]
[%order (rev order=arranged-notes)]
[%view (rev =view)]
[%sort (rev =sort)]
[%perm (rev =perm)]
==
::
++ apply-diff
|= [=global =diff]
^- (each global id)
?~ diff
global
=. global
?- -.i.diff
%order &+global(order (apply-rev order.global +.i.diff))
%view &+global(view (apply-rev view.global +.i.diff))
%sort &+global(sort (apply-rev sort.global +.i.diff))
%perm &+global(perm (apply-rev perm.global +.i.diff))
++ apply-diffs
|= [=global =diffs]
^- [(list [id:notes diff:notes]) _global]
?~ diffs [~ global]
=^ hed global
?- -.i.diffs
%order [~ global(order (apply-rev order.global +.i.diffs))]
%view [~ global(view (apply-rev view.global +.i.diffs))]
%sort [~ global(sort (apply-rev sort.global +.i.diffs))]
%perm [~ global(perm (apply-rev perm.global +.i.diffs))]
%notes
=/ res (apply-diff:notes notes.global +.i.diff)
=/ res (apply-diff:notes notes.global +.i.diffs)
?~ res
|+id.i.diff
&+global(notes u.res)
[[id.i.diffs diff.i.diffs]~ global]
[~ global(notes u.res)]
==
$(diff t.diff)
=^ tal global $(diffs t.diffs)
[(weld hed tal) global]
--
::
:: $notes: a set of time ordered diary posts
Expand Down Expand Up @@ -379,7 +380,7 @@
command
==
::
+$ remark-action
+$ remark-action
$~ [%read ~]
$>(?(%read %read-at %watch %unwatch) action)
::
Expand All @@ -401,7 +402,7 @@
::
:: $diff: the full suite of modifications that can be made to a diary
::
+$ diff diff:diary
+$ diff diffs:diary
::
:: $net: an indicator of whether I'm a host or subscriber
::
Expand Down

0 comments on commit d52657f

Please sign in to comment.