public void Resize(bool grow)
        {
            HNode temp = Head;

            if (temp.Size > 1 || grow)
            {
                for (int i = 0; i < temp.Size; i++)
                {
                    InitBucket(temp, i);
                }
                temp.Pred = null;
                int size;

                if (grow)
                {
                    size = temp.Size * 2;
                }
                else
                {
                    size = temp.Size / 2;
                }

                HNode tempPrime = new HNode(size, temp);
                Interlocked.CompareExchange(ref Head, tempPrime, temp);
                Size = size;
            }
        }
 public LFHashTable()
 {
     Head             = new HNode(1, null);
     Head.Buckets[0]  = new FSet(0, true);
     NumberOfElements = 0;
     Size             = 1;
 }
        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 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));
        }
Esempio n. 6
0
 public HNode(int size, HNode pred)
 {
     Buckets = new FSet[size];
     Size    = size;
     Pred    = pred;
 }