Re: Upcoming GLib changes

On Sat, 3 Jul 1999, Scott Wimer wrote:

> Tim,
> Basically, I want an array/list where I can work off of either 
> end with equal ease.
> I've only rarely needed a queue.  I've on many occasions wanted
> to work of both ends of a list.

ok, imagine something like:

typedef struct _GQueue GQueue;
struct _GQueue
  GList *head;
  GList *tail;

GQueue*  g_queue_create         (void);
void     g_queue_free           (GQueue  *queue);
void     g_queue_push_head      (GQueue  *queue,
                                 gpointer data);
void     g_queue_push_tail      (GQueue  *queue,
                                 gpointer data);
gpointer g_queue_pop_head       (GQueue  *queue);
gpointer g_queue_pop_tail       (GQueue  *queue);
guint    g_queue_length         (GQueue  *queue);
gboolean g_queue_is_empty       (GQueue  *queue);
/* and maybe */
gpointer g_queue_peek_head      (GQueue  *queue);
gpointer g_queue_peek_tail      (GQueue  *queue);

/* and maybe for interoparability */
void     g_queue_push_head_link (GQueue  *queue,
                                 GList   *link);
void     g_queue_push_tail_link (GQueue  *queue,
                                 GList   *link);
GList*   g_queue_pop_head_link  (GQueue  *queue);
GList*   g_queue_pop_tail_link  (GQueue  *queue);

that would be everything you could need, right?
i.e. normal stack (LIFO) behaviour:

g_queue_push_head (q, data);
data = g_queue_pop_head (q);

or even

g_queue_push_tail (q, data);
data = g_queue_pop_tail (q);

and "double ended" stack (FIFO) behaviour:

g_queue_push_head (q, data);
data = g_queue_pop_tail (q);


g_queue_push_tail (q, data);
data = g_queue_pop_head (q);

it just happens that we refer to these double ended stacks as "Queues".
it doesn't really matter how you call it, the implementation is the same:
FIFO lists = queues = doubly linked list + tail cache = double ended stack.

> Just my 2 cents,
> scottwimer

just my, erm - 10 Pfennig? ;)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]