This is FunctionCache.h in view mode; [Download] [Up]
/*
File FunctionCache.h
A cache remembers function values, f(x) = y, so that function evaluations can avoid lengthy recomputations. Each cache has a finite capacity. When a new value is added to the cache, the cache discards the value that has gone unused for the longest period of time. It uses a callback function to alert the application that a value is being discarded. In this way memory can be freed and reclaimed for other uses.
*/
#import <objc/Object.h>
#import <objc/HashTable.h>
/* 行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行 */
#define ISASTRING 0
#define ISAOBJECT 1
typedef void (* freeFunction)(void *);
typedef struct cacheElement {
void * key, * value;
struct cacheElement * previous, * next;
int utility;
} cacheElement;
/* 行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行行 */
@interface FunctionCache:Object
{
HashTable * cache;
cacheElement * worst, * best;
unsigned capacity;
freeFunction freeKey, freeValue;
}
- initKey: (const char *) key
value: (const char *) value
capacity: (unsigned) theCapacity
freeKey: (freeFunction) theFreeKey
freeValue: (freeFunction) theFreeValue;
- initKeyType: (int) key valueType: (int) value capacity: (unsigned) theCapacity;
- setCapacity: (unsigned) theCapacity;
- add: (void *) key value: (void *) value;
- remove: (void *) key;
- (void *) find: (void *) key;
- (cacheElement *) detach: (cacheElement *) cell;
- release: (cacheElement *) cell;
@endThese are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.