KUDr@3900: /* $Id$ */ KUDr@3900: KUDr@3900: struct CHashItem1 { KUDr@3900: struct CKey { KUDr@3900: int k; KUDr@3900: FORCEINLINE int CalcHash() const {return k;}; KUDr@3900: FORCEINLINE bool operator == (const CKey& other) const {return (k == other.k);} KUDr@3900: }; KUDr@3900: typedef CKey Key; KUDr@3900: CKey key; KUDr@3900: int val; KUDr@3900: CHashItem1* m_next; KUDr@3900: KUDr@3900: CHashItem1() : m_next(NULL) {} KUDr@3900: FORCEINLINE const Key& GetKey() const {return key;} KUDr@3900: CHashItem1* GetHashNext() {return m_next;} KUDr@3900: void SetHashNext(CHashItem1* next) {m_next = next;} KUDr@3900: }; KUDr@3900: KUDr@3900: static int TestHashTable1(bool silent) KUDr@3900: { KUDr@3900: typedef CHashItem1 Item; KUDr@3900: typedef CHashTableT HashTable1_t; KUDr@3900: typedef CArrayT Array_t; KUDr@3900: typedef CHashTableT HashTable2_t; KUDr@3900: KUDr@3900: int res = 0; KUDr@3900: { KUDr@3900: HashTable1_t ht1; KUDr@3900: HashTable2_t ht2; KUDr@3900: Array_t ar1; KUDr@3900: Array_t ar2; KUDr@3900: KUDr@3900: #ifdef _DEBUG KUDr@3900: static const int nItems = 10000; KUDr@3900: #else KUDr@3900: static const int nItems = 1000000; KUDr@3900: #endif KUDr@3900: { KUDr@3900: srand(0); KUDr@3900: for (int i = 0; i < nItems; i++) { KUDr@3900: int r1 = i; KUDr@3900: int r2 = rand() & 0x0000FFFF | (rand() << 16); KUDr@3900: Item& I1 = ar1.Add(); KUDr@3900: Item& I2 = ar2.Add(); KUDr@3900: I1.key.k = r1; KUDr@3900: I2.key.k = r1; KUDr@3900: I1.val = r2; KUDr@3900: I2.val = r2; KUDr@3900: ht1.Push(I1); KUDr@3900: ht2.Push(I2); KUDr@3900: } KUDr@3900: } KUDr@3900: { KUDr@3900: srand(0); KUDr@3900: for (int i = 0; i < nItems; i++) { KUDr@3900: int r1 = i; KUDr@3900: int r2 = rand() & 0x0000FFFF | (rand() << 16); KUDr@3900: HashTable1_t::Tkey k; k.k = r1; KUDr@3900: Item& i1 = ht1.Find(k); KUDr@3900: Item& i2 = ht2.Find(k); KUDr@3900: KUDr@3900: CHECK_INT(0, &i1 != NULL, 1); KUDr@3900: CHECK_INT(1, &i2 != NULL, 1); KUDr@3900: KUDr@3900: if (&i1 != NULL) CHECK_INT(2, i1.val, r2); KUDr@3900: if (&i2 != NULL) CHECK_INT(3, i2.val, r2); KUDr@3900: } KUDr@3900: } KUDr@3900: } KUDr@3900: return res; KUDr@3900: } KUDr@3900: KUDr@3900: