News for hackers. Stuff that matters.
Re:The Skip list by eru on Saturday March 06, 2010 @06:55AM (#1171432)
How do you develop a persistent (i.e. purely functional) version of them?
Re:The Skip list by camccann on Saturday March 06, 2010 @10:55AM (#1171656)
Brief nitpicking: "persistent" and "purely functional" are not really the same thing.

On the "purely functional" end, any stochastic algorithm is by definition not pure in the "referentially transparent" sense, so that's right out, and building a PRNG into the data structure is probably suboptimal.

As far as persistence/immutability go, the skip list doesn't seem well suited to that, either--any time you change an element, you'd have to replace all the elements with pointers to it, and elements with pointers to those, and so on recursively. There are standard solutions to this, but all would entail nontrivial changes to the structure.

In the end, it would be easy to make something not obviously broken that looked like a skip list, but I don't know whether it would have the same performance characteristics, or even worthwhile performance at all.

Given that skip lists are, in essence, a way of retrofitting some of the benefits of a tree structure onto a linked list, I suspect it would be more worthwhile to find an existing immutable, functional tree structure and retrofit some of the benefits of a linked list onto it.

Re:The Skip list by eru on Saturday March 06, 2010 @01:42PM (#1171920)
> Brief nitpicking: "persistent" and "purely functional" are not really the same thing.

You are right about that. But I did not have time for a longer explanation and some people take "persistent" to mean "can be saved to disk".

For stochastic algorithms you will probably use the same trick as with monadic I/O --- you can make the description of the algorithm purely functional, but not its execution.

Re:The Skip list by camccann on Saturday March 06, 2010 @02:40PM (#1171988)
For stochastic algorithms you will probably use the same trick as with monadic I/O --- you can make the description of the algorithm purely functional, but not its execution.

Certainly possible, but how well this works depends on how, and to what extent, referential transparency is enforced by the language.

For instance, in Haskell, there really isn't a satisfying solution that I'm aware of. Threading a PRNG (as with the state monad) keeps the code "pure", but enforces a strict sequencing on use of the structure, wrecking laziness. On the other hand, any nondeterminism without threading a PRNG probably requires unsafePerformIO.

Re:The Skip list by chancho on Saturday March 06, 2010 @03:04PM (#1172040)
'Probabilistic' doesn't have to mean 'nondeterministic'. Hash tables are deterministic and probabilistic. You could probably do the same with a skip list: hash the key to see what level of the skip list it gets promoted to.
Re:The Skip list by eru on Sunday March 07, 2010 @12:36PM (#1173664)
If you split your PRNG, you can 'tree' it through your algorithm instead of threading it. That should help with lazyness.
Re:The Skip list by keefe on Saturday March 06, 2010 @12:10PM (#1171764)
local state, I like to have it... I think this is a nice argument for using oop
Re:The Skip list by chancho on Saturday March 06, 2010 @12:19PM (#1171778)
local state, you will not like what concurrent threads do to it... For every nice argument there is a counter.
Re:The Skip list by keefe on Saturday March 06, 2010 @02:03PM (#1171946)
I'm absolutely fine with what concurrent threads would do to it? Thread synch stuff is really not hard once you've done it a while. It's actually one of the more fun pieces of programming, given that you have jprofiler (or similar) to inspect what's going on in the jvm as you try different things. To me, it is a very logical idea and powerful tool to pair up a bit of memory with a bit of algorithm.
Re:The Skip list by eru on Monday March 08, 2010 @10:33AM (#1175498)
But --- is it composable?
Re:The Skip list by keefe on Monday March 08, 2010 @02:53PM (#1176245)
Probably not, but I'm getting good throughput and low latency in performance tests and I never see a deadlock so who cares?
Re:The Skip list by pmjordan on Saturday March 06, 2010 @07:28AM (#1171449)
There aren't any cycles, so this shouldn't be difficult. I'm not sure how efficient it'll be though, even with laziness.
Re:The Skip list by crux_ on Saturday March 06, 2010 @12:33PM (#1171805)
An easy first guess as to efficiency would be O(n) for insertions and deletions, since that's what you need to maintain a sorted list (which is the lowest level of a skip-list).
Re:The Skip list by chancho on Saturday March 06, 2010 @12:50PM (#1171835)
It doesn't have to be a linked list though. There are other purely functional sequence data structures which support O(log n) insertion and deletion, e.g. Haskell's Data.Sequence, which is a finger tree of some sort. If you could find a way to do binary search on one of these in better than O(log^2 n) time you'd pretty much have your purely functional skip list.