3. FIFO Queue(2リストキュー)
type foo Queue = foo list x foo list
fun head (x :: f, r) = x O(1)
fun tail (x :: f, r) = (f, r) O(1)
fun snoc ((f, r), x) = (f, x :: r) O(1)
リスト終端への挿入にconsを用いるため、
リスト後半をreverseして保持
2012年5月19日土曜日
11. §6.4.2 with Lazy Evaluation
O(1)
in amortized time
2012年5月19日土曜日
12. §6.4.2 with Lazy Evaluation
Queue with O(1) amortized time.
Persistent
Lazy Evaluation
Strict Working Copy
2012年5月19日土曜日
13. §6.4.2 with Lazy Evaluation
with the Physicist’s Method.
change in
shared potential
strict cost
(non-amortized)
cost amortized
unshared cost
cost
2012年5月19日土曜日
14. §6.4.2 with Lazy Evaluation
with the Physicist’s Method.
change in
potential
strict paid
(non-amortized) shared cost
cost
paid shared cost
= actually executed cost
2012年5月19日土曜日
15. §6.4.2 with Lazy Evaluation
with the Physicist’s Method. max potential
=
max shared cost ???
change in
potential
strict paid
(non-amortized) shared cost
cost
2012年5月19日土曜日
17. type a Queue = a list x int x a list susp x int x a list
suspended front list + ordinal rear list
lengths for front and rear lists
to calculate the diff of front and rear lengths
to guarantee front >= rear
working copy of front list
front is suspended, so necessary to keep the access to the prefix for head
queries.
2012年5月19日土曜日
18. Potential
length of working copy
diff of front and rear lengths
if those values are = 0, then rotation happens
definition of potential
Ψ(q) = min (2|w|, |f| - |r|)
2012年5月19日土曜日