protected int FindEmptySlot(HashBucket <TKey, TValue> bucket) { for (int i = 0; i < bucket.Length; i++) { if (!bucket.Used(i) && bucket.Lock(i)) { return(i); } } return(-1); }
// Returns -1 if all slots are locked private int PickSlotNumber(HashBucket <TKey, TValue> bucket) { int slotNumber = _random.Next(_bucketWidth); if (bucket.Lock(slotNumber)) { return(slotNumber); } for (int i = 0; i < DEFAULT_SLOT_WIDTH; i++) { if (i == slotNumber) { continue; } if (bucket.Lock(i)) { return(i); } } return(-1); }