diff --git a/.gitignore b/.gitignore index a99e22b..b3338dc 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,4 @@ gmon.out test-driver /assets/html/_documentation.html tags -/trdata.h* +trdata.h diff --git a/include/tr/queue.h b/include/tr/queue.h index 47f2714..69f9dd8 100644 --- a/include/tr/queue.h +++ b/include/tr/queue.h @@ -51,9 +51,12 @@ TR_CLASS(TR_Queue) { TR_INSTANCE_INIT(TR_Queue); TR_CLASSVARS_DECL(TR_Queue) {}; -void TR_queuePut(TR_Queue, void *); -void TR_queuePutFirst(TR_Queue, void *); -void * TR_queueGet(TR_Queue); +void TR_queuePut(TR_Queue, void *); +void TR_queuePutFirst(TR_Queue, void *); +void * TR_queueGet(TR_Queue); +TR_Queue TR_queueFind(TR_Queue, void *); +TR_Queue TR_queueFindParent(TR_Queue, void *); +void TR_queueDelete(TR_Queue, void *); #define TR_queueEmpty(this) (0 >= (this)->nmsg) diff --git a/src/queue/Makefile.am b/src/queue/Makefile.am index 1e8973e..bc42ec8 100644 --- a/src/queue/Makefile.am +++ b/src/queue/Makefile.am @@ -5,5 +5,12 @@ AM_CFLAGS += -I../../include/ noinst_LTLIBRARIES = libqueue.la -libqueue_la_SOURCES = queue.c get.c put.c put_first.c +libqueue_la_SOURCES = queue.c \ + get.c \ + put.c \ + put_first.c \ + find.c \ + find_parent.c \ + delete.c + libqueue_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/queue/delete.c b/src/queue/delete.c new file mode 100644 index 0000000..937b691 --- /dev/null +++ b/src/queue/delete.c @@ -0,0 +1,42 @@ +/** + * \file + * + * \author Georg Hopp + * + * \copyright + * Copyright © 2014 Georg Hopp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "trbase.h" +#include "tr/queue.h" + +void +TR_queueDelete(TR_Queue this, void * msg) +{ + TR_Queue node, parent = TR_queueFindParent(this, msg); + + if (! parent) return; + + node = parent->next; + parent->next = node->next; + if (node == this->last) { + this->last = parent; + } + TR_delete(node); + this->nmsg--; +} + +// vim: set ts=4 sw=4: diff --git a/src/queue/find.c b/src/queue/find.c new file mode 100644 index 0000000..67f51d3 --- /dev/null +++ b/src/queue/find.c @@ -0,0 +1,36 @@ +/** + * \file + * + * \author Georg Hopp + * + * \copyright + * Copyright © 2014 Georg Hopp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "trbase.h" +#include "tr/queue.h" + +TR_Queue +TR_queueFind(TR_Queue this, void * msg) +{ + TR_Queue node; + + for (node = this->first; node && node->msg != msg; node = node->next); + + return node; +} + +// vim: set ts=4 sw=4: diff --git a/src/queue/find_parent.c b/src/queue/find_parent.c new file mode 100644 index 0000000..707c29b --- /dev/null +++ b/src/queue/find_parent.c @@ -0,0 +1,36 @@ +/** + * \file + * + * \author Georg Hopp + * + * \copyright + * Copyright © 2014 Georg Hopp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "trbase.h" +#include "tr/queue.h" + +TR_Queue +TR_queueFindParent(TR_Queue this, void * msg) +{ + TR_Queue node; + + for (node = this; node->next && node->next->msg != msg; node = node->next); + + return node->next ? node : NULL; +} + +// vim: set ts=4 sw=4: diff --git a/trdata.h b/trdata.h deleted file mode 100644 index ae6b4fd..0000000 --- a/trdata.h +++ /dev/null @@ -1,93 +0,0 @@ -/* trdata.h. Generated from trdata.h.in by configure. */ -/* trdata.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define to 1 if stdbool.h conforms to C99. */ -#define HAVE_STDBOOL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDIO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYSLOG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if the system has the type `_Bool'. */ -#define HAVE__BOOL 1 - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "libtrhash" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "Georg Hopp " - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "libtrhash" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libtrhash 0.0.0" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "libtrhash" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.0.0" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "0.0.0" - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ -#endif - -/* Define to `int' if does not define. */ -/* #undef pid_t */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */