Beispiel #1
0
        public bool SearchingPhase(uint maxBucketSize, BucketSortedList[] sortedLists, uint[] dispTable)
        {
            var maxProbes = (uint)(((Math.Log(_m) / Math.Log(2.0)) / 20) * MaxProbesBase);
            uint i;
            var occupTable = new BitArray((int) (((_n + 31) / 32) * sizeof(uint)));

            for(i = maxBucketSize; i > 0; i--)
            {
                uint probeNum = 0;
                uint probe0Num = 0;
                uint probe1Num = 0;
                var sortedListSize = sortedLists[i].Size;
                while(sortedLists[i].Size != 0)
                {
                    var currBucket = sortedLists[i].BucketsList;
                    uint nonPlacedBucket=0;
                    for (uint j = 0; j < sortedLists[i].Size; j++)
                    {
                        // if bucket is successfully placed remove it from list
                        if (PlaceBucketProbe(probe0Num, probe1Num, currBucket, i, occupTable))
                        {	
                            dispTable[_buckets[currBucket].BucketID] = probe0Num + probe1Num * _n;
                        } 
                        else
                        {
                            _buckets[nonPlacedBucket + sortedLists[i].BucketsList].ItemsList = _buckets[currBucket].ItemsList;
                            _buckets[nonPlacedBucket + sortedLists[i].BucketsList].BucketID = _buckets[currBucket].BucketID;
                            nonPlacedBucket++;
                        }
                        currBucket++;
                    }
                    sortedLists[i].Size = nonPlacedBucket;
                    probe0Num++;
                    if(probe0Num >= _n)
                    {
                        probe0Num -= _n;
                        probe1Num++;
                    }
                    probeNum++;
                    if (probeNum < maxProbes && probe1Num < _n) continue;
                    sortedLists[i].Size = sortedListSize;
                    return false;
                }
                sortedLists[i].Size = sortedListSize;
            }
            return true;            
        }
Beispiel #2
0
        public BucketSortedList[] OrderingPhase(uint maxBucketSize)
        {
            var  sortedLists  = new BucketSortedList[maxBucketSize + 1];
            var  inputBuckets = _buckets;
            var  inputItems   = _items;
            uint i;
            uint bucketSize, position;

            for (i = 0; i < _nbuckets; i++)
            {
                bucketSize = inputBuckets[i].Size;
                if (bucketSize == 0)
                {
                    continue;
                }
                sortedLists[bucketSize].Size++;
            }

            sortedLists[1].BucketsList = 0;
            // Determine final position of list of buckets into the contiguous array that will store all the buckets
            for (i = 2; i <= maxBucketSize; i++)
            {
                sortedLists[i].BucketsList = sortedLists[i - 1].BucketsList + sortedLists[i - 1].Size;
                sortedLists[i - 1].Size    = 0;
            }

            sortedLists[i - 1].Size = 0;
            // Store the buckets in a new array which is sorted by bucket sizes
            var outputBuckets = new Bucket[_nbuckets];

            for (i = 0; i < _nbuckets; i++)
            {
                bucketSize = inputBuckets[i].Size;
                if (bucketSize == 0)
                {
                    continue;
                }

                position = sortedLists[bucketSize].BucketsList + sortedLists[bucketSize].Size;
                outputBuckets[position].BucketID  = i;
                outputBuckets[position].ItemsList = inputBuckets[i].ItemsList;
                sortedLists[bucketSize].Size++;
            }

            _buckets = outputBuckets;

            // Store the items according to the new order of buckets.
            var outputItems = new Item[_n];

            position = 0;

            for (bucketSize = 1; bucketSize <= maxBucketSize; bucketSize++)
            {
                for (i = sortedLists[bucketSize].BucketsList;
                     i < sortedLists[bucketSize].Size + sortedLists[bucketSize].BucketsList;
                     i++)
                {
                    var position2 = outputBuckets[i].ItemsList;
                    outputBuckets[i].ItemsList = position;
                    for (uint j = 0; j < bucketSize; j++)
                    {
                        outputItems[position].F = inputItems[position2].F;
                        outputItems[position].H = inputItems[position2].H;
                        position++;
                        position2++;
                    }
                }
            }

            //Return the items sorted in new order and free the old items sorted in old order
            _items = outputItems;
            return(sortedLists);
        }
Beispiel #3
0
        public BucketSortedList[] OrderingPhase(uint maxBucketSize)
        {
            var sortedLists = new BucketSortedList[maxBucketSize + 1];
            var inputBuckets = _buckets;
            var inputItems = _items;
            uint i;
            uint bucketSize, position;

            for (i = 0; i < _nbuckets; i++)
            {
                bucketSize = inputBuckets[i].Size;
                if (bucketSize == 0)
                    continue;
                sortedLists[bucketSize].Size++;
            }
            
            sortedLists[1].BucketsList = 0;
            // Determine final position of list of buckets into the contiguous array that will store all the buckets
            for (i = 2; i <= maxBucketSize; i++)
            {
                sortedLists[i].BucketsList = sortedLists[i - 1].BucketsList + sortedLists[i - 1].Size;
                sortedLists[i - 1].Size = 0;
            }
            
            sortedLists[i - 1].Size = 0;
            // Store the buckets in a new array which is sorted by bucket sizes
            var outputBuckets = new Bucket[_nbuckets];

            for (i = 0; i < _nbuckets; i++)
            {
                bucketSize = inputBuckets[i].Size;
                if (bucketSize == 0)
                {
                    continue;
                }
                
                position = sortedLists[bucketSize].BucketsList + sortedLists[bucketSize].Size;
                outputBuckets[position].BucketID = i;
                outputBuckets[position].ItemsList = inputBuckets[i].ItemsList;
                sortedLists[bucketSize].Size++;
            }
            
            _buckets = outputBuckets;

            // Store the items according to the new order of buckets.
            var outputItems = new Item[_n];
            position = 0;
            
            for (bucketSize = 1; bucketSize <= maxBucketSize; bucketSize++)
            {
                for (i = sortedLists[bucketSize].BucketsList;
                     i < sortedLists[bucketSize].Size + sortedLists[bucketSize].BucketsList;
                     i++)
                {
                    var position2 = outputBuckets[i].ItemsList;
                    outputBuckets[i].ItemsList = position;
                    for (uint j = 0; j < bucketSize; j++)
                    {
                        outputItems[position].F = inputItems[position2].F;
                        outputItems[position].H = inputItems[position2].H;
                        position++;
                        position2++;
                    }
                }
            }

            //Return the items sorted in new order and free the old items sorted in old order
            _items = outputItems;
            return sortedLists;
        }