From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: David Kastrup <dak@gnu.org>
Cc: guile-devel@gnu.org
Subject: Re: Growable arrays?
Date: Mon, 11 Jun 2012 10:14:00 +0200 [thread overview]
Message-ID: <87txyi465z.fsf@gnuvola.org> (raw)
In-Reply-To: <87hauku0mb.fsf@fencepost.gnu.org> (David Kastrup's message of "Sat, 09 Jun 2012 14:32:28 +0200")
() David Kastrup <dak@gnu.org>
() Sat, 09 Jun 2012 14:32:28 +0200
Suggestions?
Guile-SDL implements (in C) collections of "enums" using both a C array
(static, used also for init) and a Scheme hash table for backing store:
http://git.savannah.gnu.org/cgit/guile-sdl.git/tree/src/sdlenums.c#n66
This is not dynamic (growable) as you specified, but i figure it
might be useful as an example building block. The modifications
are straightforward. You would have to add a container for the
set of arrays, and two (more) indirections to ‘lookup’ (line 97),
the first to distinguish between integer/otherwise ‘key’, the
second to index into the outer container.
Alternatively, keep track of collection size and add entries to
the hash table under both the user-given key and the monotonic
‘size - 1’ (two entries). Extremely wasteful spacewise.
Less wasteful spacewise but more wasteful timewise would be to
combine the above approaches, where the initial (static, before
growth) set does not get a double entry, but in turn requires
another check (branch) in ‘lookup’. Actually the cut-off index
need not be the initial set; it need only correspond to the
initial array allocation (possibly greater than the initial set).
I suspect some of these considerations have gone into the vlist
implementation (though not all since IIRC vlists alloc doubling
"on overflow"; there is not a single threshold), so another idea
is to use that, back-porting as necessary.
Tangential: I think vlists should be aggressively exercised,
debugged and then back-ported to 1.8 and before. It's a nice
self-contained design. This requires a change of policy, though.
next prev parent reply other threads:[~2012-06-11 8:14 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-09 12:32 Growable arrays? David Kastrup
2012-06-09 14:43 ` Krister Svanlund
2012-06-09 17:35 ` David Kastrup
2012-06-11 4:23 ` Daniel Hartwig
2012-06-11 4:37 ` David Kastrup
2012-06-11 5:00 ` Daniel Hartwig
2012-06-11 7:25 ` David Kastrup
2012-06-11 9:01 ` Daniel Hartwig
2012-06-11 9:13 ` Daniel Hartwig
2012-06-11 10:38 ` David Kastrup
2012-06-11 11:57 ` Daniel Hartwig
2012-06-11 12:13 ` Noah Lavine
2012-06-11 12:28 ` David Kastrup
2012-06-11 23:50 ` Mark H Weaver
2012-06-12 9:34 ` David Kastrup
2012-06-12 20:34 ` Mark H Weaver
2012-06-12 20:47 ` David Kastrup
2012-06-12 21:03 ` Mark H Weaver
2012-06-12 21:18 ` David Kastrup
2012-06-11 8:14 ` Thien-Thi Nguyen [this message]
2012-06-11 9:08 ` Andy Wingo
2012-06-11 9:55 ` David Kastrup
2012-06-11 11:25 ` Andy Wingo
2012-06-11 12:00 ` David Kastrup
2012-06-11 12:12 ` David Kastrup
2012-06-11 12:20 ` David Kastrup
2012-06-11 13:04 ` Daniel Hartwig
2012-06-11 14:19 ` David Kastrup
2012-06-11 15:24 ` Stefan Israelsson Tampe
2012-06-11 15:27 ` Andy Wingo
2012-06-11 16:03 ` David Kastrup
2012-06-11 12:20 ` Daniel Hartwig
2012-06-11 12:36 ` David Kastrup
2012-06-11 12:02 ` Ludovic Courtès
2012-06-12 13:36 ` Hans Aberg
2012-06-14 14:33 ` Mark H Weaver
2012-06-14 14:47 ` David Kastrup
2012-06-14 15:23 ` Daniel Hartwig
2012-06-14 15:34 ` David Kastrup
2012-06-14 16:56 ` Daniel Hartwig
2012-06-14 17:15 ` David Kastrup
2012-06-14 17:23 ` Daniel Hartwig
2012-06-14 17:49 ` David Kastrup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87txyi465z.fsf@gnuvola.org \
--to=ttn@gnuvola.org \
--cc=dak@gnu.org \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).