예제 #1
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);
            }
        }
예제 #2
0
        void Mark(int u)
        {
            TPosition pos = GenerateKey(u);

            while (!Null(pos.cluster.Cluster[pos.offset]))
            {
                if (pos.cluster.Cluster[pos.offset].u == u)
                {
                    break;
                }
                IncreaseKey(ref pos);
            }
            TEntry entry = GetTEntry(pos);

            if (entry.GetMark() != true)
            {
                if (!IsTerminal(entry.low))
                {
                    Mark(entry.low);
                }

                AddMark(ref pos);

                if (!IsTerminal(entry.high))
                {
                    Mark(entry.high);
                }
            }
        }
예제 #3
0
        public void Remove(int u)
        {
            TPosition pos = GenerateKey(u);

            while (!Null(pos.cluster.Cluster[pos.offset]))
            {
                if (pos.cluster.Cluster[pos.offset].u == u)
                {
                    count--;
                    pos.cluster.Cluster[pos.offset] = TEntry.DirtyEntry();     //Only flags dirty
                    return;
                }
                IncreaseKey(ref pos);
            }
        }
예제 #4
0
        public void Add(TEntry entry)
        {
#if NoGC
            if (NeedResize())
            {
                AddCluster();
            }
#endif
            TPosition pos = GenerateKey(entry.u);
            while (Used(pos.cluster.Cluster[pos.offset]))
            {
                IncreaseKey(ref pos);
            }
            pos.cluster.Cluster[pos.offset] = entry;
            count++;
        }
예제 #5
0
 private static bool Dirty(TEntry entry)
 {
     return(entry.low == -1);
 }
예제 #6
0
 private static bool Used(TEntry entry)
 {
     return(entry.GetVar() > 0 || entry.u > 0);
 }
예제 #7
0
 private static bool Null(TEntry entry)
 {
     return(entry.u == 0 && entry.GetVar() == 0);
 }