root/src/include/private/hashtable_itr.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. hashtable_iterator_key
  2. hashtable_iterator_value

   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 #ifdef __cplusplus
   9 extern "C" {
  10 #endif
  11 /*****************************************************************************/
  12 /* This struct is only concrete here to allow the inlining of two of the
  13  * accessor functions. */
  14 struct hashtable_itr
  15 {
  16     struct hashtable *h;
  17     struct entry *e;
  18     struct entry *parent;
  19     unsigned int index;
  20 };
  21 
  22 
  23 /*****************************************************************************/
  24 /* hashtable_iterator
  25  */
  26 
  27 struct hashtable_itr *
  28 hashtable_iterator(struct hashtable *h);
  29 
  30 /*****************************************************************************/
  31 /* hashtable_iterator_key
  32  * - return the value of the (key,value) pair at the current position */
  33 extern __inline__ void *
  34 hashtable_iterator_key(struct hashtable_itr *i);
  35 
  36 extern __inline__ void *
  37 hashtable_iterator_key(struct hashtable_itr *i)
  38 {
  39     return i->e->k;
  40 }
  41 
  42 /*****************************************************************************/
  43 /* value - return the value of the (key,value) pair at the current position */
  44 
  45 extern __inline__ void *
  46 hashtable_iterator_value(struct hashtable_itr *i);
  47 
  48 extern __inline__ void *
  49 hashtable_iterator_value(struct hashtable_itr *i)
  50 {
  51     return i->e->v;
  52 }
  53 
  54 /*****************************************************************************/
  55 /* advance - advance the iterator to the next element
  56  *           returns zero if advanced to end of table */
  57 
  58 int
  59 hashtable_iterator_advance(struct hashtable_itr *itr);
  60 
  61 /*****************************************************************************/
  62 /* remove - remove current element and advance the iterator to the next element
  63  *          NB: if you need the value to free it, read it before
  64  *          removing. ie: beware memory leaks!
  65  *          returns zero if advanced to end of table */
  66 
  67 int
  68 hashtable_iterator_remove(struct hashtable_itr *itr);
  69 
  70 /*****************************************************************************/
  71 /* search - overwrite the supplied iterator, to point to the entry
  72  *          matching the supplied key.
  73  h points to the hashtable to be searched.
  74  *          returns zero if not found. */
  75 int
  76 hashtable_iterator_search(struct hashtable_itr *itr,
  77                           struct hashtable *h, void *k);
  78 
  79 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype)                               \
  80         int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
  81         {                                                                                                                                       \
  82                 return (hashtable_iterator_search(i,h,k));                                              \
  83         }
  84 
  85 #ifdef __cplusplus
  86 }
  87 #endif
  88 
  89 #endif /* __HASHTABLE_ITR_CWC22__*/
  90 
  91 /*
  92  * Copyright (c) 2002, 2004, Christopher Clark
  93  * All rights reserved.
  94  * 
  95  * Redistribution and use in source and binary forms, with or without
  96  * modification, are permitted provided that the following conditions
  97  * are met:
  98  * 
  99  * * Redistributions of source code must retain the above copyright
 100  * notice, this list of conditions and the following disclaimer.
 101  * 
 102  * * Redistributions in binary form must reproduce the above copyright
 103  * notice, this list of conditions and the following disclaimer in the
 104  * documentation and/or other materials provided with the distribution.
 105  * 
 106  * * Neither the name of the original author; nor the names of any contributors
 107  * may be used to endorse or promote products derived from this software
 108  * without specific prior written permission.
 109  * 
 110  * 
 111  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 112  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 113  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 114  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
 115  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 116  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 117  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 118  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 119  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 120  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 121  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 122  */
 123 
 124 /* For Emacs:
 125  * Local Variables:
 126  * mode:c
 127  * indent-tabs-mode:t
 128  * tab-width:4
 129  * c-basic-offset:4
 130  * End:
 131  * For VIM:
 132  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 133  */
 134 

/* [<][>][^][v][top][bottom][index][help] */