MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KeyTable2.hpp
1 /*
2  Copyright (C) 2003, 2005, 2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef KEY_TABLE2_HPP
20 #define KEY_TABLE2_HPP
21 
22 #include <DLHashTable2.hpp>
23 
27 template <class T, class U>
28 class KeyTable2 : public DLHashTable2<T, U> {
29 public:
30  KeyTable2(ArrayPool<U>& pool) :
31  DLHashTable2<T, U>(pool) {
32  }
33 
34  bool find(Ptr<T>& ptr, const T& rec) const {
35  return DLHashTable2<T, U>::find(ptr, rec);
36  }
37 
38  bool find(Ptr<T>& ptr, Uint32 key) const {
39  T rec;
40  rec.key = key;
41  return DLHashTable2<T, U>::find(ptr, rec);
42  }
43 };
44 
45 template <class T, class U>
46 class KeyTable2C : public KeyTable2<T, U> {
47  Uint32 m_count;
48 public:
49  KeyTable2C(ArrayPool<U>& pool) :
50  KeyTable2<T, U>(pool), m_count(0) {
51  }
52 
53  Uint32 get_count() const { return m_count; }
54 
55  bool seize(Ptr<T> & ptr) {
56  if (KeyTable2<T, U>::seize(ptr))
57  {
58  m_count ++;
59  return true;
60  }
61  return false;
62  }
63 
64  void add(Ptr<T> & ptr) {
66  m_count ++;
67  }
68 
69  void remove(Ptr<T> & ptr, const T & key) {
70  KeyTable2<T, U>::remove(ptr, key);
71  if (ptr.i != RNIL)
72  {
73  assert(m_count);
74  m_count --;
75  }
76  }
77 
78  void remove(Uint32 i) {
80  assert(m_count);
81  m_count --;
82  }
83 
84  void remove(Ptr<T> & ptr) {
86  assert(m_count);
87  m_count --;
88  }
89 
90  void removeAll() {
92  m_count = 0;
93  }
94 
95  void release(Ptr<T> & ptr, const T & key) {
96  KeyTable2<T, U>::release(ptr, key);
97  if (ptr.i != RNIL)
98  {
99  assert(m_count);
100  m_count --;
101  }
102  }
103 
104  void release(Uint32 i) {
106  assert(m_count);
107  m_count --;
108  }
109 
110  void release(Ptr<T> & ptr) {
112  assert(m_count);
113  m_count --;
114  }
115 };
116 
117 #endif