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, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 */ 25 26 #ifndef KEY_TABLE2_HPP 27 #define KEY_TABLE2_HPP 28 29 #include <DLHashTable2.hpp> 30 31 /** 32 * KeyTable2 is DLHashTable2 with hardcoded Uint32 key named "key". 33 */ 34 template <class T, class U> 35 class KeyTable2 : public DLHashTable2<T, U> { 36 public: KeyTable2(ArrayPool<U> & pool)37 KeyTable2(ArrayPool<U>& pool) : 38 DLHashTable2<T, U>(pool) { 39 } 40 find(Ptr<T> & ptr,const T & rec) const41 bool find(Ptr<T>& ptr, const T& rec) const { 42 return DLHashTable2<T, U>::find(ptr, rec); 43 } 44 find(Ptr<T> & ptr,Uint32 key) const45 bool find(Ptr<T>& ptr, Uint32 key) const { 46 T rec; 47 rec.key = key; 48 return DLHashTable2<T, U>::find(ptr, rec); 49 } 50 }; 51 52 template <class T, class U> 53 class KeyTable2C : public KeyTable2<T, U> { 54 Uint32 m_count; 55 public: KeyTable2C(ArrayPool<U> & pool)56 KeyTable2C(ArrayPool<U>& pool) : 57 KeyTable2<T, U>(pool), m_count(0) { 58 } 59 get_count() const60 Uint32 get_count() const { return m_count; } 61 seize(Ptr<T> & ptr)62 bool seize(Ptr<T> & ptr) { 63 if (KeyTable2<T, U>::seize(ptr)) 64 { 65 m_count ++; 66 return true; 67 } 68 return false; 69 } 70 add(Ptr<T> & ptr)71 void add(Ptr<T> & ptr) { 72 KeyTable2<T, U>::add(ptr); 73 m_count ++; 74 } 75 remove(Ptr<T> & ptr,const T & key)76 void remove(Ptr<T> & ptr, const T & key) { 77 KeyTable2<T, U>::remove(ptr, key); 78 if (ptr.i != RNIL) 79 { 80 assert(m_count); 81 m_count --; 82 } 83 } 84 remove(Uint32 i)85 void remove(Uint32 i) { 86 KeyTable2<T, U>::remove(i); 87 assert(m_count); 88 m_count --; 89 } 90 remove(Ptr<T> & ptr)91 void remove(Ptr<T> & ptr) { 92 KeyTable2<T, U>::remove(ptr); 93 assert(m_count); 94 m_count --; 95 } 96 removeAll()97 void removeAll() { 98 KeyTable2<T, U>::removeAll(); 99 m_count = 0; 100 } 101 release(Ptr<T> & ptr,const T & key)102 void release(Ptr<T> & ptr, const T & key) { 103 KeyTable2<T, U>::release(ptr, key); 104 if (ptr.i != RNIL) 105 { 106 assert(m_count); 107 m_count --; 108 } 109 } 110 release(Uint32 i)111 void release(Uint32 i) { 112 KeyTable2<T, U>::release(i); 113 assert(m_count); 114 m_count --; 115 } 116 release(Ptr<T> & ptr)117 void release(Ptr<T> & ptr) { 118 KeyTable2<T, U>::release(ptr); 119 assert(m_count); 120 m_count --; 121 } 122 }; 123 124 #endif 125