1 
2 /* Web Polygraph       http://www.web-polygraph.org/
3  * Copyright 2003-2011 The Measurement Factory
4  * Licensed under the Apache License, Version 2.0 */
5 
6 #ifndef POLYGRAPH__CACHE_CACHEENTRYHASH_H
7 #define POLYGRAPH__CACHE_CACHEENTRYHASH_H
8 
9 #include "base/ObjId.h"
10 
11 class CacheEntry;
12 
13 // a hash for cache entries
14 // we would use a "generic" hash, but its implementation via
15 // templates is probably way to ugly and/or inefficient
16 
17 class CacheEntryHash {
18 	public:
19 		typedef CacheEntry **Loc; // an address returned by find() and used in []
20 
21 	public:
22 		CacheEntryHash(int aCapacity); // cap may be adjusted a bit
23 		~CacheEntryHash();             // no garbage collection
24 
capacity()25 		int capacity() const { return theCapacity; }
count()26 		int count() const { return theCount; }
27 
28 		bool find(const ObjId &id, Loc &loc) const;
29 		void add(CacheEntry *entry);
30 
31 		void addAt(Loc idx, CacheEntry *entry);
32 		CacheEntry *delAt(Loc idx);
33 
34 	protected:
35 		Loc theIndex;       // hash (stores pointers to real items)
36 		int theCapacity;    // hash capacity (in 1st level slots)
37 		int theCount;       // entries in the hash
38 };
39 
40 #endif
41