private static void Move(this ISimpleList <int> list, int oldIndex, int newIndex) { var value = list[oldIndex]; list.RemoveAt(oldIndex); list.Insert(newIndex, value); }
private static void Swap(this ISimpleList <int> list, int index1, int index2) { var temp = list[index1]; list[index1] = list[index2]; list[index2] = temp; }
public static void BruteForceCreateCnWithLimit(UInt32 n, UInt32 limit, ISimpleList <UInt32> Cn, ISimpleList <UInt32> GnBuffer) { if (n == 0) { throw new ArgumentOutOfRangeException("n", n, "n cannot be 0"); } Cn.Add(1); for (UInt32 potentialCoprime = 2; potentialCoprime <= limit; potentialCoprime++) { Boolean isCoprime = true; for (UInt32 primeIndex = 0; primeIndex < n; primeIndex++) { UInt32 prime = PrimeTable.Values[primeIndex]; if ((potentialCoprime % prime) == 0) { isCoprime = false; if (primeIndex == n - 1) { GnBuffer.Add(potentialCoprime); } break; } } if (isCoprime) { Cn.Add(potentialCoprime); } } }
public void AliasesAndProperties() { ISimpleList list = GoInterface <ISimpleList> .From(new MyCollection(), CastOptions.AllowUnmatchedMethods); list.Add(10); Assert.That(list[0].Equals(10)); Assert.AreEqual(1, list.Count); }
public ListAdapter(ISimpleList inner, Func <IDictionary, TElementAdapter> createItemAdapter) { if (inner == null) { throw new ArgumentNullException("inner"); } _inner = inner.OfType <IDictionary>().Select(createItemAdapter).ToList(); }
public static void SelectSpecificItem <S, V>(this ISimpleList <S> thisList, Func <S, V> selector, V value) where S : ISelectableObject { thisList.ForEach(items => { if (selector(items) !.Equals(value)) //has to be this way still. { items.IsSelected = true; }
public static void MergeSort(this ISimpleList <int> list) { var result = SplitAndMerge(list, 0, list.Count - 1); list.Clear(); foreach (var value in result) { list.Add(value); } }
private static void QuickSort(ISimpleList <int> list, int start, int end) { if (start >= end) { return; } var splitIndex = Split(list, start, end); QuickSort(list, start, splitIndex - 1); QuickSort(list, splitIndex + 1, end); }
public static void BubbleSort(this ISimpleList <int> list) { for (int i = list.Count; i > 1; i--) { for (int j = 1; j < i; j++) { if (list[j - 1] > list[j]) { list.Swap(j - 1, j); } } } }
/// <summary> /// 构造所有公有属性 /// </summary> /// <param name="Columns"></param> /// <returns></returns> protected virtual string GenerateProperties(ISimpleList <Column> Columns) { StringBuilder sBuilder = new StringBuilder(); if (Columns != null) { foreach (var Col in Columns) { GenerateProperty(sBuilder, Col); } } return(sBuilder.ToString()); }
public static void InsertSort(this ISimpleList <int> list) { for (int i = 1; i < list.Count; i++) { for (int j = 0; j < i; j++) { if (list[j] > list[i]) { list.Move(i, j); break; } } } }
public static void HeapSort(this ISimpleList <int> list) { var heap = new SimpleHeap <int>(); foreach (var value in list) { heap.Insert(value); } list.Clear(); while (heap.Count > 0) { list.Add(heap.RemoveTop()); } }
public static void SelectSort(this ISimpleList <int> list) { for (int i = 0; i < list.Count - 1; i++) { var minIndex = i; for (int j = i + 1; j < list.Count; j++) { if (list[minIndex] > list[j]) { minIndex = j; } } list.Swap(minIndex, i); } }
public static void SelectUnselectItem <S>(this ISimpleList <S> thisList, int index) //has to be generics or casting problems. where S : ISelectableObject { int i = 0; foreach (var item in thisList) { if (i == index) { item.SelectUnselectItem(); return; } i++; } throw new ArgumentOutOfRangeException(nameof(index)); }
private static int Split(ISimpleList <int> list, int start, int end) { var pivot = list[end]; var wall = start; for (int i = start; i < end; i++) { if (list[i] > pivot) { continue; } list.Swap(wall, i); wall++; } list.Swap(wall, end); return(wall); }
public string[] Run(ISimpleList <String> array, string[] input) { var instructions = input; foreach (var instruction in instructions) { char command = instruction[0]; String value = instruction.Substring(1); switch (command) { case '+': array.Add(value); break; case '-': array.RemoveAt(Int32.Parse(value)); break; case '~': array.Clear(); break; case '^': var t = value.Split(' '); int index = Int32.Parse(t[0]); String item = t[1]; array.Insert(index, item); break; default: break; } } int lenght = array.Count; var result = new String[lenght]; for (int i = 0; i < lenght; i++) { result[i] = array[i]; } return(result); }
private static IEnumerable <int> SplitAndMerge(ISimpleList <int> list, int start, int end) { if (end < start) { return(Enumerable.Empty <int>()); } if (end == start) { return new [] { list[start] } } ; var middle = (end + start) / 2; var res1 = SplitAndMerge(list, start, middle); var res2 = SplitAndMerge(list, middle + 1, end); var merged = Merge(res1, res2); Debug.WriteLine("Merged: " + String.Join(" ", merged)); return(merged); }
public static UInt32[] BruteForceCreateCn(UInt32 n, UInt32 count, ISimpleList <UInt32> GnBuffer) { if (n == 0) { throw new ArgumentOutOfRangeException("n", n, "n cannot be 0"); } UInt32[] Cn = new UInt32[count]; Cn[0] = 1; UInt32 nextCnIndex = 1; for (UInt32 potentialCoprime = 2; nextCnIndex < count; potentialCoprime++) { Boolean isCoprime = true; for (UInt32 primeIndex = 0; primeIndex < n; primeIndex++) { UInt32 prime = PrimeTable.Values[primeIndex]; if ((potentialCoprime % prime) == 0) { isCoprime = false; if (primeIndex == n - 1) { GnBuffer.Add(potentialCoprime); } break; } } if (isCoprime) { Cn[nextCnIndex++] = potentialCoprime; } } return(Cn); }
public static void ShellSort(this ISimpleList <int> list) { Debug.WriteLine("Initial: " + String.Join(" ", list)); for (int gap = list.Count / 2; gap > 0; gap /= 2) { for (var i = gap; i < list.Count; i++) { var current = list[i]; int j = i - gap; for (; j >= 0; j -= gap) { if (list[j] < current) { break; } list[j + gap] = list[j]; } list[j + gap] = current; Debug.WriteLine($"Insert {current} [{i}] -> [{j + gap}]"); Debug.WriteLine($"Gap {gap}: " + String.Join(" ", list)); } } }
public CsvArray() { A = new CsvArrayAdapter(this, "S"); }
public static void QuickSort(this ISimpleList <int> list) { QuickSort(list, 0, list.Count - 1); }
public Database() { SpecifiedPropertyUpdater.Register(this); Tables = new ArrayAdapter <Table>(this, "Table"); Functions = new ArrayAdapter <Function>(this, "Function"); }
public Association() { SpecifiedPropertyUpdater.Register(this); TheseKeys = new CsvArrayAdapter(this, "ThisKey"); OtherKeys = new CsvArrayAdapter(this, "OtherKey"); }
public Function() { SpecifiedPropertyUpdater.Register(this); Parameters = new ArrayAdapter <Parameter>(this, "Parameter"); }
public Type() { SpecifiedPropertyUpdater.Register(this); Columns = new ArrayAdapter <Column>(this, "Items"); Associations = new ArrayAdapter <Association>(this, "Items"); }
/// <summary> /// /// </summary> public Function() { SpecifiedHelper.Register(this); Parameters = new ArrayHelper <Parameter>(this, "Parameter"); }
/// <summary> /// /// </summary> public Type() { SpecifiedHelper.Register(this); Columns = new ArrayHelper <Column>(this, "Items"); Associations = new ArrayHelper <Association>(this, "Items"); }
public Type() { SpecifiedPropertyUpdater.Register(this); Columns = new ArrayAdapter<Column>(this, "Items"); Associations = new ArrayAdapter<Association>(this, "Items"); }
public Function() { SpecifiedPropertyUpdater.Register(this); Parameters = new ArrayAdapter<Parameter>(this, "Parameter"); }
/// <summary> /// /// </summary> public Database() { SpecifiedHelper.Register(this); Tables = new ArrayHelper <Table>(this, "Table"); Functions = new ArrayHelper <Function>(this, "Function"); }
public Database() { SpecifiedPropertyUpdater.Register(this); Tables = new ArrayAdapter<Table>(this, "Table"); Functions = new ArrayAdapter<Function>(this, "Function"); }
public FruitListManager(ISimpleList <string> list) { m_list = list; }
public int Execute(object pdispOrder, object pdispContext, int lFlags) { IDictionary order = null; IDictionary context = null; try { order = (IDictionary)pdispOrder; context = (IDictionary)pdispContext; ISimpleList lineItems = (ISimpleList)order["items"]; var url = ConfigurationManager.AppSettings.Get("PricingServiceUrl"); if (lineItems != null && lineItems.Count > 0) { var prices = PipelineServiceHelper.CreateWebServiceInstance(url).GetPrices(order["BranchId"].ToString(), order["CustomerId"].ToString(), DateTime.Parse(order["RequestedShipDate"].ToString()), lineItems.Cast <IDictionary>().Select( p => new product() { itemnumber = p["product_id"].ToString(), catalog_id = p["product_catalog"].ToString() }).ToArray()); foreach (object lineItem in lineItems) { IDictionary Item = (IDictionary)lineItem; // Only price new items, filled/subbed/replacement items get their pricing from the mainframe if (Item["MainFrameStatus"].ToString().Length == 0) { var itemPrice = ((KeithLink.Ext.Pipeline.ItemPrice.PipelineService.PriceReturn)prices).Prices.Where(p => p.ItemNumber.Equals(Item["product_id"].ToString())); if (itemPrice.Any()) { var price = Item["Each"].ToString().ToLower() == "true" ? itemPrice.First().PackagePrice : itemPrice.First().CasePrice; if (price == 0) //TODO: Enable this check once we are using a real customer. For now there are far too many products without a price. { throw new Exception("Price Not Found"); } Item["_cy_iadjust_regularprice"] = (decimal)price; Item["cy_placed_price"] = (decimal)price; } else { throw new Exception("Price Not Found"); } } } } //Taxes? Shipping Cost? order["_cy_oadjust_subtotal"] = lineItems.Cast <IDictionary>().Sum(l => (int)l["quantity"] * (decimal)l["cy_placed_price"]); order["_cy_total_total"] = lineItems.Cast <IDictionary>().Sum(l => (int)l["quantity"] * (decimal)l["cy_placed_price"]); return(StatusSuccess); } catch (Exception ex) { Object errorMsg = ex.Message; LogErrorMessage(ex); ((ISimpleList)order["_Basket_Errors"]).Add(ref errorMsg); return(StatusError); } }