source: trunk/include/lru_cache.h @ 168

Last change on this file since 168 was 168, checked in by tim, 14 years ago

merged remaining smb_deps items into regfi

began formatting API comments for use with doxygen

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