Re: Advice on choosing the right data structure

2013-12-07 Thread dabd
Why isn't a zipper appropriate for tree recursion? On Sunday, December 8, 2013 2:16:33 AM UTC, Alexander Hudek wrote: > > This is still just recursion because of the map. That means it has all the > problems of recursion. If you need to avoid recursion, you need to do a > depth first or breadth

Re: Advice on choosing the right data structure

2013-12-07 Thread Alexander Hudek
This is still just recursion because of the map. That means it has all the problems of recursion. If you need to avoid recursion, you need to do a depth first or breadth first traversal of the tree and hold onto state as you do it. The zipper does some of this for you and provides an easy way to

Re: Advice on choosing the right data structure

2013-12-04 Thread dabd
Thanks I'll take a look at your libraries. One problem I found with the zipper API is that if you have a recursive function that takes a loc, when you call it on the clojure.zip/children of a given loc it won't work because this function returns a seq of nodes instead of a seq of locs. Shouldn'

Re: Advice on choosing the right data structure

2013-12-04 Thread Alexander Hudek
Additionally, if you need more complex access patterns you could see if this helps: https://github.com/akhudek/zip-visit For performance, there is a fast-zip library that is api compatible with clojure.zip. You can just swap the clojure.zip namespace for the fast-zip namespace. Note that you'd

Re: Advice on choosing the right data structure

2013-12-04 Thread James Reeves
On 4 December 2013 21:09, dabd wrote: > I didn't get there because I ran into problems with the zipper API. When > you call 'children' on a loc you get a seq of nodes instead of a seq of > locs which causes me problems in a recursive algorithm operating on locs. > Have you tried using next and

Re: Advice on choosing the right data structure

2013-12-04 Thread Ben Wolfson
oh, I meant custom from the bottom up, without using clojure.zip at all (so your issue with the return value of children wouldn't come up). I realize this doesn't answer your question about alternatives. On Wed, Dec 4, 2013 at 1:15 PM, dabd wrote: > I had to implement a custom tree zipper as no

Re: Advice on choosing the right data structure

2013-12-04 Thread dabd
I had to implement a custom tree zipper as none of the existing zippers worked for me. My question is are there better alternatives when you want the best performance in clojure? On Wednesday, December 4, 2013 9:12:16 PM UTC, Ben wrote: > > it might be worthwhile to implement custom zippers for

Re: Advice on choosing the right data structure

2013-12-04 Thread Ben Wolfson
it might be worthwhile to implement custom zippers for your trees, without using clojure.zip. I've done this for navigating into json structures and it was relatively painless (admittedly I only needed a smallish subset of the functionality provided by clojure.zip). On Wed, Dec 4, 2013 at 1:09 PM

Re: Advice on choosing the right data structure

2013-12-04 Thread dabd
I didn't get there because I ran into problems with the zipper API. When you call 'children' on a loc you get a seq of nodes instead of a seq of locs which causes me problems in a recursive algorithm operating on locs. On Wednesday, December 4, 2013 8:38:17 PM UTC, James Reeves wrote: > > On 4

Re: Advice on choosing the right data structure

2013-12-04 Thread James Reeves
On 4 December 2013 20:27, dabd wrote: > > I tried a purely functional approach with zippers but ran into some > trouble with the zipper API. I also think I will would have performance > problems too as there is a lot of bookkeeping in a zipper (paths, parents > associated with a loc). > You thin

Advice on choosing the right data structure

2013-12-04 Thread dabd
I go for an imperative implementation it seems like deftype to represent the tree nodes would work well since it allows for mutable fields. Any advice on choosing the right data structure and whether to use a functional or imperative implementation is appreciated. Thanks. -- -- You received