"Fossies" - the Fresh Open Source Software Archive

Member "FunctionCheck-3.2.0/src/fcmanager/fc_xhash.h" (26 May 2012, 3473 Bytes) of package /linux/privat/old/FunctionCheck-3.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * FunctionCheck profiler
    3  * (C) Copyright 2000-2012 Yannick Perret
    4  * 
    5  *  This program is free software; you can redistribute it and/or
    6  *  modify it under the terms of the GNU General Public License as
    7  *  published by the Free Software Foundation; either version 2 of the
    8  *  License, or (at your option) any later version.
    9  *
   10  *  This program is distributed in the hope that it will be useful,
   11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13  *  General Public License for more details.
   14  *
   15  *  You should have received a copy of the GNU General Public License
   16  *  along with this program; if not, write to the Free Software
   17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18  */
   19 /** fc_xhash.h: all functions for hash-tables **/
   20 
   21 #ifndef __fc_xhash_h_
   22 #define __fc_xhash_h_
   23 
   24 /*
   25    Notes:
   26      this is a particular kind of hash-table. when removing
   27      elements the size of the hash-table is never reduced.
   28      
   29      access to an element cost between 1 and 8 memory access
   30      (regardless the overcost in case of hash-table resizing)
   31 */
   32 
   33 #include <stdio.h>
   34 #include <stdlib.h>
   35 
   36 /* structure of entries in a hash-table */
   37 #define FC_HASH_DEPTH 8
   38 
   39 typedef struct _FC_HNode FC_HNode;
   40 
   41 struct _FC_HNode
   42 {
   43   /* storage for the used key (for resize) */
   44   void *key;
   45 
   46   /* local data stored for the user */
   47   int  value;
   48   void *ptr1;
   49   void *ptr2;
   50   
   51   FC_HNode *next;
   52   FC_HNode *fnext;
   53 };
   54 
   55 /* structure of a hash-table */
   56 #define FC_HASH_MAX_ADD 32
   57 
   58 typedef struct
   59 {
   60   int size;  /* current size of the hash-table */
   61   int nb;    /* number of elements in the hash-table */
   62   FC_HNode **nodes; /* list of entries */
   63   FC_HNode *rnodes; /* list of nodes */
   64   FC_HNode *add_rnodes[FC_HASH_MAX_ADD]; /* additionnal list of nodes */
   65   int nb_add_rnodes;/* position in additionnal list */
   66   int nb_rnodes;    /* used entries */
   67   int max_rnodes;   /* size */
   68   FC_HNode *free_entry;   /* next free entry */
   69   int frozen;       /* maw size reached, do not resize */
   70 } FC_Hash;
   71 
   72 /* a function to apply to each elements */
   73 typedef void (*FC_HFunc)(void *key, int val, void *ptr1, void *ptr2, void *data);
   74 
   75 /* create a hash-table */
   76 FC_Hash *fc_hash_new(void);
   77 
   78 /* destroy a hash-table */
   79 void fc_hash_destroy(FC_Hash *hash);
   80 
   81 /* insert an element in a hash-table */
   82 void fc_hash_insert(FC_Hash *hash, void *key,
   83                     int val, void *ptr1, void *ptr2);
   84 
   85 /* search an element in a hash-table */
   86 int fc_hash_lookup(FC_Hash *hash, void *key,
   87                    int *val, void **ptr1, void **ptr2);
   88 
   89 /* (!) search an element in a hash-table and return pointers
   90    on the entries (in order to modify their values without
   91    having to remove/modify/insert.
   92    WARNING: these pointers are only valid until you perfom
   93             an other action on this hash-table. after any
   94         operation they may become invalid */
   95 int fc_hash_lookup_modify(FC_Hash *hash, void *key,
   96                           int **val, void ***ptr1, void ***ptr2);
   97 
   98 /* remove an element from a hash-table */
   99 void fc_hash_remove(FC_Hash *hash, void *key);
  100 
  101 /* apply a function to each elements of the hash-table */
  102 void fc_hash_foreach(FC_Hash *hash, FC_HFunc func, void *data);
  103 
  104 /* get the number of elements in the hash-table */
  105 int fc_hash_size(FC_Hash *hash);
  106 
  107 /* for debug purpose. prints the internal data inside the hash-table */
  108 void fc_hash_debug(FC_Hash *hash);
  109 
  110 #endif /* __fc_xhash_h_ */
  111