Browse Source

add queueDestroy and hashEmpty

1.0.0
Georg Hopp 11 years ago
parent
commit
b9b5faa37d
  1. 2
      include/tr/hash.h
  2. 1
      include/tr/queue.h
  3. 1
      src/hash/each.c
  4. 3
      src/queue/Makefile.am
  5. 46
      src/queue/destroy.c
  6. 12
      src/queue/queue.c

2
include/tr/hash.h

@ -36,6 +36,8 @@ TR_CLASS(TR_Hash) {
TR_INSTANCE_INIT(TR_Hash);
TR_CLASSVARS_DECL(TR_Hash) {};
#define TR_hashEmpty(hash) (NULL == (hash)->root)
void * TR_hashAdd(TR_Hash, void *);
void * TR_hashDelete(TR_Hash, const char *, size_t);
void * TR_hashGet(TR_Hash, const char *, size_t);

1
include/tr/queue.h

@ -57,6 +57,7 @@ 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 *);
void TR_queueDestroy(TR_Queue);
#define TR_queueEmpty(this) (0 >= (this)->nmsg)

1
src/hash/each.c

@ -28,7 +28,6 @@
static void (*cb)(const void*, const void*);
static
inline
void
walk(const void * node, const void * data, const int depth)
{

3
src/queue/Makefile.am

@ -11,6 +11,7 @@ libqueue_la_SOURCES = queue.c \
put_first.c \
find.c \
find_parent.c \
delete.c
delete.c \
destroy.c
libqueue_la_CFLAGS = $(AM_CFLAGS)

46
src/queue/destroy.c

@ -0,0 +1,46 @@
/**
* \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 <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include "trbase.h"
#include "tr/queue.h"
void
TR_queueDestroy(TR_Queue this)
{
TR_Queue node = this->first;
while (NULL != node) {
TR_Queue next = node->next;
if (this->free_msgs) {
TR_delete(node->msg);
}
TR_delete(node);
node = next;
}
this->first = this->next = this->last = NULL;
this->nmsg = 0;
}
// vim: set ts=4 sw=4:

12
src/queue/queue.c

@ -40,17 +40,7 @@ static
void
queueDtor(void * _this)
{
TR_Queue this = _this;
TR_Queue node = this->first;
while (NULL != node) {
TR_Queue next = node->next;
if (this->free_msgs) {
TR_delete(node->msg);
}
TR_delete(node);
node = next;
}
TR_queueDestroy((TR_Queue)_this);
}
TR_INIT_IFACE(TR_Class, queueCtor, queueDtor, NULL);

Loading…
Cancel
Save