Exemplo n.º 1
0
        private readonly int nLimit; // if n > nLimit, do not save locations from search

        public Dictionary <int, int> TrivialSolution(int location)
        {
            /**
             * Iterate through each list of coordinate nodes, perform binary
             * search to find index holding node with data, extract location
             * -> O(k log(n))  */

            // Return dictionary w/ key=dimension, pair=location in dimension
            Dictionary <int, int> locationsOfData = new Dictionary <int, int>();
            BinarySearchNodes     bsn             = new BinarySearchNodes();

            for (int i = 0; i < k; i++)
            {
                CoordNode[] arr       = InputCoordMatrix[i];
                int         nodeIndex = bsn.BinarySearch(arr, location, 0);
                int         nodeData  = arr[nodeIndex].GetAttr(1);

                // Memory issues, this is a stupid amount of space especially
                // when we're only trying to record function timing
                if (k < nLimit)
                {
                    locationsOfData.Add(i + 1, nodeData);
                }
            }

            return(locationsOfData);
        }
Exemplo n.º 2
0
        public Dictionary <int, int> FractionalCascadingSearch(int data)
        {
            /**
             * Perform binary search to find data in first dimension. Then iteratively use
             * the previous and/or next pointers to search the (tiny) range of the next
             * dimension given by the prev and next node pointers    */
            BinarySearchNodes bsn = new BinarySearchNodes();

            // Return dictionary w/ key=dimension, pair=location in dimension
            Dictionary <int, int> locationsOfData = new Dictionary <int, int>();

            // Other variables we'll need
            FCNode dataNode = null;
            int    dataIndex;
            int    currentDim = 1;

            // Find data in first dimension
            dataIndex = bsn.BinarySearch(NodeMatrixPrime[0], data, 0);
            dataNode  = NodeMatrixPrime[0][dataIndex];

            // Ensure that dataNode is in the correct dimension - if not check neighbors
            if (dataNode.GetDim() != currentDim)
            {
                FCNode next = dataNode.GetNextPointer();
                FCNode prev = dataNode.GetPrevPointer();
                if (TargetNodeCheck(next, data, currentDim))
                {
                    dataNode = next;
                }
                else if (TargetNodeCheck(prev, data, currentDim))
                {
                    dataNode = prev;
                }
                else
                {
                    string errorMsg = "Cannot locate data in augmented list 1'\n" +
                                      $"DataNode: {dataNode}\nIndex neighbor left:\t" +
                                      NodeMatrixPrime[0][dataIndex - 1] +
                                      "\nIndex neighbor right:\t" +
                                      NodeMatrixPrime[0][dataIndex + 1] +
                                      $"\nNextNode: {next}nPrevNode: {prev}";
                    throw new Exception(errorMsg);
                }
            }

            if (k < nLimit) // This takes up too much memory
            // Assign first dimension location in return dictionary
            {
                locationsOfData[currentDim] = dataNode.GetAttr(1);
            }

            for (int i = 1; i < NodeMatrixPrime.Length; i++)
            {
                // Walk through promoted node pointers, starting with the list 2' until
                // list (k)'
                currentDim++;
                dataNode = FindNodeFromPointerRange(dataNode, currentDim);
                if (k < nLimit)
                {
                    locationsOfData[currentDim] = dataNode.GetAttr(1);
                }
            }

            return(locationsOfData);
        }