"Fossies" - the Fresh Open Source Software Archive

Member "FunctionCheck-3.2.0/src/fcmanager/fc_xlhash.h" (26 May 2012, 3574 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_xlhash_h_
   22 #define __fc_xlhash_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_LHASH_DEPTH 8
   38 
   39 typedef struct _FC_LHNode FC_LHNode;
   40 struct _FC_LHNode
   41 {
   42   /* storage for the used key */
   43   unsigned long long key;
   44 
   45   /* local data stored for the user */
   46   int  value;
   47   void *ptr1;
   48   void *ptr2;
   49   
   50   FC_LHNode *next;
   51   FC_LHNode *fnext;
   52 };
   53 
   54 /* structure of a hash-table */
   55 #define FC_LHASH_MAX_ADD 32
   56 typedef struct
   57 {
   58   int size;  /* current size of the hash-table */
   59   int nb;    /* number of elements in the hash-table */
   60   FC_LHNode **nodes; /* list of entries */
   61   FC_LHNode *rnodes; /* list of nodes */
   62   FC_LHNode *add_rnodes[FC_LHASH_MAX_ADD]; /* additionnal list of nodes */
   63   int nb_add_rnodes;/* position in additionnal list */
   64   int nb_rnodes;    /* used entries */
   65   int max_rnodes;   /* size */
   66   FC_LHNode *free_entry;   /* next free entry */
   67   int frozen;       /* maw size reached, do not resize */
   68 } FC_LHash;
   69 
   70 /* a function to apply to each elements */
   71 typedef void (*FC_LHFunc)(unsigned long long key, int val, void *ptr1, void *ptr2, void *data);
   72 
   73 /* create a hash-table */
   74 FC_LHash *fc_lhash_new(void);
   75 
   76 /* destroy a hash-table */
   77 void fc_lhash_destroy(FC_LHash *hash);
   78 
   79 /* insert an element in a hash-table */
   80 void fc_lhash_insert(FC_LHash *hash, unsigned long long key,
   81                      int val, void *ptr1, void *ptr2);
   82 
   83 /* search an element in a hash-table */
   84 int fc_lhash_lookup(FC_LHash *hash, unsigned long long key,
   85                     int *val, void **ptr1, void **ptr2);
   86 
   87 /* (!) search an element in a hash-table and return pointers
   88    on the entries (in order to modify their values without
   89    having to remove/modify/insert.
   90    WARNING: these pointers are only valid until you perfom
   91             an other action on this hash-table. after any
   92         operation they may become invalid */
   93 int fc_lhash_lookup_modify(FC_LHash *hash, unsigned long long key,
   94                            int **val, void ***ptr1, void ***ptr2);
   95 
   96 /* remove an element from a hash-table */
   97 void fc_lhash_remove(FC_LHash *hash, unsigned long long key);
   98 
   99 /* apply a function to each elements of the hash-table */
  100 void fc_lhash_foreach(FC_LHash *hash, FC_LHFunc func, void *data);
  101 
  102 /* get the number of elements in the hash-table */
  103 int fc_lhash_size(FC_LHash *hash);
  104 
  105 /* for debug purpose. prints the internal data inside the hash-table */
  106 void fc_lhash_debug(FC_LHash *hash);
  107 
  108 #endif /* __fc_xhash_h_ */
  109