source: releases/0.11.0/include/lru_cache.h @ 165

Last change on this file since 165 was 147, checked in by tim, 16 years ago

added talloc library

incorporated talloc into winsec and lru_cache modules

introduced talloc into SK caching system

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/*
2 * Copyright (C) 2008-2009 Timothy D. Morgan
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
16 *
17 * $Id: lru_cache.h 147 2009-02-22 19:31:52Z tim $
18 */
19
20#ifndef LRU_CACHE_H
21#define LRU_CACHE_H
22
23#include <stdbool.h>
24#include <stdint.h>
25#include <stdlib.h>
26#include <stdio.h>
27#include <string.h>
28#include <unistd.h>
29#include "talloc.h"
30
31struct lru_cache_element;
32typedef struct lru_cache_element lru_cache_element; 
33
34struct lru_cache_element
35{
36  void* index;
37  uint32_t index_len;
38  void* data;
39  lru_cache_element* next;
40  lru_cache_element* older;
41  lru_cache_element* newer;
42};
43
44typedef struct _lru_cache
45{
46  uint32_t secret;
47  uint32_t num_keys;
48  uint32_t num_buckets;
49  uint32_t max_keys;
50  lru_cache_element* oldest;
51  lru_cache_element* newest;
52  lru_cache_element** table;
53  bool talloc_data;
54} lru_cache;
55
56
57lru_cache* lru_cache_create(uint32_t max_keys, uint32_t secret);
58lru_cache* lru_cache_create_ctx(void* talloc_ctx, uint32_t max_keys, 
59                                uint32_t secret, bool talloc_data);
60void lru_cache_destroy(lru_cache* ht);
61
62/*
63 *
64 */
65bool lru_cache_update(lru_cache* ht, const void* index, 
66                      uint32_t index_len, void* data);
67
68/* Returns pointer to data previously stored at index.
69 * If no data was found at index, NULL is returned.
70 */
71void* lru_cache_find(lru_cache* ht, const void* index, 
72                     uint32_t index_len);
73
74/* Removes entry from table at index.
75 * Returns pointer to data that was there previously. 
76 * Returns NULL if no entry is at index.
77 */
78bool lru_cache_remove(lru_cache* ht, const void* index, 
79                      uint32_t index_len);
80
81#endif
Note: See TracBrowser for help on using the repository browser.