public when_a_customer_is_requested()
        {
            fakeDataService = A.Fake<DataService>();
            //A.CallTo(() => fakeDataService.AddMessage()).MustHaveHappened();

            handler = new GetIndex(fakeDataService);
        }
Esempio n. 2
0
        internal static int Binary <T>(GetIndex <T> get, int index, int length, CompareToKnownValue <T> compare)
        {
            int low = index;
            int hi  = index + length - 1;

            while (low <= hi)
            {
                int           median        = low + (hi - low >> 1);
                CompareResult compareResult = compare(get(median));
                if (compareResult is Less)
                {
                    low = median + 1;
                }
                else if (compareResult is Greater)
                {
                    hi = median - 1;
                }
                else if (compareResult is Equal)
                {
                    return(median);
                }
                else
                {
                    throw new TowelBugException("Unhandled CompareResult.");
                }
            }
            return(~low);
        }
Esempio n. 3
0
        /// <summary>Sorts an entire array in non-decreasing order using the odd-even sort algorithm.</summary>
        /// <typeparam name="T">The type of objects stored within the array.</typeparam>
        /// <param name="compare">The method of compare for the sort.</param>
        /// <param name="get">Delegate for getting a value at a specified index.</param>
        /// <param name="set">Delegate for setting a value at a specified index.</param>
        /// <remarks>Runtime: Omega(n), average(n^2), O(n^2). Memory: in place. Stablity: yes.</remarks>
        public static void OddEven <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
        {
            var sorted = false;

            while (!sorted)
            {
                sorted = true;
                for (var i = start + 1; i < end - 1; i += 2)
                {
                    if (compare(get(i), get(i + 1)) == Comparison.Greater)
                    {
                        T temp = get(i);
                        set(i, get(i + 1));
                        set(i + 1, temp);
                        sorted = false;
                    }
                }
                for (var i = start; i < end - 1; i += 2)
                {
                    if (compare(get(i), get(i + 1)) == Comparison.Greater)
                    {
                        T temp = get(i);
                        set(i, get(i + 1));
                        set(i + 1, temp);
                        sorted = false;
                    }
                }
            }
        }
Esempio n. 4
0
        private static void MaxHeapify <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int heapSize, int index)
        {
            int left    = (index + 1) * 2 - 1;
            int right   = (index + 1) * 2;
            int largest = 0;

            if (left < heapSize && compare(get(left), get(index)) == Comparison.Greater)
            {
                largest = left;
            }
            else
            {
                largest = index;
            }
            if (right < heapSize && compare(get(right), get(largest)) == Comparison.Greater)
            {
                largest = right;
            }
            if (largest != index)
            {
                T temp = get(index);
                set(index, get(largest));
                set(largest, temp);
                MaxHeapify(compare, get, set, heapSize, largest);
            }
        }
Esempio n. 5
0
 private Hashtable[] collectAllTerms(Cluster[] clusters)
 {
     Hashtable[] clusterTerms = new Hashtable[clusters.Length];             //collect all term counts for each cluster
     for (int i = 0; i < clusterTerms.Length; i++)
     {
         clusterTerms[i] = new Hashtable();
         IDictionaryEnumerator en = clusters[i].DocIds.GetEnumerator();
         while (en.MoveNext())
         {
             short         docId    = Convert.ToInt16(en.Key);
             DocTermItem[] docTerms = GetIndex.DocTerms(docId);                     //get all terms+counts for current doc
             foreach (DocTermItem dt in docTerms)
             {
                 int           termId    = dt.TermId;
                 short         termCount = dt.TermCount;
                 TermCountItem tc        = new TermCountItem(termId, termCount);
                 if (!clusterTerms[i].Contains(termId))
                 {
                     clusterTerms[i].Add(termId, tc);
                 }
                 else
                 {
                     TermCountItem existingTC = (TermCountItem)clusterTerms[i][termId];
                     existingTC.termCount = existingTC.termCount + termCount;
                 }
             }
         }
     }
     return(clusterTerms);
 }
Esempio n. 6
0
        private static int Binary <T>(GetIndex <T> get, int index, int length, CompareToKnownValue <T> compare)
        {
            int low = index;
            int hi  = index + length - 1;

            while (low <= hi)
            {
                int median = low + (hi - low >> 1);
                switch (compare(get(median)))
                {
                case CompareResult.Equal:
                    return(median);

                case CompareResult.Less:
                    low = median + 1;
                    break;

                case CompareResult.Greater:
                    hi = median - 1;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            return(~low);
        }
Esempio n. 7
0
 private static void Quick_Recursive <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int len)
 {
     if (len > 1)
     {
         T   pivot = get(start);
         int i     = start;
         int j     = start + len - 1;
         int k     = j;
         while (i <= j)
         {
             if (compare(get(j), pivot) == Comparison.Less)
             {
                 T temp = get(i);
                 set(i++, get(j));
                 set(j, temp);
             }
             else if (compare(get(j), pivot) == Comparison.Equal)
             {
                 j--;
             }
             else
             {
                 T temp = get(k);
                 set(k--, get(j));
                 set(j--, temp);
             }
         }
         Quick_Recursive(compare, get, set, start, i - start);
         Quick_Recursive(compare, get, set, k + 1, start + len - (k + 1));
     }
 }
Esempio n. 8
0
        public bool TryFindValueAt(GetIndex <K> point, out T value)
        {
            var parent    = _root;
            int dimension = -1;

            do
            {
                if (parent == null)
                {
                    value = default(T);
                    return(false);
                }
                else if (AreEqual(point, this._locate(parent.Value)))
                {
                    value = parent.Value;
                    return(true);
                }

                // Keep searching
                dimension = (dimension + 1) % _dimensions;

                if (this._compareKey(point(dimension), this._locate(parent.Value)(dimension)) == (Less | Equal))
                {
                    parent = parent.LeftChild;
                }
                else
                {
                    parent = parent.RightChild;
                }
            }while (true);
        }
Esempio n. 9
0
 /// <summary>Sorts an entire array in non-decreasing order using the slow sort algorithm.</summary>
 /// <typeparam name="T">The type of objects stored within the array.</typeparam>
 /// <param name="compare">The method of compare for the sort.</param>
 /// <param name="array">The array to be sorted.</param>
 /// <remarks>Runtime: Omega(n), average(n*n!), O(infinity). Memory: in place. Stablity: no.</remarks>
 public static void Bogo <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
 {
     while (!BogoCheck(compare, get, set, start, end))
     {
         Shuffle(get, set, start, end);
     }
 }
Esempio n. 10
0
        // load DLL
        private void loadDllButton_Click(object sender, RoutedEventArgs e)
        {
            if (!csvFlag)
            {
                MessageBox.Show("add csv path");
                return;
            }
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.InitialDirectory = "c:\\";
            dialog.Filter           = "DLL Files(*.dll)| *.dll";
            dialog.FilterIndex      = 2;
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == true)
            {
                int hModule = LoadLibrary(dialog.FileName);
                //delegate
                IntPtr func  = GetProcAddress(hModule, "CreateAlgorithem");
                IntPtr func2 = GetProcAddress(hModule, "RunAlgorithem");
                IntPtr func3 = GetProcAddress(hModule, "GetVectorSize");
                IntPtr func4 = GetProcAddress(hModule, "GetByIndex");
                IntPtr func5 = GetProcAddress(hModule, "GetDataVectorSize"); // Mustly use for minCircle alg
                IntPtr func6 = GetProcAddress(hModule, "GetDataByIndex");

                // func
                Create   maker          = (Create)Marshal.GetDelegateForFunctionPointer(func, typeof(Create));
                Run      runner         = (Run)Marshal.GetDelegateForFunctionPointer(func2, typeof(Run));
                Size     sizer          = (Size)Marshal.GetDelegateForFunctionPointer(func3, typeof(Size));
                GetIndex indexer        = (GetIndex)Marshal.GetDelegateForFunctionPointer(func4, typeof(GetIndex));
                Size     circle_sizer   = (Size)Marshal.GetDelegateForFunctionPointer(func5, typeof(Size));
                GetIndex circle_indexer = (GetIndex)Marshal.GetDelegateForFunctionPointer(func6, typeof(GetIndex));
                // test
                maker();
                runner();
                int           size        = sizer();
                int           circle_size = circle_sizer();
                List <string> list        = new List <string>();
                List <string> circle_list = new List <string>();
                // test
                for (int i = 0; i < size; i++)
                {
                    string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(indexer());
                    list.Add(str);
                }

                if (circle_size > 0)
                {
                    for (int i = 0; i < circle_size; i++)
                    {
                        string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(circle_indexer());
                        circle_list.Add(str);
                    }
                }

                if (list.Count > 0)
                {
                    (Application.Current as App).Graph_VM.add_Algo_Detect(list);
                }
            }
        }
Esempio n. 11
0
 /// <summary>Sorts an entire array in a randomized order.</summary>
 /// <typeparam name="T">The type of objects stored within the array.</typeparam>
 /// <param name="get">The get accessor of the structure to shuffle.</param>
 /// <param name="set">The set accessor of the structure to shuffle.</param>
 /// <param name="start">The starting index of the shuffle.</param>
 /// <param name="end">The ending index of the shuffle.</param>
 /// <remarks>Runtime: O(n). Memory: in place. Stable: N/A (not a comparative sort).</remarks>
 public static void Shuffle <T>(System.Random random, GetIndex <T> get, SetIndex <T> set, int start, int end)
 {
     for (int i = start; i < end; i++)
     {
         int randomIndex = random.Next(start, end);
         T   temp        = get(i);
         set(i, get(randomIndex));
         set(randomIndex, temp);
     }
 }
Esempio n. 12
0
 /// <summary>Performs a binary search to find the index where a specific value fits in indexed, sorted items.</summary>
 /// <typeparam name="T">The generic type of the set of values.</typeparam>
 /// <param name="get">Indexer delegate.</param>
 /// <param name="length">The number of indexed items.</param>
 /// <param name="compare">Comparison delegate.</param>
 /// <returns>The index where the specific value fits into the index, sorted items.</returns>
 public static int Binary <T>(GetIndex <T> get, int length, CompareToKnownValue <T> compare)
 {
     _ = get ?? throw new ArgumentNullException(nameof(get));
     _ = compare ?? throw new ArgumentNullException(nameof(compare));
     if (length <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(length), length, "!(" + nameof(length) + " > 0)");
     }
     return(Binary(get, 0, length, compare));
 }
Esempio n. 13
0
 private static bool BogoCheck <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
 {
     for (int i = start; i < end - 1; i++)
     {
         if (compare(get(i), get(i + 1)) == Comparison.Greater)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 14
0
File: Sort.cs Progetto: GSKSan/Towel
 internal static bool BogoCheck <T>(Compare <T> compare, GetIndex <T> get, int start, int end)
 {
     for (int i = start; i <= end - 1; i++)
     {
         if (compare(get(i), get(i + 1)) == CompareResult.Greater)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 15
0
 public T FindValueAt(GetIndex <K> point)
 {
     if (TryFindValueAt(point, out T value))
     {
         return(value);
     }
     else
     {
         return(default(T));
     }
 }
Esempio n. 16
0
        public bool AreEqual(GetIndex <K> a, GetIndex <K> b)
        {
            for (var index = 0; index < this._dimensions; index++)
            {
                if (!(this._compareKey(a(index), b(index)) == Equal))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 17
0
 public void RefreshShow()
 {
     IsDirtyShow = false;
     if (GetIndex != null)
     {
         Index = GetIndex.Invoke();
     }
     for (int i = 0; i < Controls.Count; i++)
     {
         var item = Controls[i];
         item.ShowDirect(i == Index, false, false, true);
     }
 }
        public async Task <IActionResult> Index()
        {
            var getAbout = new GetIndex();
            var under    = await getAbout.GetAbout();

            var indViewModel = new IndexViewModel()
            {
                Ind   = under,
                Title = "About"
            };

            return(View(indViewModel));
        }
Esempio n. 19
0
 /// <summary>Sorts an entire array in non-decreasing order using the insertion sort algorithm.</summary>
 /// <typeparam name="T">The type of objects stored within the array.</typeparam>
 /// <param name="compare">Returns positive if left greater than right.</param>
 /// <param name="get">Delegate for getting a value at a specified index.</param>
 /// <param name="set">Delegate for setting a value at a specified index.</param>
 /// <param name="start">The starting index of the sort.</param>
 /// <param name="end">The ending index of the sort.</param>
 /// <remarks>Runtime: Omega(n), average(n^2), O(n^2). Memory: in place. Stablity: yes.</remarks>
 public static void Insertion <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
 {
     for (int i = start + 1; i < end; i++)
     {
         T   temp = get(i);
         int j;
         for (j = i; j > start && compare(get(j - 1), temp) == Comparison.Greater; j--)
         {
             set(j, get(j - 1));
         }
         set(j, temp);
     }
 }
Esempio n. 20
0
        internal K DistanceSquaredBetweenPoints(GetIndex <K> a, GetIndex <K> b)
        {
            K distance = this._zero;

            // Return the absolute distance bewteen 2 hyper points
            for (var dimension = 0; dimension < _dimensions; dimension++)
            {
                K distOnThisAxis        = this._subtract(a(dimension), b(dimension));
                K distOnThisAxisSquared = this._multiply(distOnThisAxis, distOnThisAxis);

                distance = this._add(distance, distOnThisAxisSquared);
            }

            return(distance);
        }
Esempio n. 21
0
 /// <summary>Sorts an entire array in non-decreasing order using the bubble sort algorithm.</summary>
 /// <typeparam name="T">The type of objects stored within the array.</typeparam>
 /// <param name="compare">The compare function (returns a positive value if left is greater than right).</param>
 /// <param name="get">Delegate for getting a value at a specified index.</param>
 /// <param name="set">Delegate for setting a value at a specified index.</param>
 /// <param name="start">The starting index of the sort.</param>
 /// <param name="end">The ending index of the sort.</param>
 /// <remarks>Runtime: Omega(n), average(n^2), O(n^2). Memory: in place. Stability: yes.</remarks>
 public static void Bubble <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
 {
     for (int i = start; i < end; i++)
     {
         for (int j = start; j < end - 1; j++)
         {
             if (compare(get(j), get(j + 1)) == Comparison.Greater)
             {
                 T temp = get(j + 1);
                 set(j + 1, get(j));
                 set(j, temp);
             }
         }
     }
 }
Esempio n. 22
0
 /// <summary>Performs a binary search to find the index where a specific value fits in indexed, sorted items.</summary>
 /// <param name="get">Indexer delegate.</param>
 /// <param name="length">The number of indexed items.</param>
 /// <param name="compare">Comparison delegate.</param>
 /// <returns>The index where the specific value fits into the index, sorted items.</returns>
 public static int Binary <T>(GetIndex <T> get, int length, CompareToExpectedValue <T> compare)
 {
     if (get is null)
     {
         throw new ArgumentNullException(nameof(get));
     }
     if (compare is null)
     {
         throw new ArgumentNullException(nameof(compare));
     }
     if (length <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(length), length, "!(" + nameof(length) + " > 0)");
     }
     return(Binary(get, 0, length, compare));
 }
Esempio n. 23
0
 /// <summary>Sorts an entire array in non-decreasing order using the selection sort algoritm.</summary>
 /// <typeparam name="T">The type of objects stored within the array.</typeparam>
 /// <param name="compare">Returns negative if the left is less than the right.</param>
 /// <param name="get">Delegate for getting a value at a specified index.</param>
 /// <param name="set">Delegate for setting a value at a specified index.</param>
 /// <param name="start">The starting index of the sort.</param>
 /// <param name="end">The ending index of the sort.</param>
 /// <remarks>Runtime: Omega(n^2), average(n^2), O(n^2). Memory: in place. Stablity: no.</remarks>
 public static void Selection <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
 {
     for (int i = 0; i < end - 1; i++)
     {
         int min_idx = i;
         for (int j = i + 1; j < end; j++)
         {
             if (compare(get(j), get(min_idx)) == Comparison.Less)
             {
                 min_idx = j;
             }
         }
         T temp = get(min_idx);
         set(min_idx, get(i));
         set(i, temp);
     }
 }
Esempio n. 24
0
        /// <summary>Sorts an entire array in non-decreasing order using the heap sort algorithm.</summary>
        /// <typeparam name="T">The type of objects stored within the array.</typeparam>
        /// <param name="compare">The method of compare for the sort.</param>
        /// <param name="get">Delegate for getting a value at a specified index.</param>
        /// <param name="set">Delegate for setting a value at a specified index.</param>
        /// <param name="start">The starting index of the sort.</param>
        /// <param name="end">The ending index of the sort.</param>
        /// <remarks>Runtime: Omega(n*ln(n)), average(n*ln(n)), O(n^2). Memory: in place. Stablity: no.</remarks>
        public static void Heap <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int end)
        {
            int heapSize = end - start;

            for (int i = (heapSize - 1) / 2; i >= 0; i--)
            {
                MaxHeapify(compare, get, set, heapSize, i);
            }
            for (int i = end - 1; i > start; i--)
            {
                T temp = get(0);
                set(0, get(i));
                set(i, temp);
                heapSize--;
                MaxHeapify(compare, get, set, heapSize, 0);
            }
        }
Esempio n. 25
0
        private static void Slow_Recursive <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int i, int j)
        {
            if (i >= j)
            {
                return;
            }
            int m = (i + j) / 2;

            Slow_Recursive(compare, get, set, i, m);
            Slow_Recursive(compare, get, set, m + 1, j);
            if (compare(get(m), get(j)) == Comparison.Less)
            {
                T temp = get(j);
                set(j, get(m));
                set(m, temp);
            }
            Slow_Recursive(compare, get, set, i, j - 1);
        }
        public static string printtestHas_getWLName(string id, string zfj, string erweima, bool iscd, string getWLName, string getWLName123)
        {
            GetModel getmodel = new GetModel();

            var print = px_PrintBLL.Querypx_PrintList().Where(s => s.PXID.Equals(erweima)).ToList();

            if (print.Count > 0)
            {
                List <GetIndex> pxlist = new List <GetIndex>();
                foreach (var item in print)
                {
                    GetIndex gi = new GetIndex();
                    gi.订单号   = item.orderid;
                    gi.车身号   = item.orderid;
                    gi.主副驾   = item.XF;
                    gi.等级    = item.cartype;
                    gi.零件号   = item.LingjianHao;
                    gi.零件号描述 = item.ordername;
                    pxlist.Add(gi);
                }
                bool flag = CallPrint.PrintM(pxlist, erweima, getWLName123, getWLName, false);
                if (flag)
                {
                    return("1");
                }

                return("0");
            }
            else
            {
                List <GetIndex> pxlist     = getmodel.GetIndexWJ(id, zfj);
                List <GetIndex> searchlist = new List <GetIndex>();
                searchlist = pxlist.Where(s => s.mg_partorder_ordertype == 4).ToList();
                searchlist.AddRange(pxlist.ToList());
                pxlist = searchlist;
                bool flag = CallPrint.PrintM(pxlist, erweima, zfj + id, getWLName);
                if (flag)
                {
                    return("1");
                }

                return("0");
            }
        }
Esempio n. 27
0
        public bool TryFindValue(T value, out GetIndex <K> point)
        {
            if (_root == null)
            {
                point = null;
                return(false);
            }

            // First-in, First-out list of nodes to search
            var nodesToSearch = new System.Collections.Generic.Queue <Node>();

            nodesToSearch.Enqueue(_root);

            while (nodesToSearch.Count > 0)
            {
                var nodeToSearch = nodesToSearch.Dequeue();

                if (nodeToSearch.Value.Equals(value))
                {
                    point = this._locate(nodeToSearch.Value);
                    return(true);
                }
                else
                {
                    if (nodeToSearch.LeftChild != null)
                    {
                        nodesToSearch.Enqueue(nodeToSearch.LeftChild);
                    }
                    if (nodeToSearch.RightChild != null)
                    {
                        nodesToSearch.Enqueue(nodeToSearch.RightChild);
                    }
                }
            }

            point = null;
            return(false);
        }
Esempio n. 28
0
        public GetIndex <T> GetClosestPoint(GetIndex <T> toPoint, int length)
        {
            T[] closest = new T[length];

            for (var dimension = 0; dimension < length; dimension++)
            {
                if (this._compareT(_minPoint[dimension], toPoint(dimension)) == Greater)
                {
                    closest[dimension] = _minPoint[dimension];
                }
                else if (this._compareT(_maxPoint[dimension], toPoint(dimension)) == Less)
                {
                    closest[dimension] = _maxPoint[dimension];
                }
                else
                {
                    // Point is within rectangle, at least on this dimension
                    closest[dimension] = toPoint(dimension);
                }
            }

            return(closest.WrapGetIndex());
        }
Esempio n. 29
0
        public Node[] RadialSearch(GetIndex <K> center, K radius, int count)
        {
            var nearestNeighbours = new NearestNeighbourList <Node, K>(count, this._minValue, this._compareKey);

            AddNearestNeighbours(
                _root,
                center,
                HyperRect <K> .Infinite(_dimensions, this._minValue, this._maxValue, this._compareKey),
                0,
                nearestNeighbours,
                this._multiply(radius, radius));

            count = nearestNeighbours.Count;

            var neighbourArray = new Node[count];

            for (var index = 0; index < count; index++)
            {
                neighbourArray[count - index - 1] = nearestNeighbours.RemoveFurtherest();
            }

            return(neighbourArray);
        }
Esempio n. 30
0
 private static void Merge_Recursive <T>(Compare <T> compare, GetIndex <T> get, SetIndex <T> set, int start, int len)
 {
     if (len > 1)
     {
         int half = len / 2;
         Merge_Recursive(compare, get, set, start, half);
         Merge_Recursive(compare, get, set, start + half, len - half);
         T[] sorted = new T[len];
         int i      = start;
         int j      = start + half;
         int k      = 0;
         while (i < start + half && j < start + len)
         {
             if (compare(get(i), get(j)) == Comparison.Greater)
             {
                 sorted[k++] = get(j++);
             }
             else
             {
                 sorted[k++] = get(i++);
             }
         }
         for (int h = 0; h < start + half - i; h++)
         {
             sorted[k + h] = get(i + h);
         }
         for (int h = 0; h < start + len - j; h++)
         {
             sorted[k + h] = get(j + h);
         }
         for (int h = 0; h < len; h++)
         {
             set(start + h, sorted[0 + h]);
         }
     }
 }
Esempio n. 31
0
        public Node[] GetNearestNeighbours(GetIndex <K> point, int count)
        {
            if (count > Count)
            {
                count = Count;
            }

            if (count < 0)
            {
                throw new ArgumentException("Number of neighbors cannot be negative");
            }

            if (count == 0)
            {
                return(new Node[0]);
            }

            var neighbours = new Node[count];

            var nearestNeighbours = new NearestNeighbourList <Node, K>(count, this._minValue, this._compareKey);

            var rect = HyperRect <K> .Infinite(_dimensions, this._minValue, this._maxValue, this._compareKey);

            AddNearestNeighbours(_root, point, rect, 0, nearestNeighbours, this._maxValue);

            count = nearestNeighbours.Count;

            var neighbourArray = new Node[count];

            for (var index = 0; index < count; index++)
            {
                neighbourArray[count - index - 1] = nearestNeighbours.RemoveFurtherest();
            }

            return(neighbourArray);
        }