public FSet InitBucket(HNode temp, int i)
        {
            FSet       b = temp.Buckets[i];
            HNode      s = temp.Pred;
            List <int> mySet;

            if (b == null && s != null)
            {
                if (temp.Size == (s.Size * 2))
                {
                    FSet       m    = s.Buckets[i % s.Size];
                    List <int> mSet = Freeze(m);
                    mySet = Intersect(mSet, temp.Size, i);
                    UnFreeze(m);
                }
                else
                {
                    FSet       m    = s.Buckets[i];
                    FSet       n    = s.Buckets[i + temp.Size];
                    List <int> mSet = Freeze(m);
                    List <int> nSet = Freeze(n);
                    mySet = Union(mSet, nSet);
                    UnFreeze(m);
                    UnFreeze(n);
                }

                FSet bPrime = new FSet(mySet, true);
                Interlocked.CompareExchange(ref temp.Buckets[i], bPrime, null);
            }
            return(temp.Buckets[i]);
        }
 public List <int> UnFreeze(FSet b)
 {
     if (!b.Ok)
     {
         b.Ok = true;
     }
     return(b.Set);
 }
 public List <int> Freeze(FSet b)
 {
     if (b.Ok)
     {
         b.Ok = false;
     }
     return(b.Set);
 }
 public bool HasMember(FSet b, int k)
 {
     try
     {
         if (b.Set.Any(x => x == k))
         {
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public bool Apply(int typeOp, int k)
        {
            FSetOp fSetOp = new FSetOp(typeOp, k);

            while (true)
            {
                HNode temp = Head;
                FSet  b    = temp.Buckets[k % temp.Size];
                if (b == null)
                {
                    b = InitBucket(temp, k % temp.Size);
                }
                if (Invoke(b, fSetOp))
                {
                    return(GetResponse(fSetOp));
                }
            }
        }
        public bool Contains(int k)
        {
            HNode temp = Head;
            FSet  b    = temp.Buckets[k % temp.Size];

            if (b == null)
            {
                HNode s = temp.Pred;
                if (s != null)
                {
                    b = s.Buckets[k % s.Size];
                }
                else
                {
                    b = temp.Buckets[k % temp.Size];
                }
            }
            return(HasMember(b, k));
        }
        public bool Invoke(FSet b, FSetOp op)
        {
            try
            {
                if (b.Ok && !op.Done)
                {
                    if (op.OpType == 1)
                    {
                        op.Resp = !HasMember(b, op.Key);
                        b.Set.Add(op.Key);
                    }
                    else if (op.OpType == -1)
                    {
                        op.Resp = HasMember(b, op.Key);
                        b.Set.Remove(op.Key);
                    }
                    op.Done = true;
                }
            }
            catch (Exception)
            { }

            return(op.Done);
        }