aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-10-04 14:43:11 +0100
committereunhhu <[email protected]>2026-10-04 14:43:11 +0100
commitda7361aae4e896edaad37dbcf404c5005a7f8596 (patch)
treeb01bde38a23df0f92093bd19dfc9ec9e39424b62 /examples
parent7340ba9af757b6f135dff9c51a193ba527f061b3 (diff)
downloadaup-da7361aae4e896edaad37dbcf404c5005a7f8596.tar.gz
aup-da7361aae4e896edaad37dbcf404c5005a7f8596.zip
Give a view a body that computes and returns its value (Pure 018)
Diffstat (limited to 'examples')
-rw-r--r--examples/routes.aup44
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/routes.aup b/examples/routes.aup
index 6656947..cf6a914 100644
--- a/examples/routes.aup
+++ b/examples/routes.aup
@@ -117,4 +117,48 @@ on path {
shortest = if best.has(path.to) { best[path.to].depth } else { -1 }
}
+# The same search as a view (Pure 018's stage 3): it reads a snapshot, so
+# it keeps no event from the owner, and readers search at once.
+view distance(start: u32, goal: u32) {
+ let seen: list of Seen by node
+ let queue: list of Step
+ queue.append(Step { node: start })
+ seen.add(Seen { node: start })
+ for i in 0 .. nodes.count {
+ if i >= queue.count { break }
+ let q = queue.first + i
+ for e in edges[q.node * 1048576 .. q.node * 1048576 + 1048576] {
+ if !seen.has(e.to) {
+ seen.add(Seen { node: e.to, depth: seen[q.node].depth + 1 })
+ queue.append(Step { node: e.to })
+ }
+ }
+ }
+ return if seen.has(goal) { seen[goal].depth } else { -1 }
+}
+
+# How many nodes the first node reaches (times 1000), and how far the farthest is.
+view reach {
+ let seen: list of Seen by node
+ let queue: list of Step
+ let farthest = 0
+ if nodes.count > 0 {
+ queue.append(Step { node: nodes.first.id })
+ seen.add(Seen { node: nodes.first.id })
+ }
+ for i in 0 .. nodes.count {
+ if i >= queue.count { break }
+ let q = queue.first + i
+ for e in edges[q.node * 1048576 .. q.node * 1048576 + 1048576] {
+ if !seen.has(e.to) {
+ let far = seen[q.node].depth + 1
+ seen.add(Seen { node: e.to, depth: far })
+ queue.append(Step { node: e.to })
+ farthest = max(farthest, far)
+ }
+ }
+ }
+ return seen.count * 1000 + farthest
+}
+
view graph = "{nodes.count} nodes, {edges.count} edges"