Re: GLib queue and stack, alloca discussion
- From: Havoc Pennington <hp Mcs Net>
- To: gtk-devel-list redhat com
- Subject: Re: GLib queue and stack, alloca discussion
- Date: Fri, 22 Jan 1999 14:27:10 -0600 (CST)
On Fri, 22 Jan 1999, Jeff Garzik wrote:
>
> should GStack and GQueue be extended to provide analogues to g_list_*
> functions? ie. I can either provide simple function wrappers that do
> something like
>
> GList * g_queue_nth (GQueue *q, guint position) {
> return q ? 0 : g_list_nth (q->list, position);
> }
>
> or have the programmer directly access this by using q->list directly.
>
IMO this is busted - you can't get the nth thing out of a queue, that's
not how queues work. It's not a queue operation. If you want to do that,
use a list. The queue or stack could also be implemented as an array for
example (in fact that might be nicer if someone wants to do it
eventually), and relying on a listish implementation is busted.
For precedent, see the STL - a queue or stack is just a vector, but you
can't do vector operations on them. You can't iterate over a stack.
The whole point of using a queue or stack instead of a list is to place
limits on what you can do with it and thus simplify the code, no? I mean,
it's not like g_list_prepend() is any harder than g_stack_push().
The whole point of the wrapper is to make it a stack rather than a list.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]