📄 cache.h
字号:
#ifndef _cache_h_#define _cache_h_/* * ASCEND: @(#)cache.h 1.0 (95/10/05 00:55:30) * * Copyright (c) 1994 Ascend Communications, Inc. * All rights reserved. * * Permission to copy all or part of this material for any purpose is * granted provided that the above copyright notice and this paragraph * are duplicated in all copies. THIS SOFTWARE IS PROVIDED ``AS IS'' * AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * static char rcsid[] = "$Id: cache.h,v 1.1.1.1 2001/08/10 20:49:27 bonze Exp $"; * */#if !defined(TRUE)#define TRUE 1#endif#if !defined(FALSE)#define FALSE 0#endif#if !defined(MIN)#define MIN(x, y) (((x) < (y)) ? (x) : (y))#endif#if !defined(MAX)#define MAX(x, y) (((x) > (y)) ? (x) : (y))#endif#define MAX_KEY_LEN 16#define MAX_VAL_LEN 16/* * BUCKETS should be prime; try 1021, 2039, 4093, 8191, 16381. More buckets * use more statically allocated memory but decrease the length of the hash * lists, which will improve performance. */#define BUCKETS 4093typedef char HASHKEY;typedef char HASHVAL;#define ELEM_DELETED ((HASHVAL *)(-1))typedef struct HASHLIST{ struct HASHLIST *next; HASHKEY key[MAX_KEY_LEN + 1]; HASHVAL val[MAX_VAL_LEN + 1]; time_t time; int idling; /* Boolean: use idle time */ time_t idle;} HASHLIST;typedef struct CACHE{ int buckets; HASHLIST *table[BUCKETS];} CACHE;typedef enum CacheMsgType{ CACHE_INSERT = 1, CACHE_DELETE, CACHE_IDLE_UPDATE} CacheMsgType;typedef struct CacheMsg{ CacheMsgType type; HASHKEY key[MAX_KEY_LEN + 1]; HASHVAL val[MAX_VAL_LEN + 1]; time_t time; time_t idle;} CacheMsg;/***********************//* function prototypes *//***********************/u_short hash PROTO((CONST HASHKEY * key, int len, int buckets));int cache_init PROTO(());CONST HASHVAL * cache_search PROTO((CONST HASHKEY * key, int len));int cache_insert PROTO((CONST HASHKEY * key, int key_len, CONST HASHVAL * val, int val_len, time_t duration, time_t idle));int cache_delete PROTO((CONST HASHKEY * key, int len));void cache_expire PROTO(());int cache_idle_update PROTO((CONST HASHKEY * key, int len, time_t idle));#endif /* _cache_h_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -