Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Queue-Definition/E/queue-definition.e
Normal file
27
Task/Queue-Definition/E/queue-definition.e
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
def makeQueue() {
|
||||
def [var head, var tail] := Ref.promise()
|
||||
|
||||
def writer {
|
||||
to enqueue(value) {
|
||||
def [nh, nt] := Ref.promise()
|
||||
tail.resolve([value, nh])
|
||||
tail := nt
|
||||
}
|
||||
}
|
||||
|
||||
def reader {
|
||||
to empty() { return !Ref.isResolved(head) }
|
||||
|
||||
to dequeue(whenEmpty) {
|
||||
if (Ref.isResolved(head)) {
|
||||
def [value, next] := head
|
||||
head := next
|
||||
return value
|
||||
} else {
|
||||
throw.eject(whenEmpty, "pop() of empty queue")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [reader, writer]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue