Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Cache_Hash_T.h
blobf80db70776d9c4b569fdcd867ee8c51da984b822
1 /* -*- c++ -*- */
2 #ifndef JAWS_CACHE_HASH_T_H
3 #define JAWS_CACHE_HASH_T_H
5 #include "JAWS/Cache_Object.h"
7 // Forward declaration
8 template <class EXT_ID, class INT_ID, class EQ_FUNC>
9 class JAWS_Hash_Bucket_Manager;
11 template <class EXT_ID, class HASH_FUNC, class EQ_FUNC>
12 class JAWS_Cache_Hash
14 public:
16 typedef JAWS_Hash_Bucket_Manager<EXT_ID, JAWS_Cache_Object *, EQ_FUNC>
17 CACHE_BUCKET_MANAGER;
19 JAWS_Cache_Hash (ACE_Allocator *alloc = 0, size_t size = 521);
20 // 521 == smallest number > 512 that is prime. Why is a prime
21 // number important? I am trying to maximize scattering when using
22 // mod on the hashed value. This might be bogus though.
24 virtual ~JAWS_Cache_Hash (void);
26 int find (const EXT_ID &ext_id) const;
27 int find (const EXT_ID &ext_id, JAWS_Cache_Object *&int_id) const;
28 int bind (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
29 int trybind (const EXT_ID &ext_id, JAWS_Cache_Object *&int_id);
30 int rebind (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id,
31 EXT_ID &old_ext_id, JAWS_Cache_Object *&old_int_id);
33 int unbind (const EXT_ID &ext_id);
34 int unbind (const EXT_ID &ext_id, JAWS_Cache_Object *&int_id);
36 size_t size (void) const;
38 protected:
40 virtual unsigned long hash (const EXT_ID &ext_id) const;
41 bool isprime (size_t number) const;
42 int new_cachebucket (size_t idx);
44 private:
46 ACE_Allocator *allocator_;
47 size_t size_;
49 ACE_SYNCH_MUTEX lock_;
50 CACHE_BUCKET_MANAGER **hashtable_;
54 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
55 #include "JAWS/Cache_Hash_T.cpp"
56 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
58 #endif /* ACE_CACHE_HASH_T_H */