Add copyright, clean up code a bit.

1999-03-17  Jeff Garzik  <jgarzik@pobox.com>

        * gstack.c, gqueue.c:
        Add copyright, clean up code a bit.
This commit is contained in:
Jeff Garzik 1999-03-17 15:38:18 +00:00 committed by Jeff Garzik
parent 771d712085
commit 05f42cc0e2
11 changed files with 225 additions and 154 deletions

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,3 +1,8 @@
1999-03-17 Jeff Garzik <jgarzik@pobox.com>
* gstack.c, gqueue.c:
Add copyright, clean up code a bit.
1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1999-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on * configure.in: Added missing values for G_MAXU(SHORT|INT|LONG) on

View File

@ -1,20 +1,21 @@
/* /* GLIB - Library of useful routines for C programming
* GQueue, opaque ADT with interface: * Copyright (C) 1999 Free Software Foundation, Inc.
*
q = g_queue_new (); * This library is free software; you can redistribute it and/or
count = g_queue_size (q); * modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
q_queue_push_front (q, data); * version 2 of the License, or (at your option) any later version.
q_queue_push_back (q, data); *
data = q_queue_pop_front (q); * This library is distributed in the hope that it will be useful,
data = q_queue_pop_back (q); * but WITHOUT ANY WARRANTY; without even the implied warranty of
#define q_queue_push q_queue_push_back * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#define q_queue_pop q_queue_pop_front * Library General Public License for more details.
*
list = g_queue_get_list (q); * You should have received a copy of the GNU Library General Public
#define g_queue_get_front g_queue_get_list * License along with this library; if not, write to the
list_end = g_queue_get_back (q); * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
*/ * Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -41,11 +42,12 @@ g_queue_new (void)
void void
g_queue_free (GQueue *q) g_queue_free (GQueue *q)
{ {
if (q) { if (q)
if (q->list) {
g_list_free (q->list); if (q->list)
g_free (q); g_list_free (q->list);
} g_free (q);
}
} }
@ -59,30 +61,32 @@ g_queue_get_size (GQueue *q)
void void
g_queue_push_front (GQueue *q, gpointer data) g_queue_push_front (GQueue *q, gpointer data)
{ {
if (q) { if (q)
q->list = g_list_prepend (q->list, data); {
q->list = g_list_prepend (q->list, data);
if (q->list_end == NULL) if (q->list_end == NULL)
q->list_end = q->list; q->list_end = q->list;
q->list_size++; q->list_size++;
} }
} }
void void
g_queue_push_back (GQueue *q, gpointer data) g_queue_push_back (GQueue *q, gpointer data)
{ {
if (q) { if (q)
q->list_end = g_list_append (q->list_end, data); {
q->list_end = g_list_append (q->list_end, data);
if (! q->list) if (! q->list)
q->list = q->list_end; q->list = q->list_end;
else else
q->list_end = q->list_end->next; q->list_end = q->list_end->next;
q->list_size++; q->list_size++;
} }
} }
@ -91,24 +95,27 @@ g_queue_pop_front (GQueue *q)
{ {
gpointer data = NULL; gpointer data = NULL;
if ((q) && (q->list)) { if ((q) && (q->list))
GList *node; {
GList *node;
node = q->list; node = q->list;
data = node->data; data = node->data;
if (! node->next) { if (! node->next)
q->list = q->list_end = NULL; {
q->list_size = 0; q->list = q->list_end = NULL;
q->list_size = 0;
}
else
{
q->list = node->next;
q->list->prev = NULL;
q->list_size--;
}
g_list_free_1 (node);
} }
else {
q->list = node->next;
q->list->prev = NULL;
q->list_size--;
}
g_list_free_1 (node);
}
return data; return data;
} }
@ -119,24 +126,27 @@ g_queue_pop_back (GQueue *q)
{ {
gpointer data = NULL; gpointer data = NULL;
if ((q) && (q->list)) { if ((q) && (q->list))
GList *node; {
GList *node;
node = q->list_end; node = q->list_end;
data = node->data; data = node->data;
if (! node->prev) { if (! node->prev)
q->list = q->list_end = NULL; {
q->list_size = 0; q->list = q->list_end = NULL;
q->list_size = 0;
}
else
{
q->list_end = node->prev;
q->list_end->next = NULL;
q->list_size--;
}
g_list_free_1 (node);
} }
else {
q->list_end = node->prev;
q->list_end->next = NULL;
q->list_size--;
}
g_list_free_1 (node);
}
return data; return data;
} }

142
gqueue.c
View File

@ -1,20 +1,21 @@
/* /* GLIB - Library of useful routines for C programming
* GQueue, opaque ADT with interface: * Copyright (C) 1999 Free Software Foundation, Inc.
*
q = g_queue_new (); * This library is free software; you can redistribute it and/or
count = g_queue_size (q); * modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
q_queue_push_front (q, data); * version 2 of the License, or (at your option) any later version.
q_queue_push_back (q, data); *
data = q_queue_pop_front (q); * This library is distributed in the hope that it will be useful,
data = q_queue_pop_back (q); * but WITHOUT ANY WARRANTY; without even the implied warranty of
#define q_queue_push q_queue_push_back * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#define q_queue_pop q_queue_pop_front * Library General Public License for more details.
*
list = g_queue_get_list (q); * You should have received a copy of the GNU Library General Public
#define g_queue_get_front g_queue_get_list * License along with this library; if not, write to the
list_end = g_queue_get_back (q); * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
*/ * Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -41,11 +42,12 @@ g_queue_new (void)
void void
g_queue_free (GQueue *q) g_queue_free (GQueue *q)
{ {
if (q) { if (q)
if (q->list) {
g_list_free (q->list); if (q->list)
g_free (q); g_list_free (q->list);
} g_free (q);
}
} }
@ -59,30 +61,32 @@ g_queue_get_size (GQueue *q)
void void
g_queue_push_front (GQueue *q, gpointer data) g_queue_push_front (GQueue *q, gpointer data)
{ {
if (q) { if (q)
q->list = g_list_prepend (q->list, data); {
q->list = g_list_prepend (q->list, data);
if (q->list_end == NULL) if (q->list_end == NULL)
q->list_end = q->list; q->list_end = q->list;
q->list_size++; q->list_size++;
} }
} }
void void
g_queue_push_back (GQueue *q, gpointer data) g_queue_push_back (GQueue *q, gpointer data)
{ {
if (q) { if (q)
q->list_end = g_list_append (q->list_end, data); {
q->list_end = g_list_append (q->list_end, data);
if (! q->list) if (! q->list)
q->list = q->list_end; q->list = q->list_end;
else else
q->list_end = q->list_end->next; q->list_end = q->list_end->next;
q->list_size++; q->list_size++;
} }
} }
@ -91,24 +95,27 @@ g_queue_pop_front (GQueue *q)
{ {
gpointer data = NULL; gpointer data = NULL;
if ((q) && (q->list)) { if ((q) && (q->list))
GList *node; {
GList *node;
node = q->list; node = q->list;
data = node->data; data = node->data;
if (! node->next) { if (! node->next)
q->list = q->list_end = NULL; {
q->list_size = 0; q->list = q->list_end = NULL;
q->list_size = 0;
}
else
{
q->list = node->next;
q->list->prev = NULL;
q->list_size--;
}
g_list_free_1 (node);
} }
else {
q->list = node->next;
q->list->prev = NULL;
q->list_size--;
}
g_list_free_1 (node);
}
return data; return data;
} }
@ -119,24 +126,27 @@ g_queue_pop_back (GQueue *q)
{ {
gpointer data = NULL; gpointer data = NULL;
if ((q) && (q->list)) { if ((q) && (q->list))
GList *node; {
GList *node;
node = q->list_end; node = q->list_end;
data = node->data; data = node->data;
if (! node->prev) { if (! node->prev)
q->list = q->list_end = NULL; {
q->list_size = 0; q->list = q->list_end = NULL;
q->list_size = 0;
}
else
{
q->list_end = node->prev;
q->list_end->next = NULL;
q->list_size--;
}
g_list_free_1 (node);
} }
else {
q->list_end = node->prev;
q->list_end->next = NULL;
q->list_size--;
}
g_list_free_1 (node);
}
return data; return data;
} }

View File

@ -1,19 +1,28 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1999 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include <config.h> # include <config.h>
#endif #endif
#include <glib.h> #include <glib.h>
/*
* GStack, opaque ADT with interface:
stack = g_stack_new ();
count = g_stack_size (stack);
g_stack_push (stack, data);
data = g_stack_pop (stack);
slist = g_stack_get_list (stack);
*/
GStack * GStack *
g_stack_new (void) g_stack_new (void)
@ -33,12 +42,13 @@ g_stack_new (void)
void void
g_stack_free (GStack *stack) g_stack_free (GStack *stack)
{ {
if (stack) { if (stack)
if (stack->list) {
g_list_free (stack->list); if (stack->list)
g_list_free (stack->list);
g_free (stack); g_free (stack);
} }
} }
@ -47,15 +57,16 @@ g_stack_pop (GStack *stack)
{ {
gpointer data = NULL; gpointer data = NULL;
if ((stack) && (stack->list)) { if ((stack) && (stack->list))
GList *node = stack->list; {
GList *node = stack->list;
stack->list = stack->list->next; stack->list = stack->list->next;
data = node->data; data = node->data;
g_list_free_1 (node); g_list_free_1 (node);
} }
return data; return data;
} }