1
/* Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
3
#ifndef __HASHTABLE_ITR_CWC22__
4
#define __HASHTABLE_ITR_CWC22__
6
#include "hashtable_private.h" /* needed to enable inlining */
10
/*****************************************************************************/
14
struct hashtable_itr *
15
hashtable_iterator(struct hashtable *h);
17
/*****************************************************************************/
18
/* hashtable_iterator_key
19
* - return the value of the (key,value) pair at the current position */
22
hashtable_iterator_key(struct hashtable_itr *i);
24
/*****************************************************************************/
25
/* value - return the value of the (key,value) pair at the current position */
28
hashtable_iterator_value(struct hashtable_itr *i);
30
/*****************************************************************************/
31
/* advance - advance the iterator to the next element
32
* returns zero if advanced to end of table */
35
hashtable_iterator_advance(struct hashtable_itr *itr);
37
/*****************************************************************************/
38
/* remove - remove current element and advance the iterator to the next element
39
* NB: if you need the value to free it, read it before
40
* removing. ie: beware memory leaks!
41
* returns zero if advanced to end of table */
44
hashtable_iterator_remove(struct hashtable_itr *itr);
46
/*****************************************************************************/
47
/* search - overwrite the supplied iterator, to point to the entry
48
* matching the supplied key.
49
h points to the hashtable to be searched.
50
* returns zero if not found. */
52
hashtable_iterator_search(struct hashtable_itr *itr,
53
struct hashtable *h, void *k);
55
#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
56
int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
58
return (hashtable_iterator_search(i,h,k)); \
63
#endif /* __HASHTABLE_ITR_CWC22__*/
66
* Copyright (c) 2002, 2004, Christopher Clark
67
* All rights reserved.
69
* Redistribution and use in source and binary forms, with or without
70
* modification, are permitted provided that the following conditions
73
* * Redistributions of source code must retain the above copyright
74
* notice, this list of conditions and the following disclaimer.
76
* * Redistributions in binary form must reproduce the above copyright
77
* notice, this list of conditions and the following disclaimer in the
78
* documentation and/or other materials provided with the distribution.
80
* * Neither the name of the original author; nor the names of any contributors
81
* may be used to endorse or promote products derived from this software
82
* without specific prior written permission.
85
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
86
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
87
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
88
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
89
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
91
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
92
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
93
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
94
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
95
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.