static int[] RadixSortAux(int[] array, int digit)
        {
            bool Empty = true;

            KVEntry[] digits      = new KVEntry[array.Length]; //array that holds the digits;
            int[]     SortedArray = new int[array.Length];     //Hold the sorted array
            for (int i = 0; i < array.Length; i++)
            {
                digits[i]       = new KVEntry();
                digits[i].Key   = i;
                digits[i].Value = (array[i] / digit) % 10;
                if (array[i] / digit != 0)
                {
                    Empty = false;
                }
            }

            if (Empty)
            {
                return(array);
            }

            KVEntry[] SortedDigits = CountingSort(digits);
            for (int i = 0; i < SortedArray.Length; i++)
            {
                SortedArray[i] = array[SortedDigits[i].Key];
            }
            return(RadixSortAux(SortedArray, digit * 10));
        }
Esempio n. 2
0
	private static KVEntry[] CountingSort(KVEntry[] ArrayA)
	{
		int[] ArrayB = new int[MaxValue(ArrayA) + 1];
		KVEntry[] ArrayC = new KVEntry[ArrayA.Length];

		for (int i = 0; i < ArrayB.Length; i++)
			ArrayB[i] = 0;

		for (int i = 0; i < ArrayA.Length; i++)
			ArrayB[ArrayA[i].Value]++;

		for (int i = 1; i < ArrayB.Length; i++)
			ArrayB[i] += ArrayB[i - 1];

		for (int i = ArrayA.Length - 1; i >= 0; i--)
		{
			int value = ArrayA[i].Value;
			int index = ArrayB[value];
			ArrayB[value]--;
			ArrayC[index - 1] = new KVEntry();
			ArrayC[index - 1].Key = i;
			ArrayC[index - 1].Value = value;
		}
		return ArrayC;
	}
        static KVEntry[] CountingSort(KVEntry[] ArrayA)
        {
            int[]     ArrayB = new int[MaxValue(ArrayA) + 1];
            KVEntry[] ArrayC = new KVEntry[ArrayA.Length];

            for (int i = 0; i < ArrayB.Length; i++)
            {
                ArrayB[i] = 0;
            }

            for (int i = 0; i < ArrayA.Length; i++)
            {
                ArrayB[ArrayA[i].Value]++;
            }

            for (int i = 1; i < ArrayB.Length; i++)
            {
                ArrayB[i] += ArrayB[i - 1];
            }

            for (int i = ArrayA.Length - 1; i >= 0; i--)
            {
                int value = ArrayA[i].Value;
                int index = ArrayB[value];
                ArrayB[value]--;
                ArrayC[index - 1]       = new KVEntry();
                ArrayC[index - 1].Key   = i;
                ArrayC[index - 1].Value = value;
            }
            return(ArrayC);
        }
Esempio n. 4
0
        private static KVEntry[] radixCountingSort(KVEntry[] inputA)
        {
            int[]     inputB = new int[MaxValue(inputA) + 1];
            KVEntry[] inputC = new KVEntry[inputA.Length];

            for (int i = 0; i < inputB.Length; i++)
            {
                inputB[i] = 0;
            }

            for (int i = 0; i < inputA.Length; i++)
            {
                inputB[inputA[i].Value]++;
            }

            for (int i = 1; i < inputB.Length; i++)
            {
                inputB[i] += inputB[i - 1];
            }

            for (int i = inputA.Length - 1; i >= 0; i--)
            {
                int value = inputA[i].Value;
                int index = inputB[value];

                inputB[value]--;
                inputC[index - 1]       = new KVEntry();
                inputC[index - 1].Key   = i;
                inputC[index - 1].Value = value;
            }

            return(inputC);
        }
Esempio n. 5
0
        private static int[] radixSortAux(int[] input, int digit)
        {
            bool empty = true;

            KVEntry[] digits      = new KVEntry[input.Length];
            int[]     sortedArray = new int[input.Length];

            for (int i = 0; i < input.Length; i++)
            {
                digits[i]       = new KVEntry();
                digits[i].Key   = i;
                digits[i].Value = (input[i] / digit) % 10;
                if ((input[i] / digit) != 0)
                {
                    empty = false;
                }
            }

            if (empty)
            {
                return(input);
            }

            KVEntry[] sortedDigits = radixCountingSort(digits);
            for (int i = 0; i < sortedArray.Length; i++)
            {
                sortedArray[i] = input[sortedDigits[i].Key];
            }

            return(radixSortAux(sortedArray, digit * 10));
        }
Esempio n. 6
0
 static int MaxValue(KVEntry[] arr)
 {
     int Max = arr[0].Value;
     for (int i = 1; i < arr.Length; i++)
         if (arr[i].Value > Max)
             Max = arr[i].Value;
     return Max;
 }
Esempio n. 7
0
        //recursive method for radix sort
        private int[] RadixSortAux(int[] intSortArray, int digit)
        {
            bool Empty = true;//set depending on if array is empty

            //array will hold key and value for type struct KVEntry
            KVEntry[] digits = new KVEntry[intSortArray.Length];
            //array to hold sorted values
            int[] SortedArray = new int[intSortArray.Length];

            //checks each element in array and sets key and value
            //also checks if there is a current digit placeholder
            for (int i = 0; i < intSortArray.Length; i++)
            {
                digits[i]     = new KVEntry(); //initialized array
                digits[i].Key = i;             //sets key to i
                //sets value to current digit placeholder(i.e. 1, 10, 100)
                digits[i].Value = (intSortArray[i] / digit) % 10;
                numComparisons++;
                //checks if value exists for current digit placeholder
                if (intSortArray[i] / digit != 0)
                {
                    Empty = false;
                }
            }

            //if no current digit placeholder
            if (Empty)
            {
                //initializes array to hold final sorted values
                int[] finalIntSort = new int[intSortArray.Length];
                //places sorted values into final sorted array
                for (int j = 0; j < intSortArray.Length; j++)
                {
                    finalIntSort[j] = intSortArray[j];
                }

                return(finalIntSort);//returns to method RadixSort
            }
            else
            {
                //sets array = to method CountingSort using digits array
                KVEntry[] SortedDigits = CountingSort(digits);
                //puts newly sorted values into SortedArray
                for (int i = 0; i < SortedArray.Length; i++)
                {
                    SortedArray[i] = intSortArray[SortedDigits[i].Key];
                }
                //returns current sort and recalls method with current values and current digit*10
                return(RadixSortAux(SortedArray, digit * 10));
            }
        }
Esempio n. 8
0
        public async Task<bool> PutKV(KVEntry entry, object extraParams=null )
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            using (var client = UsingHttpClient())
            {
                var uri = new UriBuilder("http", consulInfo.Host, consulInfo.Port, String.Format("/v{0}/{1}/{2}",
                                consulInfo.Version, KV_ENTRIES, entry.Key),
                                (extraParams==null) ? "" : GetExtraValuesFragment(extraParams)).Uri;
                var httpContent = new StringContent(entry.Value ?? "", Encoding.UTF8, ConsulProtocolDataMediaType);
                var res = await client.PutAsync(uri, httpContent);
                var responseContent = await res.Content.ReadAsStringAsync();
                return (res.StatusCode == HttpStatusCode.OK && Convert.ToBoolean(responseContent));
            }
        }
Esempio n. 9
0
        //method that swaps elements for radix sort
        private KVEntry[] CountingSort(KVEntry[] ArrayA)
        {
            //new array of length MaxValue + 1
            int[] ArrayB = new int[MaxValue(ArrayA) + 1];
            //new array of length arrayA/SortedArray
            KVEntry[] ArrayC = new KVEntry[ArrayA.Length];

            //sets arrayB values to 0
            for (int i = 0; i < ArrayB.Length; i++)
            {
                ArrayB[i] = 0;
            }

            //value of arrayA index i becomes index of arrayB
            //value for arrayB becomes # of elements with same value in arrayA
            //values added separately in loop
            for (int i = 0; i < ArrayA.Length; i++)
            {
                ArrayB[ArrayA[i].Value]++;
                numSwaps++;
            }

            //adds values from index i and (i-1) and places at i
            for (int i = 1; i < ArrayB.Length; i++)
            {
                ArrayB[i] += ArrayB[i - 1];
                numSwaps++;
            }

            for (int i = ArrayA.Length - 1; i >= 0; i--)
            {
                //gets value for arrayA at index i
                int value = ArrayA[i].Value;
                //gets value for arrayB and index value
                int index = ArrayB[value];
                //subtracts 1 from value
                ArrayB[value]--;
                //next 3 steps put values in arrayC-values for current placeholder are now sorted
                ArrayC[index - 1]       = new KVEntry();
                ArrayC[index - 1].Key   = i;
                ArrayC[index - 1].Value = value;
                numSwaps++;
            }
            return(ArrayC);//returns to method RadixSortAux
        }
Esempio n. 10
0
	private static int[] RadixSort(int[] array, int digit)
	{
		bool Empty = true;
		KVEntry[] digits = new KVEntry[array.Length];//array that holds the digits;
		int[] SortedArray = new int[array.Length];//Hold the sorted array
		for (int i = 0; i < array.Length; i++)
		{
			digits[i] = new KVEntry();
			digits[i].Key = i;
			digits[i].Value = (array[i] / digit) % 10;
			if (array[i]/digit!=0)
				Empty = false;
		}

		if (Empty)
			return array;

		KVEntry[] SortedDigits = CountingSort(digits);
		for (int i = 0; i < SortedArray.Length; i++)
			SortedArray[i] = array[SortedDigits[i].Key];
		return RadixSort(SortedArray, digit * 10);
	}
 public void SetOriginKVEntry(KVEntry kvEntry)
 {
     _kvEntry = kvEntry;
 }
 public ConsulMembershipTableEntry(KVEntry kvEntry)
 {
     _kvEntry = kvEntry;
     Members = new Dictionary<string, ConsulMembershipEntry>();
 }