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