Community preference so far? taylanbayirli@xxxxxx (26 Sep 2015 17:29 UTC)
Re: Community preference so far? Alex Shinn (29 Sep 2015 02:43 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (29 Sep 2015 09:17 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (29 Sep 2015 11:00 UTC)
Re: Community preference so far? Alex Shinn (30 Sep 2015 03:16 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (30 Sep 2015 09:37 UTC)
Re: Community preference so far? Alex Shinn (30 Sep 2015 14:02 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (30 Sep 2015 20:44 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (01 Oct 2015 08:36 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (29 Sep 2015 11:36 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (01 Oct 2015 12:53 UTC)
Re: Community preference so far? Alex Shinn (30 Sep 2015 03:32 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (30 Sep 2015 08:56 UTC)
Re: Community preference so far? Alex Shinn (30 Sep 2015 09:38 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (30 Sep 2015 09:46 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (30 Sep 2015 10:03 UTC)
Re: Community preference so far? Evan Hanson (30 Sep 2015 11:54 UTC)
Re: Community preference so far? taylanbayirli@xxxxxx (30 Sep 2015 22:34 UTC)
Re: Community preference so far? Per Bothner (29 Sep 2015 11:14 UTC)
Re: Community preference so far? John Cowan (29 Sep 2015 12:07 UTC)
Re: Community preference so far? Per Bothner (29 Sep 2015 12:47 UTC)
Re: Community preference so far? Alex Shinn (30 Sep 2015 09:15 UTC)

Re: Community preference so far? taylanbayirli@xxxxxx 01 Oct 2015 12:53 UTC

xxxxxx@gmail.com (Taylan Ulrich "Bayırlı/Kammer") writes:

> xxxxxx@gmail.com (Taylan Ulrich "Bayırlı/Kammer") writes:
>
>> A full cursor API for hash tables I have yet to see in any Scheme
>> implementation I looked at.  It's unclear to me how the cursor would
>> deal with rehashes.
>
> Correction: Racket has one, and the cursor is guaranteed to work so long
> as no entries are added to or removed from the hash table.
>
> I'll ponder and ask around on possible problems with that and add it if
> I don't find out about any problems.

If I'm not mistaken, implementing a cursor as an integer is simple with
hash tables using open addressing.

For those using chaining, one could use a record type bundling a bucket
vector index with a cell; 'cursor-next' could look like:

    (let ((index (cursor-index cursor))
          (cell (cursor-cell cursor)))
      (if (null? (cdr cell))
          (make-cursor (+ 1 index) (vector-ref buckets (+ 1 index)))
          (make-cursor index (cdr cell))))

(except that I don't handle the termination case, and don't jump over
empty buckets, but you get the idea)

That requires a low-level implementation when the bucket vector isn't
actually a Scheme vector, and I would rather not burden implementations
with that.  There might also be problems I fail to see right now with
this strategy I came up with on a whim.  We're also allocating a new
cursor for every step.

An alternative might be to use continuations:

  (define (hashtable-cursor ht)
    (call-with-prompt ht-walk
      (lambda ()
        (hashtable-walk ht
          (lambda (k v)
            (abort-to-prompt ht-walk k v))))
      (lambda (cont k v)
        (make-cursor cont k v))))

  (define (hashtable-cursor-next cursor)
    (call-with-prompt ht-walk
      (cursor-cont cursor)
      (lambda (cont k v)
        (make-cursor cont k v))))

I just tried that in Guile, but apparently the partial continuation I
create ends up being an "unrewindable" one.  I don't know why; it could
be because rewinding across C stack frames is not supported or so.

I also tried to make a call/cc based version, and failed, although it
seems possible because it doesn't have the "unrewindable continuation"
problem (I came far enough to notice that).  Possibly it mandates a
different API than hashtable-cursor/hashtable-cursor-next.  The
implementation would probably be pretty inefficient too.

So I'd say we want to keep cursors out of SRFI-126.  Or I can try to add
them as an optional feature if you think that would help.

Taylan