public bool SearchingPhase(uint maxBucketSize, BucketSortedList[] sortedLists, uint[] dispTable) { var maxProbes = (uint)(((Math.Log(_m) / Math.Log(2.0)) / 20) * MaxProbesBase); uint i; var occupTable = new BitArray((int) (((_n + 31) / 32) * sizeof(uint))); for(i = maxBucketSize; i > 0; i--) { uint probeNum = 0; uint probe0Num = 0; uint probe1Num = 0; var sortedListSize = sortedLists[i].Size; while(sortedLists[i].Size != 0) { var currBucket = sortedLists[i].BucketsList; uint nonPlacedBucket=0; for (uint j = 0; j < sortedLists[i].Size; j++) { // if bucket is successfully placed remove it from list if (PlaceBucketProbe(probe0Num, probe1Num, currBucket, i, occupTable)) { dispTable[_buckets[currBucket].BucketID] = probe0Num + probe1Num * _n; } else { _buckets[nonPlacedBucket + sortedLists[i].BucketsList].ItemsList = _buckets[currBucket].ItemsList; _buckets[nonPlacedBucket + sortedLists[i].BucketsList].BucketID = _buckets[currBucket].BucketID; nonPlacedBucket++; } currBucket++; } sortedLists[i].Size = nonPlacedBucket; probe0Num++; if(probe0Num >= _n) { probe0Num -= _n; probe1Num++; } probeNum++; if (probeNum < maxProbes && probe1Num < _n) continue; sortedLists[i].Size = sortedListSize; return false; } sortedLists[i].Size = sortedListSize; } return true; }
bool PlaceBucketProbe(uint probe0Num, uint probe1Num, uint bucketNum, uint size, BitArray occupTable) { uint i; uint position; var p = _buckets[bucketNum].ItemsList; // try place bucket with probe_num for(i = 0; i < size; i++) // placement { position = (uint)((_items[p].F + ((ulong)_items[p].H) * probe0Num + probe1Num) % _n); if (occupTable.GetBit(position)) { break; } occupTable.SetBit(position); p++; } if(i != size) // Undo the placement { p= _buckets[bucketNum].ItemsList; for (; ; ) { if (i == 0) { break; } position = (uint)((_items[p].F + ((ulong)_items[p].H) * probe0Num + probe1Num) % _n); occupTable.UnSetBit(position); // ([position/32]^=(1<<(position%32)); p++; i--; } return false; } return true; }