示例#1
0
        void GarbageCollect()
        {
            foreach (KeyValuePair <int, int> root in refCount)
            {
                Mark(root.Key);
            }

            TCluster cluster = this.FirstCluster;
            TEntry   tempEntry;

            while (cluster != null)
            {
                for (int i = 0; i < cluster.Cluster.Length; i++)
                {
                    tempEntry = cluster.Cluster[i];
                    if (Used(tempEntry) && tempEntry.GetMark() == false)
                    {
                        Remove(tempEntry.u);
                        Kernel.H.Remove(tempEntry.GetVar(), tempEntry.low, tempEntry.high);
                    }
                    else if (Used(tempEntry) && tempEntry.GetMark() == true)
                    {
                        UnMark(tempEntry.u);
                    }
                }
                cluster = cluster.next;
            }
        }
示例#2
0
        private void AddCluster()
        {
            TCluster NewCluster = new TCluster(this.size);

            size = (int)(size * this.factor);

            NewCluster.next   = this.FirstCluster;              //New cluster is added in the beginning
            this.FirstCluster = NewCluster;

            TPosition pos = new TPosition(ref FirstCluster.next, 0);

            while (!(pos.cluster == FirstCluster && pos.offset == 0))      //rehash
            {
                if (Used(pos.cluster.Cluster[pos.offset]))
                {
                    TEntry    entry       = pos.cluster.Cluster[pos.offset];
                    TPosition newPosition = GenerateKey(entry.u);

                    if (newPosition.offset != pos.offset || newPosition.cluster != pos.cluster)
                    {
                        pos.cluster.Cluster[pos.offset] = TEntry.DirtyEntry();
                        this.count--;
                        Add(entry);
                    }
                }

                IncreaseKey(ref pos);
            }
        }
示例#3
0
 public void Clear()
 {
     count             = 0;
     size              = startSize;
     this.FirstCluster = new TCluster(size);
     refCount.Clear();
     refCount.Add(0, 1);
     refCount.Add(1, 1);
 }
示例#4
0
        //splits a key into cluster + offset
        internal TPosition GenerateKey(int u)
        {
            int      offset = u % size;
            TCluster probe  = FirstCluster;

            while (offset >= probe.Cluster.Length)
            {
                offset -= probe.Cluster.Length;
                probe   = probe.next;
            }

            return(new TPosition(ref probe, offset));
        }
示例#5
0
 internal TPosition(ref TCluster cluster, int offset)
 {
     this.cluster = cluster;
     this.offset  = offset;
 }