Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
PFDS 10.1.2Binary Random-Access     List Revisited                 @rf0444
a Seq = NIL | CONS of a * (a * a) Seq  NIL  CONS 1 NIL  CONS 1 (CONS (2, 3) NIL)  CONS 1 (CONS (2,3) (CONS ((4,5),(6,7)) N...
a Seq = NIL | CONS of a * (a * a) Seq  NIL       0個  CONS 1 NIL     1個  CONS 1 (CONS (2, 3) NIL)    3個  CONS 1 (CONS (2,3)...
a Seq = NIL | CONS of a * (a * a) Seq  CONS 1 (CONS (2,3) (CONS ((4,5),(6,7)) NIL))      1個        2個                4個   ...
9.2.1 Binary Random-Access Listsa Tree = LEAF of a | NODE of a Tree * a Treea Digit = ZERO | ONE of a Treea RList = a Digi...
9.2.1 Binary Random-Access Lists 型だけ見ると下の構成もできるように見える            ONE ZERO ONEサイズが                               5        1...
10.1.2 Binary Random-Access            Lists Revisiteda Seq = NIL | ZERO of (a * a) Seq           | ONE of a * (a * a) Seq...
head, tail大体 9.2.1 と同じ
lookuplookup 5     ONE    ONE     ZERO                   ONE      1    (2, 3)          (((4, 5), (6, 7)), ((8, 9), (10, 11...
lookuplookup 5     ONE    ONE     ZERO                   ONE      1    (2, 3)          (((4, 5), (6, 7)), ((8, 9), (10, 11...
lookuplookup 4    ZERO      ONE      ZERO                    ONE             (2, 3)            (((4, 5), (6, 7)), ((8, 9),...
lookuplookup 2 の左         ONE     ZERO                   ONE        (2, 3)          (((4, 5), (6, 7)), ((8, 9), (10, 11)))...
lookuplookup 1 の左         ZERO ZERO                   ONE                     (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup...
lookuplookup 0 の右 の左          ZERO                   ONE                 (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup 0 の左...
lookuplookup 0 の左 の右 の左                                                          ONE                                      ...
updateupdate 5 20     ONE    ONE     ZERO                   ONE      1    (2, 3)          (((4, 5), (6, 7)), ((8, 9), (10,...
updateupdate 5 20     ONE     ONE     ZERO                   ONE      1     (2, 3)          (((4, 5), (6, 7)), ((8, 9), (1...
updatecons 1 . update 4 20     ZERO    ONE     ZERO                   ONE            (2, 3)          (((4, 5), (6, 7)), ((...
updatecons 1 . ZERO . update 2 (20, 7)            ONE     ZERO                   ONE           (2, 3)          (((4, 5), (...
updatecons 1 . ZERO . cons (2, 3) . update 1 (20, 7)             ZERO ZERO                   ONE                         (...
updatecons 1 . ZERO . cons (2, 3) . ZERO .update 0 ((4, 5), (20, 7))                  ZERO                   ONE          ...
updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO .update 0 (((4, 5), (20, 7)), ((8, 9), (10, 11)))                         ...
updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO                                           ONE                           ((...
update先頭要素が ZERO の時に毎回 lookup が走る 結果、update は O(log^2 n)変更する値ではなく、変更する関数を渡すようにする
updateupdate 5 20      ONE     ONE     ZERO                    ONE       1     (2, 3)           (((4, 5), (6, 7)), ((8, 9)...
updatefupdate (fn _ -> 20) 5     ONE     ONE     ZERO                   ONE      1     (2, 3)          (((4, 5), (6, 7)), ...
updatecons 1 . fupdate (fn x -> 20) 4     ZERO    ONE     ZERO                   ONE            (2, 3)          (((4, 5), ...
updatecons 1 . ZERO . fupdate (fn (x, y) -> (20, y)) 2            ONE     ZERO                   ONE           (2, 3)     ...
updatecons 1 . ZERO . cons (2, 3) .fupdate (fn (x, y) -> (20, y)) 1              ZERO ZERO                   ONE          ...
updatecons 1 . ZERO . cons (2, 3) . ZERO .fupdate (fn (w, (x, y)) -> (w, (20, y))) 0                   ZERO               ...
updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO .fupdate (fn ((w, (x, y)), z) -> ((w, (20, y)), z)) 0                     ...
updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO                                          ONE                          (((4...
Upcoming SlideShare
Loading in …5
×

PFDS 10.1.2

531 views

Published on

  • Be the first to comment

PFDS 10.1.2

  1. 1. PFDS 10.1.2Binary Random-Access List Revisited @rf0444
  2. 2. a Seq = NIL | CONS of a * (a * a) Seq NIL CONS 1 NIL CONS 1 (CONS (2, 3) NIL) CONS 1 (CONS (2,3) (CONS ((4,5),(6,7)) NIL))
  3. 3. a Seq = NIL | CONS of a * (a * a) Seq NIL 0個 CONS 1 NIL 1個 CONS 1 (CONS (2, 3) NIL) 3個 CONS 1 (CONS (2,3) (CONS ((4,5),(6,7)) NIL)) 7個
  4. 4. a Seq = NIL | CONS of a * (a * a) Seq CONS 1 (CONS (2,3) (CONS ((4,5),(6,7)) NIL)) 1個 2個 4個 a a*a (a * a) * (a * a)
  5. 5. 9.2.1 Binary Random-Access Listsa Tree = LEAF of a | NODE of a Tree * a Treea Digit = ZERO | ONE of a Treea RList = a Digit list ONE ZERO ONE 1 2 3 4 5
  6. 6. 9.2.1 Binary Random-Access Lists 型だけ見ると下の構成もできるように見える ONE ZERO ONEサイズが 5 1 2おかしい 3 4 完全じゃない
  7. 7. 10.1.2 Binary Random-Access Lists Revisiteda Seq = NIL | ZERO of (a * a) Seq | ONE of a * (a * a) Seq ((a * a) * (a * a)) * ((a * a) * (a * a)) Seq ONE ZERO ONE 1 ((2, 3), (4,5))a a*a (a * a) * (a * a)
  8. 8. head, tail大体 9.2.1 と同じ
  9. 9. lookuplookup 5 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  10. 10. lookuplookup 5 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup 4 ZERO ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  11. 11. lookuplookup 4 ZERO ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup 2 の左 ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  12. 12. lookuplookup 2 の左 ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup 1 の左 ZERO ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  13. 13. lookuplookup 1 の左 ZERO ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup 0 の右 の左 ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  14. 14. lookuplookup 0 の右 の左 ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))lookup 0 の左 の右 の左 ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  15. 15. lookuplookup 0 の左 の右 の左 ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))(((4, 5), (6, 7)), ((8, 9), (10, 11)))  の左 の右 の左 ((4, 5), (6, 7))     の右 の左 (6, 7)        の左 6
  16. 16. updateupdate 5 20 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  17. 17. updateupdate 5 20 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . update 4 20 ZERO ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  18. 18. updatecons 1 . update 4 20 ZERO ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . update 2 (20, 7) ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  19. 19. updatecons 1 . ZERO . update 2 (20, 7) ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . update 1 (20, 7) ZERO ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  20. 20. updatecons 1 . ZERO . cons (2, 3) . update 1 (20, 7) ZERO ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . ZERO .update 0 ((4, 5), (20, 7)) ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  21. 21. updatecons 1 . ZERO . cons (2, 3) . ZERO .update 0 ((4, 5), (20, 7)) ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . ZERO . ZERO .update 0 (((4, 5), (20, 7)), ((8, 9), (10, 11))) ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  22. 22. updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO .update 0 (((4, 5), (20, 7)), ((8, 9), (10, 11))) ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . ZERO . ZERO ONE (((4, 5), (20, 7)), ((8, 9), (10, 11)))
  23. 23. updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO ONE (((4, 5), (20, 7)), ((8, 9), (10, 11))) ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (20, 7)), ((8, 9), (10, 11)))
  24. 24. update先頭要素が ZERO の時に毎回 lookup が走る 結果、update は O(log^2 n)変更する値ではなく、変更する関数を渡すようにする
  25. 25. updateupdate 5 20 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))fupdate (fn _ -> 20) 5 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  26. 26. updatefupdate (fn _ -> 20) 5 ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . fupdate (fn _ -> 20) 4 ZERO ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  27. 27. updatecons 1 . fupdate (fn x -> 20) 4 ZERO ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . fupdate (fn (x, y) -> (20, y)) 2 ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  28. 28. updatecons 1 . ZERO . fupdate (fn (x, y) -> (20, y)) 2 ONE ZERO ONE (2, 3) (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) .fupdate (fn (x, y) -> (20, y)) 1 ZERO ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  29. 29. updatecons 1 . ZERO . cons (2, 3) .fupdate (fn (x, y) -> (20, y)) 1 ZERO ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . ZERO .fupdate (fn (w, (x, y)) -> (w, (20, y))) 0 ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  30. 30. updatecons 1 . ZERO . cons (2, 3) . ZERO .fupdate (fn (w, (x, y)) -> (w, (20, y))) 0 ZERO ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . ZERO . ZERO .fupdate (fn ((w, (x, y)), z) -> ((w, (20, y)), z)) 0 ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))
  31. 31. updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO .fupdate (fn ((w, (x, y)), z) -> ((w, (20, y)), z)) 0 ONE (((4, 5), (6, 7)), ((8, 9), (10, 11)))cons 1 . ZERO . cons (2, 3) . ZERO . ZERO ONE (((4, 5), (20, 7)), ((8, 9), (10, 11)))
  32. 32. updatecons 1 . ZERO . cons (2, 3) . ZERO . ZERO ONE (((4, 5), (20, 7)), ((8, 9), (10, 11))) ONE ONE ZERO ONE 1 (2, 3) (((4, 5), (20, 7)), ((8, 9), (10, 11)))

×