Skip to content

Commit b9d0e38

Browse files
committed
Replace hideous words with an even more hideous algorithm
1 parent 3da431c commit b9d0e38

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

spec/Section 6 -- Execution.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ variableValues):
152152
- Let {pending} be an empty list.
153153
- If {initialDefers} is not an empty object:
154154
- Let {id} be {nextId} and increment {nextId} by one.
155-
- Let {path} be the longest common path prefix list for every path list key in
156-
{initialDefers}, or the empty list if no such list exists.
157-
- TODO: This really needs rewording!
155+
- Let {path} be {LongestCommonPathPrefix(initialDefers)}.
158156
- Let {pendingPayload} be an unordered map containing {id}, {path}.
159157
- Add {pendingPayload} to {pending}.
160158
- Let {defers} be {initialDefers}.
@@ -229,9 +227,7 @@ variableValues):
229227
{incrementalPayload} to {incremental}.
230228
- If {batchDefers} is not an empty object:
231229
- Let {id} be {nextId} and increment {nextId} by one.
232-
- Let {path} be the longest common path prefix list for every path list
233-
key in {batchDefers}, or the empty list if no such list exists.
234-
- TODO: This really needs rewording!
230+
- Let {path} be {LongestCommonPathPrefix(batchDefers)}.
235231
- Let {pendingPayload} be an unordered map containing {id}, {path}.
236232
- Add {pendingPayload} to {pending}.
237233
- Let {defers} be {batchDefers}.
@@ -277,9 +273,7 @@ variableValues):
277273
- Append {incrementalPayload} to {incremental}.
278274
- If {childDefers} is not an empty object:
279275
- Let {id} be {nextId} and increment {nextId} by one.
280-
- Let {path} be the longest common path prefix list for every path list
281-
key in {childDefers}, or the empty list if no such list exists.
282-
- TODO: This really needs rewording!
276+
- Let {path} be {LongestCommonPathPrefix(childDefers)}.
283277
- Let {pendingPayload} be an unordered map containing {id}, {path}.
284278
- Add {pendingPayload} to {pending}.
285279
- Let {defers} be {childDefers}.
@@ -300,6 +294,26 @@ variableValues):
300294
- {FlushStream(false)}.
301295
- Complete {responseStream}.
302296

297+
LongestCommonPathPrefix(map):
298+
299+
- Let {paths} be a list of the keys of {map}.
300+
- Let {longestCommonPathPrefix} be the first entry in {paths}.
301+
- For each {path} in paths:
302+
- Let {commonPrefix} be an empty list.
303+
- Let {length} be the least of the length of {path} and the length of
304+
{longestCommonPathPrefix}.
305+
- Let {index} be {0}.
306+
- While {index} is less than {length} and the entries at position {index} in
307+
both {path} and {longestCommonPathPrefix} are both equal, let {pathEntry} be
308+
this value:
309+
- Add {pathEntry} to {commonPrefix}.
310+
- Let {longestCommonPathPrefix} be {commonPrefix}.
311+
- Return {longestCommonPathPrefix}.
312+
313+
TODO: Consider rewording to something like: Let {longestCommonPathPrefix} be the
314+
longest list such that every entry in {paths} starts with
315+
{longestCommonPathPrefix}. Note: This may be the empty list.
316+
303317
### Mutation
304318

305319
If the operation is a mutation, the result of the operation is the result of

0 commit comments

Comments
 (0)