src/cache.h

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

FUNCTIONS

This source file includes following functions.

   1 /*
   2  * cache.h - a header for cache module 
   3  * by Hirotsugu Kakugawa
   4  *   5 Aug 1996
   5  */
   6 /*
   7  * Copyright (C) 1996, 1997 Hirotsugu Kakugawa. 
   8  * All rights reserved.
   9  *
  10  * This file is part of the VFlib Library.  This library is free
  11  * software; you can redistribute it and/or modify it under the terms of
  12  * the GNU Library General Public License as published by the Free
  13  * Software Foundation; either version 2 of the License, or (at your
  14  * option) any later version.  This library is distributed in the hope
  15  * that it will be useful, but WITHOUT ANY WARRANTY; without even the
  16  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  17  * PURPOSE.  See the GNU Library General Public License for more details.
  18  * You should have received a copy of the GNU Library General Public
  19  * License along with this library; if not, write to the Free Software
  20  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21  */
  22 
  23 #ifndef __VFLIB_CACHE_H__
  24 #define __VFLIB_CACHE_H__
  25 
  26 /* Cache Element */
  27 typedef struct s_vf_cache_elem  *VF_CACHE_ELEM;
  28 struct s_vf_cache_elem {
  29   void        *object;          /* cached object */
  30   void        *key;             /* element key */
  31   int         key_len;          /* key length */
  32   VF_CACHE_ELEM  l_forw, l_back; /* forw./backw. in LRU list */
  33   VF_CACHE_ELEM  h_forw, h_back; /* forw./backw. in hash table, free list*/
  34 };
  35 /* Cache */
  36 typedef struct s_vf_cache  *VF_CACHE;
  37 struct s_vf_cache {
  38   /* Public: common method */
  39   void    *(*get)(VF_CACHE,void*,int); 
  40   void    (*del)(VF_CACHE,void*,int); 
  41   /* Private: class dependent method */
  42   void    *(*load_elem)(VF_CACHE,void*,int);
  43   void    (*unload_elem)(void*);
  44   /* Private: internal data structure */
  45   int                  cache_size;
  46   int                  hash_size; 
  47   VF_CACHE_ELEM           hash_table;
  48   struct s_vf_cache_elem  lru_list;
  49   VF_CACHE_ELEM           free_list;
  50 };
  51 extern VF_CACHE vf_cache_create (int,int,
  52                                  void *(*load_func)(VF_CACHE,void*,int),
  53                                  void (*unload_func)(void*));
  54 
  55 /** HASH **/
  56 /* Hash Element */
  57 typedef struct s_vf_hash_elem  *VF_HASH_ELEM;
  58 struct s_vf_hash_elem {
  59   int         link_cnt;
  60   void        *object;          /* object */
  61   void        *key;             /* element key */
  62   int         key_len;          /* key length */
  63   VF_HASH_ELEM  h_forw, h_back; /* forw./backw. in hash table, free list*/
  64 };
  65 /* Hash */
  66 typedef struct s_vf_hash  *VF_HASH;
  67 struct s_vf_hash {
  68   /* Public: common method */
  69   void    *(*get)(VF_HASH,void*,int); 
  70   void    *(*put)(VF_HASH,void*,void*,int); 
  71   void    (*del)(VF_HASH,void*,int); 
  72   /* Private: internal data structure */
  73   int           hash_size; 
  74   VF_HASH_ELEM  table;
  75 };
  76 extern VF_HASH vf_hash_create (int);
  77 
  78 
  79 /** TABLE **/
  80 /* Table Element */
  81 typedef struct s_vf_table_elem  *VF_TABLE_ELEM;
  82 struct s_vf_table_elem {
  83   int         link_cnt;
  84   void        *object;     /* object */
  85   void        *key;        /* element key */
  86   int         key_len;     /* key length */
  87 };
  88 /* Table */
  89 typedef struct s_vf_table  *VF_TABLE;
  90 struct s_vf_table {
  91   /* Public: common method */
  92   int     (*put)(VF_TABLE,void*,void*,int); 
  93   int     (*put2)(VF_TABLE,void*,void*,int); 
  94   int     (*get_id_by_key)(VF_TABLE,void*,int); 
  95   int     (*get_id_by_obj)(VF_TABLE,void*); 
  96   void   *(*get_obj_by_id)(VF_TABLE,int); 
  97   void   *(*get_obj_by_key)(VF_TABLE,void*,int); 
  98   int     (*del_obj_by_id)(VF_TABLE,int); 
  99   int     (*del_obj_by_key)(VF_TABLE,void*,int); 
 100   int     (*link_by_id)(VF_TABLE,int); 
 101   int     (*unlink_by_id)(VF_TABLE,int); 
 102   int     (*get_nelements)(VF_TABLE); 
 103   /* Private: internal data */
 104   int            nelems;
 105   int            next_slot;
 106   int            table_size; 
 107   VF_TABLE_ELEM  table;
 108 };
 109 Glocal VF_TABLE  vf_table_create (void);
 110 
 111 #endif  /* __VFLIB_CACHE_H__ */
 112                                
 113 /*EOF*/

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