public bool MappingPhase(out uint hashSeed, out uint maxBucketSize) { var hl = new uint[3]; var mapItems = new MapItem[_m]; uint mappingIterations = 1000; var rdm = new Random(111); maxBucketSize = 0; for (; ;) { mappingIterations--; hashSeed = (uint)rdm.Next((int)_m); // ((cmph_uint32)rand() % this->_m); BucketsClean(); _keySource.Rewind(); uint i; for (i = 0; i < _m; i++) { JenkinsHash.HashVector(hashSeed, _keySource.Read(), hl); uint g = hl[0] % _nbuckets; mapItems[i].F = hl[1] % _n; mapItems[i].H = hl[2] % (_n - 1) + 1; mapItems[i].BucketNum = g; _buckets[g].Size++; if (_buckets[g].Size > maxBucketSize) { maxBucketSize = _buckets[g].Size; } } _buckets[0].ItemsList = 0; for (i = 1; i < _nbuckets; i++) { _buckets[i].ItemsList = _buckets[i - 1].ItemsList + _buckets[i - 1].Size; _buckets[i - 1].Size = 0; } _buckets[i - 1].Size = 0; for (i = 0; i < _m; i++) { if (!BucketsInsert(mapItems, i)) { break; } } if (i == _m) { return(true); // SUCCESS } if (mappingIterations == 0) { return(false); } } }
/// <summary> /// Compute the hash value associate with the key /// </summary> /// <param name="key">key from the original key set</param> /// <returns>Hash value (0 > hash > N)</returns> public uint Search(byte[] key) { var hl = new uint[3]; JenkinsHash.HashVector(_hashSeed, key, hl); var g = hl[0] % _nbuckets; var f = hl[1] % _n; var h = hl[2] % (_n - 1) + 1; var disp = _cs.Query(g); var probe0Num = disp % _n; var probe1Num = disp / _n; var position = (uint)((f + ((ulong)h) * probe0Num + probe1Num) % _n); return(position); }