2

Possible Duplicate:
Zipper like data structure with more then one cursor

Let T a big tree (or another big data structure). Suppose you have some interest points in it (P = {p1, p2, ...} where pN in T). You can use zippers for each pN but, what if I must update (CRUD) T on certain pN?.

Ignoring shared memory issue (solved with locks), using a imperative language I can use pointers. Updating pN I'm updating T really.

What's correct way on ("pure") Haskell?

Thanks!

NOTE: P is a real list, all time we have P with interest points and we can update one point, some or all at a time. P exists to avoid search each pN at each time (T is big). Thanks again!

UPDATE: I'm sorry, I find a correct response to my problem (Zipper like data structure with more than one cursor), how I can update (or remove) my question?

Community
  • 1
  • 1
josejuan
  • 9,338
  • 24
  • 31

1 Answers1

1

"You can use zippers for each pN"

Imagine a text adventure game, like Zork. You are the zipper and T is the tree-world you are exploring. In room p7 you can alter the contents and do the U in CRUD. Then you look at you options:

  • You may move UP the tree T
  • You may move LEFT-DOWN the tree T
  • You may move LEFT-RIGHT the tree T

That list covers the basic moves in a binary tree, your T may differ. To update all of P you walk the zipper along some route to visit all the p1, p2, p3, etc. A simple route is to start at the root of T, descend to p1, go back up to root of T, descend to p2, go back to root of T, descend to p3, etc.

Eventually you are done and leave the T-world. This is often called "closing the zipper".

Chris Kuklewicz
  • 8,123
  • 22
  • 33
  • 1
    Thanks Chris! but P is a real list to speedup updates on each pN (T is big). I've updated description. :) – josejuan Aug 27 '12 at 09:48