regfi
lru_cache.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008-2010 Timothy D. Morgan
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; version 3 of the License.
00007  * 
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
00016  *
00017  * $Id: lru_cache.h 253 2011-06-13 02:27:42Z tim $
00018  */
00019 
00028 #ifndef LRU_CACHE_H
00029 #define LRU_CACHE_H
00030 
00031 #include <stdbool.h>
00032 #include <stdint.h>
00033 #include <stdlib.h>
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include <unistd.h>
00037 #include <talloc.h>
00038 
00039 #include "compat.h"
00040 
00041 
00042 struct lru_cache_element;
00043 typedef struct lru_cache_element lru_cache_element; 
00044 
00045 struct lru_cache_element
00046 {
00047   void* index;
00048   uint32_t index_len;
00049   void* data;
00050   lru_cache_element* next;
00051   lru_cache_element* older;
00052   lru_cache_element* newer;
00053 };
00054 
00055 
00057 typedef struct _lru_cache
00058 {
00059   uint32_t secret;
00060   uint32_t num_keys;
00061   uint32_t num_buckets;
00062   uint32_t max_keys;
00063   lru_cache_element* oldest;
00064   lru_cache_element* newest;
00065   lru_cache_element** table;
00066   bool talloc_data;
00067 } lru_cache;
00068 
00069 
00073 _EXPORT()
00074 lru_cache* lru_cache_create(uint32_t max_keys, uint32_t secret);
00075 
00076 
00080 _EXPORT()
00081 lru_cache* lru_cache_create_ctx(void* talloc_ctx, uint32_t max_keys, 
00082                                 uint32_t secret, bool talloc_data);
00083 
00084 
00088 _EXPORT()
00089 void lru_cache_destroy(lru_cache* ht);
00090 
00091 
00095 _EXPORT()
00096 bool lru_cache_update(lru_cache* ht, const void* index, 
00097                       uint32_t index_len, void* data);
00098 
00105 _EXPORT()
00106 void* lru_cache_find(lru_cache* ht, const void* index, 
00107                      uint32_t index_len);
00108 
00117 _EXPORT()
00118 bool lru_cache_remove(lru_cache* ht, const void* index, 
00119                       uint32_t index_len);
00120 
00121 #endif
 All Data Structures Files Functions Variables