[xiph-commits] r3212 - liboggz/trunk/src/liboggz
shans at svn.annodex.net
shans at svn.annodex.net
Wed Aug 29 17:49:32 PDT 2007
Author: shans
Date: 2007-08-29 17:49:32 -0700 (Wed, 29 Aug 2007)
New Revision: 3212
Added:
liboggz/trunk/src/liboggz/oggz_dlist.c
liboggz/trunk/src/liboggz/oggz_dlist.h
Modified:
liboggz/trunk/src/liboggz/Makefile.am
Log:
Double-linked list implementation for oggz
Modified: liboggz/trunk/src/liboggz/Makefile.am
===================================================================
--- liboggz/trunk/src/liboggz/Makefile.am 2007-08-30 00:49:02 UTC (rev 3211)
+++ liboggz/trunk/src/liboggz/Makefile.am 2007-08-30 00:49:32 UTC (rev 3212)
@@ -18,6 +18,7 @@
oggz_stream.c oggz_stream.h \
oggz_table.c \
oggz_vector.c oggz_vector.h \
+ oggz_dlist.c oggz_dlist.h \
metric_internal.c
liboggz_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ @SHLIB_VERSION_ARG@
Added: liboggz/trunk/src/liboggz/oggz_dlist.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_dlist.c (rev 0)
+++ liboggz/trunk/src/liboggz/oggz_dlist.c 2007-08-30 00:49:32 UTC (rev 3212)
@@ -0,0 +1,171 @@
+/*
+ Copyright (C) 2003 Commonwealth Scientific and Industrial Research
+ Organisation (CSIRO) Australia
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of CSIRO Australia nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "config.h"
+#include <stdlib.h>
+
+#include "oggz_dlist.h"
+
+typedef struct OggzDListElem {
+ struct OggzDListElem * next;
+ struct OggzDListElem * prev;
+ void * data;
+} OggzDListElem;
+
+struct _OggzDList {
+ OggzDListElem * head;
+ OggzDListElem * tail;
+};
+
+OggzDList *
+oggz_dlist_new (void) {
+
+ OggzDList *dlist = malloc(sizeof(OggzDList));
+
+ OggzDListElem * dummy_front = malloc(sizeof(OggzDListElem));
+ OggzDListElem * dummy_back = malloc(sizeof(OggzDListElem));
+
+ dummy_front->next = dummy_back;
+ dummy_front->prev = NULL;
+
+ dummy_back->prev = dummy_front;
+ dummy_back->next = NULL;
+
+ dlist->head = dummy_front;
+ dlist->tail = dummy_back;
+
+}
+
+void
+oggz_dlist_delete(OggzDList *dlist) {
+
+ OggzDListElem *p;
+
+ for (p = dlist->head->next; p != NULL; p = p->next) {
+ free(p->prev);
+ }
+
+ free(dlist->tail);
+ free(dlist);
+
+}
+
+int
+oggz_dlist_is_empty(OggzDList *dlist) {
+ return (dlist->head->next == dlist->tail);
+}
+
+void
+oggz_dlist_append(OggzDList *dlist, void *elem) {
+
+ OggzDListElem *new_elem = malloc(sizeof(OggzDListElem));
+
+ new_elem->data = elem;
+ new_elem->next = dlist->tail;
+ new_elem->prev = dlist->tail->prev;
+ new_elem->prev->next = new_elem;
+ new_elem->next->prev = new_elem;
+}
+
+void
+oggz_dlist_prepend(OggzDList *dlist, void *elem) {
+
+ OggzDListElem *new_elem = malloc(sizeof(OggzDListElem));
+
+ new_elem->data = elem;
+ new_elem->prev = dlist->head;
+ new_elem->next = dlist->head->next;
+ new_elem->prev->next = new_elem;
+ new_elem->next->prev = new_elem;
+
+}
+
+void
+oggz_dlist_iter(OggzDList *dlist, OggzDListIterFunc func) {
+
+ OggzDListElem *p;
+
+ for (p = dlist->head->next; p != dlist->tail; p = p->next) {
+ if (func(p->data) == DLIST_ITER_CANCEL) {
+ break;
+ }
+ }
+
+}
+
+void
+oggz_dlist_reverse_iter(OggzDList *dlist, OggzDListIterFunc func) {
+
+ OggzDListElem *p;
+
+ for (p = dlist->tail->prev; p != dlist->head; p = p->prev) {
+ if (func(p->data) == DLIST_ITER_CANCEL) {
+ break;
+ }
+ }
+}
+
+void
+oggz_dlist_deliter(OggzDList *dlist, OggzDListIterFunc func) {
+
+ OggzDListElem *p;
+
+ for (p = dlist->head->next; p != dlist->tail; p = p->next) {
+ if (func(p->data) == DLIST_ITER_CANCEL) {
+ break;
+ }
+
+ p->prev->next = p->next;
+ p->next->prev = p->prev;
+
+ free(p);
+ }
+
+}
+
+void
+oggz_dlist_reverse_deliter(OggzDList *dlist, OggzDListIterFunc func) {
+
+ OggzDListElem *p;
+
+ for (p = dlist->tail->prev; p != dlist->head; p = p->prev) {
+ if (func(p->data) == DLIST_ITER_CANCEL) {
+ break;
+ }
+
+ p->prev->next = p->next;
+ p->next->prev = p->prev;
+
+ free(p);
+ }
+
+}
Added: liboggz/trunk/src/liboggz/oggz_dlist.h
===================================================================
--- liboggz/trunk/src/liboggz/oggz_dlist.h (rev 0)
+++ liboggz/trunk/src/liboggz/oggz_dlist.h 2007-08-30 00:49:32 UTC (rev 3212)
@@ -0,0 +1,70 @@
+/*
+ Copyright (C) 2003 Commonwealth Scientific and Industrial Research
+ Organisation (CSIRO) Australia
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of CSIRO Australia nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __OGGZ_DLIST_H__
+#define __OGGZ_DLIST_H__
+
+struct _OggzDList;
+typedef struct _OggzDList OggzDList;
+
+typedef enum {DLIST_ITER_CANCEL, DLIST_ITER_CONTINUE} OggzDListIterResponse;
+
+typedef OggzDListIterResponse (*OggzDListIterFunc) (void *elem);
+
+OggzDList *
+oggz_dlist_new (void);
+
+void
+oggz_dlist_delete(OggzDList *dlist);
+
+int
+oggz_dlist_is_empty(OggzDList *dlist);
+
+void
+oggz_dlist_append(OggzDList *dlist, void *elem);
+
+void
+oggz_dlist_prepend(OggzDList *dlist, void *elem);
+
+void
+oggz_dlist_iter(OggzDList *dlist, OggzDListIterFunc func);
+
+void
+oggz_dlist_reverse_iter(OggzDList *dlist, OggzDListIterFunc func);
+
+void
+oggz_dlist_deliter(OggzDList *dlist, OggzDListIterFunc func);
+
+void
+oggz_dlist_reverse_deliter(OggzDList *dlist, OggzDListIterFunc func);
+
+#endif
More information about the commits
mailing list