Ejemplo n.º 1
0
        /// <summary>
        /// Partions the vertices based on the pivot value.
        /// </summary>
        /// <typeparam name="TEdgeData"></typeparam>
        /// <param name="graph">The graph to sort.</param>
        /// <param name="n">The hilbert accuracy.</param>
        /// <param name="left">The first vertex to consider.</param>
        /// <param name="right">The last vertex to consider.</param>
        /// <return>The new left.</return>
        private static uint SortHilbertPartition <TEdgeData>(GraphBase <TEdgeData> graph, int n, uint left, uint right)
            where TEdgeData : struct, IGraphEdgeData
        { // get the pivot value.
            uint  start      = left;
            ulong pivotValue = graph.HilbertDistance(n, left);

            left++;

            while (true)
            {
                ulong leftValue = graph.HilbertDistance(n, left);
                while (left <= right && leftValue <= pivotValue)
                { // move the left to the first value bigger than pivot.
                    left++;
                    leftValue = graph.HilbertDistance(n, left);
                }

                ulong rightValue = graph.HilbertDistance(n, right);
                while (left <= right && rightValue > pivotValue)
                { // move the right to the first value smaller than pivot.
                    right--;
                    rightValue = graph.HilbertDistance(n, right);
                }

                if (left > right)
                { // we are done searching, left is to the right of right.
                    // make sure the pivot value is where it is supposed to be.
                    graph.Switch(start, left - 1);
                    return(left);
                }

                // swith left<->right.
                graph.Switch(left, right);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Switches the locations around for the two given vertices.
        /// </summary>
        /// <typeparam name="TEdgeData"></typeparam>
        public static void Switch <TEdgeData>(this GraphBase <TEdgeData> graph, uint vertex1, uint vertex2)
            where TEdgeData : struct, IGraphEdgeData
        {
            if (graph.IsDirected)
            {
                throw new ArgumentException("Cannot switch two vertices on a directed graph without it's reverse index.");
            }

            graph.Switch(vertex1, vertex2, null);
        }