1 /* Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */ 2 3 #ifndef __HASHTABLE_ITR_CWC22__ 4 #define __HASHTABLE_ITR_CWC22__ 5 #include "hashtable.h" 6 #include "hashtable_private.h" /* needed to enable inlining */ 7 8 struct hashtable_itr; 9 10 /*****************************************************************************/ 11 /* hashtable_iterator 12 */ 13 14 struct hashtable_itr * 15 hashtable_iterator(struct hashtable *h); 16 17 /*****************************************************************************/ 18 /* hashtable_iterator_key 19 * - return the value of the (key,value) pair at the current position */ 20 21 void * 22 hashtable_iterator_key(struct hashtable_itr *i); 23 24 /*****************************************************************************/ 25 /* value - return the value of the (key,value) pair at the current position */ 26 27 void * 28 hashtable_iterator_value(struct hashtable_itr *i); 29 30 /*****************************************************************************/ 31 /* advance - advance the iterator to the next element 32 * returns zero if advanced to end of table */ 33 34 int 35 hashtable_iterator_advance(struct hashtable_itr *itr); 36 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 */ 42 43 int 44 hashtable_iterator_remove(struct hashtable_itr *itr); 45 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. */ 51 int 52 hashtable_iterator_search(struct hashtable_itr *itr, 53 struct hashtable *h, void *k); 54 55 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ 56 int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ 57 { \ 58 return (hashtable_iterator_search(i,h,k)); \ 59 } 60 61 62 63 #endif /* __HASHTABLE_ITR_CWC22__*/ 64 65 /* 66 * Copyright (c) 2002, 2004, Christopher Clark 67 * All rights reserved. 68 * 69 * Redistribution and use in source and binary forms, with or without 70 * modification, are permitted provided that the following conditions 71 * are met: 72 * 73 * * Redistributions of source code must retain the above copyright 74 * notice, this list of conditions and the following disclaimer. 75 * 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. 79 * 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. 83 * 84 * 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. 96 */ 97