File: Cache_Hash_T.h

package info (click to toggle)
ace 6.0.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,368 kB
  • sloc: cpp: 341,826; perl: 30,850; ansic: 20,952; makefile: 10,144; sh: 4,744; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; csh: 48; tcl: 5
file content (60 lines) | stat: -rw-r--r-- 1,709 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* -*- c++ -*- */
// $Id: Cache_Hash_T.h 81993 2008-06-16 20:26:16Z sowayaa $

#ifndef JAWS_CACHE_HASH_T_H
#define JAWS_CACHE_HASH_T_H

#include "JAWS/Cache_Object.h"

// Forward declaration
template <class EXT_ID, class INT_ID, class EQ_FUNC>
class JAWS_Hash_Bucket_Manager;

template <class EXT_ID, class HASH_FUNC, class EQ_FUNC>
class JAWS_Cache_Hash
{
public:

  typedef JAWS_Hash_Bucket_Manager<EXT_ID, JAWS_Cache_Object *, EQ_FUNC>
          CACHE_BUCKET_MANAGER;

  JAWS_Cache_Hash (ACE_Allocator *alloc = 0, size_t size = 521);
  // 521 == smallest number > 512 that is prime.  Why is a prime
  // number important?  I am trying to maximize scattering when using
  // mod on the hashed value.  This might be bogus though.

  virtual ~JAWS_Cache_Hash (void);

  int find (const EXT_ID &ext_id) const;
  int find (const EXT_ID &ext_id, JAWS_Cache_Object *&int_id) const;
  int bind (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
  int trybind (const EXT_ID &ext_id, JAWS_Cache_Object *&int_id);
  int rebind (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id,
              EXT_ID &old_ext_id, JAWS_Cache_Object *&old_int_id);

  int unbind (const EXT_ID &ext_id);
  int unbind (const EXT_ID &ext_id, JAWS_Cache_Object *&int_id);

  size_t size (void) const;

protected:

  virtual unsigned long hash (const EXT_ID &ext_id) const;
  int isprime (unsigned long number) const;
  int new_cachebucket (size_t idx);

private:

  ACE_Allocator *allocator_;
  size_t size_;

  ACE_SYNCH_MUTEX lock_;
  CACHE_BUCKET_MANAGER **hashtable_;

};

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "JAWS/Cache_Hash_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#endif /* ACE_CACHE_HASH_T_H */