1 /****************************************
2 * BDD+ Manipulator (SAPPORO-1.21) *
3 * (Hash table methods) *
4 * (C) Shin-ichi MINATO (Feb. 18, 2009) *
5 ****************************************/
12 _wheel = new BDD_Entry[_hashSize];
16 BDD_Hash::~BDD_Hash() { delete[] _wheel; }
18 void BDD_Hash::Clear()
20 if(_hashSize != 0) delete[] _wheel;
22 _wheel = new BDD_Entry[_hashSize];
26 BDD_Hash::BDD_Entry* BDD_Hash::GetEntry(BDD key)
28 bddword id = key.GetID();
29 bddword hash = (id+(id>>10)+(id>>20)) & (_hashSize - 1);
31 while(_wheel[i]._key != -1)
33 if(key == _wheel[i]._key) return & _wheel[i];
38 while(_wheel[i]._key != -1)
40 if(_wheel[i]._ptr == 0) break;
47 void BDD_Hash::Enlarge()
49 bddword oldSize = _hashSize;
50 BDD_Entry* oldWheel = _wheel;
53 _wheel = new BDD_Entry[_hashSize];
56 cerr << "<ERROR> BDD_Hash::Enlarge(): Memory overflow (";
57 cerr << _hashSize << ")\n";
61 for(bddword i=0; i<oldSize; i++)
62 if(oldWheel[i]._ptr != 0)
63 if(oldWheel[i]._key != -1)
64 Enter(oldWheel[i]._key, oldWheel[i]._ptr);
68 void BDD_Hash::Enter(BDD key, void* ptr)
69 // ptr = 0 means deleting.
71 BDD_Entry* ent = GetEntry(key);
72 if(ent -> _key == -1) _amount++;
73 else if(ent -> _ptr == 0) _amount++;
74 if(ptr == 0) _amount--;
77 if(_amount >= (_hashSize>>1)) Enlarge();
80 void* BDD_Hash::Refer(BDD key)
81 // returns 0 if not found.
83 BDD_Entry* ent = GetEntry(key);
84 if(ent -> _key == -1) return 0;
88 bddword BDD_Hash::Amount() { return _amount; }