Example #1
0
        public bool Lookup(int item)
        {
            HashCombo i = new HashCombo(item, size);

            if (BucketPosition(i.Hash1, i.Fingerprint) != -1 || BucketPosition(i.Hash2, i.Fingerprint) != -1)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        public void Delete(int item)
        {
            HashCombo i = new HashCombo(item, size);

            if (BucketPosition(i.Hash1, i.Fingerprint) != -1)
            {
                ResetBucket(i.Hash1, i.Fingerprint);
            }
            if (BucketPosition(i.Hash2, i.Fingerprint) != -1)
            {
                ResetBucket(i.Hash2, i.Fingerprint);
            }
        }
Example #3
0
        private void ReplaceAndPlace(HashCombo item)
        {
            if (replace_counter == 500)
            {
                Filter_backup = (int[, ])Filter.Clone();
            }
            if (replace_counter == 0)
            {
                Filter          = Filter_backup;
                replace_counter = 500;
                IsFull          = true;
                return;
            }
            replace_counter--;

            int location = -1;
            int choice   = rand.Next(0, 2);

            if (choice == 0)
            {
                location = item.Hash1;
            }
            else
            {
                location = item.Hash2;
            }

            choice = rand.Next(0, bucket_size);



            int original_obj = Filter[location, choice];

            Filter[location, choice] = item.Fingerprint;
            Insert(original_obj, finger_only: true);
        }
Example #4
0
 public void Insert(int item, bool finger_only = false)
 {
     if (!IsFull)
     {
         HashCombo i = new HashCombo(item, size, finger_only);
         if (IsEmptyAt(i.Hash1) == -1)
         {
             if (IsEmptyAt(i.Hash2) == -1)
             {
                 ReplaceAndPlace(i);
             }
             else
             {
                 Filter[i.Hash2, IsEmptyAt(i.Hash2)] = i.Fingerprint;
                 replace_counter = 500;
             }
         }
         else
         {
             Filter[i.Hash1, IsEmptyAt(i.Hash1)] = i.Fingerprint;
             replace_counter = 500;
         }
     }
 }