コード例 #1
0
ファイル: CuckooFilter.cs プロジェクト: spence521/BVC_Filters
        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);
        }
コード例 #2
0
ファイル: CuckooFilter.cs プロジェクト: spence521/BVC_Filters
        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);
            }
        }
コード例 #3
0
ファイル: CuckooFilter.cs プロジェクト: spence521/BVC_Filters
        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);
        }
コード例 #4
0
ファイル: CuckooFilter.cs プロジェクト: spence521/BVC_Filters
 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;
         }
     }
 }