Changeset 602
- Timestamp:
- 07/22/08 07:18:37 (4 months ago)
- Files:
-
- trunk/rphp/runtime/include/pHash.h (modified) (6 diffs)
- trunk/rphp/runtime/pHash.cpp (modified) (3 diffs)
- trunk/rphp/runtime/test/phashTestCase.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/runtime/include/pHash.h
r601 r602 34 34 // custom key type 35 35 namespace rphp { 36 typedef boost::variant< pInt, pBString,pUString > hKeyVar;37 typedef enum { hKeyInt, hKeyBStr,hKeyUStr } hKeyType;36 typedef boost::variant< pInt, /*pBString,*/ pUString > hKeyVar; 37 typedef enum { hKeyInt, /*hKeyBStr,*/ hKeyUStr } hKeyType; 38 38 } 39 39 … … 53 53 return static_cast<std::size_t>(k); 54 54 } 55 55 56 /* 56 57 std::size_t operator()(const pBString &k) const { 57 58 return boost::hash_value(k); 58 59 } 60 */ 59 61 60 62 std::size_t operator()(const pUString &k) const { … … 72 74 return hKeyInt; 73 75 } 74 76 77 /* 75 78 hKeyType operator()(const pBString &k) const { 76 79 return hKeyBStr; 77 80 } 81 */ 78 82 79 83 hKeyType operator()(const pUString &k) const { … … 91 95 h_container(const pUString k, pVarP d) : pData(d), key(k) { } 92 96 93 h_container(const pBString k, pVarP d) : pData(d), key(k) { }97 // h_container(const pBString k, pVarP d) : pData(d), key(k) { } 94 98 95 99 h_container(const pInt k, pVarP d) : pData(d), key(k) { } … … 138 142 // modifiers 139 143 void insert(const pUString &key, pVarP data); 144 //void insert(const pBString &key, pVarP data); 140 145 void insert(const pInt &key, pVarP data); 141 146 void insertNext(pVarP data); 147 148 size_type remove(const pUString &key); 149 //void remove(const pBString &key); 150 size_type remove(const pInt &key); 142 151 143 // size152 // queries 144 153 const size_type getSize() { return hashData.size(); } 154 const bool keyExists(const pUString &key); 155 //const bool keyExists(const pBString &key); 156 const bool keyExists(const pInt &key); 145 157 146 158 // dump of contents … … 148 160 149 161 // lookup 150 pVarP operator[] ( const pUString &key ) { 151 stableHash::iterator k = hashData.find(key); 152 if (k == hashData.end()) 153 return pVarP(); 154 else 155 return (*k).pData; 156 } 157 pVarP operator[] ( const pInt &key ) { 158 stableHash::iterator k = hashData.find(key); 159 if (k == hashData.end()) 160 return pVarP(); 161 else 162 return (*k).pData; 163 } 162 pVarP operator[] (const pUString &key); 163 //pVarP operator[] (const pBString &key); 164 pVarP operator[] (const pInt &key); 164 165 165 166 trunk/rphp/runtime/pHash.cpp
r599 r602 34 34 } 35 35 36 /* 37 void pHash::insert(const pBString &key, pVarP data) { 38 // TODO check numeric string, set maxIntKey accordingly 39 hashData.insert(h_container(key, data)); 40 } 41 */ 42 36 43 void pHash::insert(const pInt &key, pVarP data) { 37 44 if (key > maxIntKey) … … 43 50 hashData.insert(h_container(maxIntKey++, data)); 44 51 } 52 53 pHash::size_type pHash::remove(const pUString &key) { 54 return hashData.erase(key); 55 } 45 56 57 pHash::size_type pHash::remove(const pInt &key) { 58 return hashData.erase(key); 59 } 60 61 62 // query 63 const bool pHash::keyExists(const pUString &key) { 64 stableHash::iterator k = hashData.find(key); 65 return (k != hashData.end()); 66 } 67 /* 68 const bool pHash::keyExists(const pBString &key) { 69 stableHash::iterator k = hashData.find(key); 70 return (k != hashData.end()); 71 } 72 */ 73 const bool pHash::keyExists(const pInt &key) { 74 stableHash::iterator k = hashData.find(key); 75 return (k != hashData.end()); 76 } 77 78 // lookup 79 pVarP pHash::operator[] ( const pUString &key ) { 80 stableHash::iterator k = hashData.find(key); 81 if (k == hashData.end()) 82 return pVarP(); 83 else 84 return (*k).pData; 85 } 86 87 /* 88 pVarP pHash::operator[] ( const pBString &key ) { 89 stableHash::iterator k = hashData.find(key); 90 if (k == hashData.end()) 91 return pVarP(); 92 else 93 return (*k).pData; 94 } 95 */ 96 97 pVarP pHash::operator[] ( const pInt &key ) { 98 stableHash::iterator k = hashData.find(key); 99 if (k == hashData.end()) 100 return pVarP(); 101 else 102 return (*k).pData; 103 } 104 105 // output 106 std::ostream& operator << (std::ostream& os, const rphp::pHash& h) 107 { 108 return os << "php_hash:" << std::endl; 109 } 110 46 111 void pHash::varDump() { 47 112 … … 65 130 } 66 131 67 std::ostream& operator << (std::ostream& os, const rphp::pHash& h) 68 { 69 return os << "php_hash:" << std::endl; 70 } 71 132 72 133 } /* namespace rphp */ 73 134 trunk/rphp/runtime/test/phashTestCase.cpp
r600 r602 13 13 14 14 rphp::pVarP lu; 15 16 // ** INSERT ** 15 17 16 18 // string key … … 29 31 CPPUNIT_ASSERT( testHash.getSize() == 3 ); 30 32 31 // testHash.varDump();32 33 // ** LOOKUP ** 34 33 35 // string key 34 36 lu = testHash["var-test"]; … … 47 49 CPPUNIT_ASSERT( lu.get() == 0 ); 48 50 51 // ** REMOVE ** 52 rphp::pHash::size_type rc = testHash.remove("var-test"); 53 CPPUNIT_ASSERT( rc == 1 ); 54 CPPUNIT_ASSERT( testHash.getSize() == 2 ); 55 56 rc = testHash.remove("doesn't exist"); 57 CPPUNIT_ASSERT( rc == 0 ); 58 CPPUNIT_ASSERT( testHash.getSize() == 2 ); 59 60 testHash.varDump(); 61 49 62 } 50 63
