00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00039 #ifndef __NUSMV_CORE_UTILS_LRUCACHE_H__
00040 #define __NUSMV_CORE_UTILS_LRUCACHE_H__
00041
00042
00043 #include "nusmv/core/utils/utils.h"
00044 #include "nusmv/core/utils/OAHash.h"
00045
00052 typedef struct LRUCache_TAG* LRUCache_ptr;
00053
00059 typedef OAHashIter LRUCacheIter;
00060
00061
00062
00068 typedef OA_HASH_EQ_FUN LRU_CACHE_EQ_FUN;
00069
00075 typedef OA_HASH_HASH_FUN LRU_CACHE_HASH_FUN;
00076
00082 typedef OA_HASH_FREE_FUN LRU_CACHE_FREE_FUN;
00083
00090 #define LRU_CACHE(self) \
00091 ((LRUCache_ptr) self)
00092
00098 #define LRU_CACHE_CHECK_INSTANCE(self) \
00099 (nusmv_assert(LRU_CACHE(self) != LRU_CACHE(NULL)))
00100
00106 #define LRU_CACHE_FOREACH(self, iter) \
00107 for (iter = LRUCache_get_first_iter(self); \
00108 !LRUCache_iter_is_end(self, iter); \
00109 iter = LRUCache_iter_next(self, iter))
00110
00116 #define LRU_CACHE_FOREACH_ENTRY(self, iter, key, value) \
00117 for (iter = LRUCache_get_first_iter(self); \
00118 !LRUCache_iter_is_end(self, iter) && \
00119 (LRUCache_iter_values(self, iter, (void**)key, (void**)value), true); \
00120 iter = LRUCache_iter_next(self, iter))
00121
00122
00123
00124
00125
00126
00127
00133 #define LRUCache_has_key(self, key) \
00134 OAHash_has_key(OA_HASH(self), key)
00135
00136
00137
00143 #define LRUCache_get_first_iter(self) \
00144 OAHash_get_first_iter(OA_HASH(self))
00145
00146
00147
00148
00154 #define LRUCache_iter_next(self, iter) \
00155 OAHash_iter_next(OA_HASH(self), (OAHashIter)iter)
00156
00157
00158
00159
00165 #define LRUCache_iter_is_end(self, iter) \
00166 OAHash_iter_is_end(OA_HASH(self), (OAHashIter)iter)
00167
00168
00169
00175 #define LRUCache_get_size(self) \
00176 OAHash_get_size(OA_HASH(self))
00177
00180
00181
00182
00183
00198 LRUCache_ptr LRUCache_create(size_t threshold,
00199 LRU_CACHE_EQ_FUN key_eq_fun,
00200 LRU_CACHE_HASH_FUN key_hash_fun,
00201 LRU_CACHE_FREE_FUN free_entry_fun,
00202 void* custom_arg);
00203
00212 void LRUCache_destroy(LRUCache_ptr self);
00213
00222 void* LRUCache_lookup(LRUCache_ptr self, const void* key);
00223
00232 boolean LRUCache_insert(LRUCache_ptr self,
00233 const void* key, const void* value);
00234
00243 boolean LRUCache_remove(LRUCache_ptr self, const void* key);
00244
00251 void LRUCache_clear(LRUCache_ptr self);
00252
00262 void LRUCache_iter_values(const LRUCache_ptr self,
00263 const LRUCacheIter iter,
00264 void** k, void** v);
00265
00270 #endif