1 /*- 2 * Copyright (c) 2004 - 2011 CTPP Team 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 4. Neither the name of the CTPP Team nor the names of its contributors 13 * may be used to endorse or promote products derived from this software 14 * without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * CTPP2HashTable.hpp 29 * 30 * $CTPP$ 31 */ 32 #ifndef _CTPP2_HASH_TABLE_HPP__ 33 #define _CTPP2_HASH_TABLE_HPP__ 1 34 35 #include "CTPP2Types.h" 36 37 /** 38 @file CTPP2HashTable.hpp 39 @brief Zero collision hash 40 */ 41 42 namespace CTPP // C++ Template Engine 43 { 44 45 /** 46 @struct HashElement CTPP2HashTable.hpp <CTPP2HashTable.hpp> 47 @brief Static data variable 48 */ 49 struct HashElement 50 { 51 /** Hash value */ 52 UINT_64 hash; 53 /** Data length */ 54 UINT_64 value; 55 }; 56 57 /** 58 @class ReducedHashTable CTPP2HashTable.hpp <CTPP2HashTable.hpp> 59 @brief Hash without collisions with reduced functionality 60 */ 61 class CTPP2DECL ReducedHashTable 62 { 63 public: 64 /** 65 @brief Constructor 66 @param aIElements - hash elements 67 @param iIPower - number of elements 68 */ 69 ReducedHashTable(const HashElement * aIElements, 70 const UINT_32 iIPower); 71 72 /** 73 @brief Get value from hash 74 @param szKey - key name 75 @param iKeyLength - key length 76 @return >0 - if success, -1 - if any error occured 77 */ 78 UINT_64 Get(CCHAR_P szKey, 79 const UINT_32 iKeyLength) const; 80 81 /** 82 @brief Get hash size 83 */ 84 UINT_64 Size() const; 85 86 /** 87 @brief A destructor 88 */ 89 ~ReducedHashTable() throw(); 90 91 private: 92 friend class VMDumper; 93 94 // Does not exist 95 ReducedHashTable(const ReducedHashTable & oRhs); 96 97 // Does not exist 98 ReducedHashTable & operator=(const ReducedHashTable & oRhs); 99 100 /** Hash elements */ 101 const HashElement * aElements; 102 /** Power of 2 */ 103 UINT_32 iPower; 104 /** Base of hash */ 105 UINT_64 iBase; 106 }; 107 108 /** 109 @class HashTable CTPP2HashTable.hpp <CTPP2HashTable.hpp> 110 @brief Hash without collisions 111 */ 112 class CTPP2DECL HashTable 113 { 114 public: 115 /** 116 @brief Constructor 117 */ 118 HashTable(); 119 120 /** 121 @brief Get value from hash 122 @param szKey - key name 123 @param iKeyLength - key length 124 @return >0 - if success, -1 - if any error occured 125 */ 126 INT_64 Get(CCHAR_P szKey, 127 const UINT_32 iKeyLength) const; 128 129 /** 130 @brief Get hash size 131 */ 132 UINT_64 Size() const; 133 134 /** 135 @brief Put value into hash 136 @param szKey - key name 137 @param iKeyLength - key length 138 @param iValue - value to store 139 @return 0 - if success, -1 - if any error occured 140 */ 141 UINT_32 Put(CCHAR_P szKey, 142 const UINT_32 iKeyLength, 143 const UINT_64 iValue); 144 145 /** 146 @brief A destructor 147 */ 148 ~HashTable() throw(); 149 private: 150 friend class VMDumper; 151 152 // Does not exist 153 HashTable(const HashTable & oRhs); 154 155 // Does not exist 156 HashTable & operator=(const HashTable & oRhs); 157 158 /** Hash elements */ 159 HashElement * aElements; 160 /** Power of 2 */ 161 UINT_32 iPower; 162 /** Base of hash */ 163 UINT_64 iBase; 164 /** Number of used elements */ 165 UINT_64 iUsed; 166 167 /** 168 @brief Resize hash 169 */ 170 void Resize(); 171 }; 172 173 } // namespace CTPP 174 #endif // _CTPP2_HASH_TABLE_HPP__ 175 // End. 176