// recursive decrypt string method internal void DecryptStrings ( DecryptCtrl Ctrl ) { if (GetType() == typeof(PdfDictionary)) { if ((PdfDictionary)this != Ctrl.EncryptionDict) { foreach (PdfKeyValue KeyValue in ((PdfDictionary)this).KeyValueArray) { KeyValue.Value.DecryptStrings(Ctrl); } } } else if (GetType() == typeof(PdfArray)) { foreach (PdfBase ArrayItem in ((PdfArray)this).Items) { ArrayItem.DecryptStrings(Ctrl); } } else if (GetType() == typeof(PdfString)) { // NOTE: some PDF file have unused objects that are not encrypted try { ((PdfString)this).StrValue = Ctrl.Encryption.DecryptByteArray(Ctrl.ObjectNumber, ((PdfString)this).StrValue); } catch {} } return; }
public int FindShortestSubArray(int[] nums) { var constNum = (int)5e5; var countArray = new ArrayItem[constNum]; var maxCount = 1; for (var i = 0; i < nums.Length; i++) { var curNum = nums[i]; if (countArray[curNum] == null) { countArray[curNum] = new ArrayItem() { Count = 1, LeftIndex = i, RightIndex = i } } ; else { countArray[curNum].Count++; countArray[curNum].RightIndex = i; maxCount = Math.Max(maxCount, countArray[curNum].Count); } } return(countArray.Where(i => i != null && i.Count == maxCount).Min(i => i.RightIndex - i.LeftIndex + 1)); }
public StudentAdministration(int EntryNr, int H) { entryNr = EntryNr; neighbourhood = H; Students = new ArrayItem[EntryNr]; collisions = 0; }
static int Copy <T>(ref ArrayItem item, T copy) where T : ICopy { int allCount = item.SourceOffset + item.SourceCount; if (allCount < item.Source.Length) { return(Copy_Copy(ref item, copy)); } else { int n = copy.Copy( item.Source.AsSpan(item.SourceOffset, item.Source.Length - item.SourceOffset), item.Des.AsSpan(item.DesOffset, item.DesCount)); Add(ref item, n); if (item.SourceOffset == item.Source.Length) { item.SourceOffset = 0; return(n + Copy_Copy(ref item, copy)); } else { return(n); } } }
static void Main(string[] args) { //!!!!-------Manual inputting----!!!!! ArrayItem arrayItem = new ArrayItem(); arrayItem.InputFunc(); arrayItem.DeleteMaxAndMin(); Console.WriteLine("--------------Initial Array--------------"); arrayItem.OutputFunc(); Console.WriteLine("--------------Bubble sort--------------"); BubbleSort bubble = new BubbleSort(); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); bubble.bubbleSort(ref arrayItem.Array); watch.Stop(); Console.WriteLine($"-Execution Time: {watch.ElapsedMilliseconds} ms-\n"); arrayItem.OutputFunc(); Console.WriteLine("--------------Selection sort--------------"); SelectionSort selection = new SelectionSort(); watch = new System.Diagnostics.Stopwatch(); watch.Start(); selection.selectionSort(ref arrayItem.Array); watch.Stop(); Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms\n"); arrayItem.OutputFunc(); }
/* * ArrItem ::= [ItemList] | [] * ItemList ::= SingleItem OptList * OptList ::= , ItemList | epsilon * SingleItem ::= Num | ArrItem */ private ArrayItem ArrItem() { ArrayItem arrayItem = new ArrayItem(); if (CheckType(TokenType.OpenBracket)) { MatchType(TokenType.OpenBracket); if (CheckType(TokenType.CloseBracket)) { MatchType(TokenType.CloseBracket); return(arrayItem); } arrayItem.Items.AddRange(ItemList()); if (!CheckType(TokenType.CloseBracket)) { Error(); } MatchType(TokenType.CloseBracket); } else { Error(); } return(arrayItem); }
/* * List ::= [ListElements] | [] * ListElements ::= ListElement OptList * OptList ::= , ListElements * ListElement ::= List | Number */ public static ArrayItem ListNTerm(string s, ref int pos) { ArrayItem arrayItem = new ArrayItem(); Console.WriteLine("ListNTerm"); if (s[pos] == '[') { ++pos; if (s[pos] == ']') { return(arrayItem); } arrayItem.Items.AddRange(ListElementsNTerm(s, ref pos)); if (s[pos] == ']') { ++pos; } else { throw new ArgumentException($"[ListNTerm(inner)] Unexpected `{s[pos]}` got at {pos}"); } } else { throw new ArgumentException($"[ListNTerm] Unexpected `{s[pos]}` got at {pos}"); } return(arrayItem); }
public void TestGetterAndSetter() { ArrayItem item = new ArrayItem(); item.abc = -1; item.dfg = -1; var _memberInfo = typeof(ArrayItem).GetMembers( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .Where(x => x.MemberType == MemberTypes.Field) .Cast <FieldInfo>().ToList(); foreach (var member in _memberInfo) { var action = ReflectionUtils.CreateInstanceFieldSetter(member); action.Invoke(item, 30); } Assert.AreEqual(item.abc, 30); Assert.AreEqual(item.dfg, 30); foreach (var member in _memberInfo) { var action = ReflectionUtils.CreateInstanceFieldGetter(member); Assert.AreEqual(action.DynamicInvoke(item), 30); } }
/* * S -> [S] | ParamList * ParamList -> [S] OptParams | NUM | NUM OptParams * OptParams -> , ParamList | eps * NUM -> int */ private static ArrayItem FromString(string str, ref int pos) { ArrayItem arrayItem = new ArrayItem(); if (str[pos] == '[') { ++pos; while (pos < str.Length && str[pos] != ']') { if (str[pos] == '[') { arrayItem.Items.Add(FromString(str, ref pos)); if (pos >= str.Length) { throw new ArgumentException($"Missing closing parenthesis at pos {str.Length - 1}"); } if (str[pos] != ']') { throw new ArgumentException($"Missing closing parenthesis at pos {pos}"); } ++pos; if (pos < str.Length && str[pos] == ',') { ++pos; } } else if (char.IsDigit(str[pos])) { Console.WriteLine("Processing number"); NumItem tmp = new NumItem(); while (pos < str.Length && char.IsDigit(str[pos])) { tmp.Value *= 10; tmp.Value += int.Parse(str[pos].ToString()); ++pos; } arrayItem.Items.Add(tmp); if (pos < str.Length && str[pos] == ',') { ++pos; } } else { throw new ArgumentException($"Unexpected `{str[pos]}` got at pos {pos}"); } } if (pos >= str.Length && str[str.Length - 1] != ']') { throw new ArgumentException($"Missing closing parenthesis at pos {str.Length - 1}"); } } else { throw new ArgumentException($"Unexpected `{str[pos]}` got at pos {pos}"); } return(arrayItem); }
/// <summary> /// Prevents a default instance of the <see cref="Manager"/> class from being created. /// </summary> private Manager() { const int n = 5000; Array = new IArrayItem[n]; for (int i = 0; i < n; i++) { Array[i] = new ArrayItem(); } }
static void Add(ref ArrayItem item, int n) { item.SourceOffset += n; item.SourceCount -= n; item.DesOffset += n; item.DesCount -= n; }
static int Copy_Copy <T>(ref ArrayItem item, T copy) where T : ICopy { int n = copy.Copy( item.Source.AsSpan(item.SourceOffset, item.SourceCount), item.Des.AsSpan(item.DesOffset, item.DesCount)); Add(ref item, n); return(n); }
public static void ReadArrayItem(this ArrayItem item, string source, bool clearPrevious = false) { if (clearPrevious) { item.Items.Clear(); } int pos = 0; item.Items.AddRange(FromString(source, ref pos).Items); }
static void Main(string[] args) { var arrayCollection = new ArrayItem(); var standardizedArray = arrayCollection.CreateIterator(); var listCollection = new ListItem(); var standardizedList = listCollection.CreateIterator(); PrintItems(standardizedArray); PrintItems(standardizedList); }
/// <summary> /// append object to byte array /// </summary> /// <param name="Ctrl">Output Control</param> public virtual void ToByteArray ( OutputCtrl Ctrl ) { // test for long line Ctrl.TestEol(); // dictionary if (GetType() == typeof(PdfDictionary)) { Ctrl.Add('<'); Ctrl.Add('<'); foreach (PdfKeyValue KeyValue in ((PdfDictionary)this).KeyValueArray) { Ctrl.AppendText(KeyValue.Key); KeyValue.Value.ToByteArray(Ctrl); } Ctrl.Add('>'); Ctrl.Add('>'); } // array else if (GetType() == typeof(PdfArray)) { Ctrl.Add('['); foreach (PdfBase ArrayItem in ((PdfArray)this).Items) { ArrayItem.ToByteArray(Ctrl); } Ctrl.Add(']'); } // PDF string else if (GetType() == typeof(PdfString)) { // convert PDF string to visual display format PdfStringToDisplay(Ctrl, ((PdfString)this).StrValue); } // get text from simple objects else { Ctrl.AppendText(ToString()); } return; }
public void ReduceShouldWork_ForArrays() { var elem1 = new ArrayItem { x = 1, y = new[] { "a", "b" } }; var elem2 = new ArrayItem { x = 1, y = new[] { "c", "d" } }; var result = elem1.ReduceCollectionProperties(elem2); Assert.AreEqual(1, result.x); Assert.IsNotNull(result.y); Assert.AreEqual(4, result.y.Length); Assert.AreEqual("a", result.y.FirstOrDefault()); Assert.AreEqual("d", result.y.LastOrDefault()); }
private IChild[] GetArrayItems(int size) { var stw = m_stopwatches["GetArrayItems"]; stw.Start(); var arr = new IChild[size]; for (var i = 0; i < arr.Length; i++) { arr[i] = new ArrayItem(i); } stw.Stop(); return(arr); }
/// <summary> /// It is assumed that the type "myType" is an enumeration type. The function displays a form in which all enumeration members are displayed. /// The function returns the string value of the chosen item, in the case in which the user aborts the selection an empty string is returned. /// </summary> /// <param name="myType"></param> /// <returns></returns> public static string ChooseItem(Type myType) { Array MyArray; MyArray = Enum.GetValues(myType); List <string> ToDisplay = new List <string>(); foreach (object ArrayItem in MyArray) { string StringToAdd = ArrayItem.ToString(); ToDisplay.Add(StringToAdd); } ChooseListItem MyForm = new ChooseListItem(); int MyNumber = MyForm.ChooseItem(ToDisplay); string ToReturn = (MyNumber == 0) ? "" : ToDisplay[MyNumber - 1]; return(ToReturn); }
public void TestIteration() { RecordItem rec = new RecordItem(); rec.SetValue("age", new IntItem(42)); ArrayItem aa = new ArrayItem(); aa.Add(rec); List <StackItem> items = aa.Items(); Assert.AreEqual(1, items.Count); dynamic item = items[0]; Assert.AreEqual(42, item.GetValue("age").IntValue); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 1) { throw new WrongParameterCountException(this, expected: 1, actual: parameters.Length); } FinalExpression param_1 = parameters [0].EvaluatedValue; if (param_1 is ArrayPointerExpression array_pointer) { ArrayItem item = array_pointer.Array.Shift(); return(new Result(item?.Value ?? new NullExpression())); } else { return(new Result(new NullExpression())); } }
private IEnumerator InsertCoroutine() { // Check if there is any work being done on the heap at the moment if (working == false && size >= 0 && size < CAPACITY) { working = true; Node node = Instantiate(nodePrefab); ArrayItem arrayItem = Instantiate(arrayBox.arrayItemPrefab); // If there is no value input then randomize node's value if (value == null || value == "") { node.Value = UnityEngine.Random.Range(0, 100); } else { node.Value = int.Parse(value); } node.transform.parent = gameObject.transform; items[size] = node; arrayItem.Value = node.Value; arrayItem.Index = size; arrayItem.transform.position = new Vector3(arrayBox.gameObject.transform.position.x + size * arrayItem.transform.localScale.x, arrayBox.gameObject.transform.position.y); arrayItem.transform.parent = arrayBox.gameObject.transform; arrayBox.Items[size] = arrayItem; size++; // Update binary heap tree upon insertion TreeUtils.PlaceNodes(items, size); TreeUtils.AddConnection(connections, items, size, connectionPrefab); // Heapify up upon insertion Coroutine a = StartCoroutine(HeapifyUp()); yield return(a); // Operation complete, set working to false working = false; } }
private void OnEnable() { size = UnityEngine.Random.Range(10, 20); items = new Node[CAPACITY]; connections = new List <Connection>(); TreeUtils.AddNodes(this.gameObject, items, size, nodePrefab); TreeUtils.PlaceNodes(items, size); TreeUtils.AddConnections(connections, items, size, connectionPrefab); arrayBox = gameObject.transform.GetChild(0).GetComponent <ArrayBox>(); arrayBox.Items = new ArrayItem[CAPACITY]; for (int i = 0; i < size; i++) { ArrayItem a = Instantiate(arrayBox.arrayItemPrefab); a.transform.position = new Vector3(arrayBox.gameObject.transform.position.x + i * a.transform.localScale.x, arrayBox.gameObject.transform.position.y); a.transform.parent = arrayBox.gameObject.transform; a.Index = i; a.Value = items[i].Value; arrayBox.Items[i] = a; } }
ArrayItem intersections(Interpreter interp, SphereItem sphere, RayItem ray) { // Compute sphere_to_ray interp.StackPush(ray); interp.Run("'origin' REC@ 0 0 0 Point -"); Vector4Item sphere_to_ray = (Vector4Item)interp.StackPop(); // Compute a interp.StackPush(ray); interp.Run("'direction' REC@ DUP DOT"); DoubleItem a = (DoubleItem)interp.StackPop(); // Compute b interp.StackPush(sphere_to_ray); interp.StackPush(ray); interp.Run("'direction' REC@ DOT 2 *"); DoubleItem b = (DoubleItem)interp.StackPop(); // Compute c interp.StackPush(sphere_to_ray); interp.Run("DUP DOT 1 -"); DoubleItem c = (DoubleItem)interp.StackPop(); float discriminant = b.FloatValue * b.FloatValue - 4.0f * a.FloatValue * c.FloatValue; ArrayItem result = new ArrayItem(); if (discriminant < 0) { return(result); } else { double t1 = (-b.FloatValue - Math.Sqrt(discriminant)) / 2.0f / a.FloatValue; double t2 = (-b.FloatValue + Math.Sqrt(discriminant)) / 2.0f / a.FloatValue; result.Add(new IntersectionItem(t1, sphere)); result.Add(new IntersectionItem(t2, sphere)); return(result); } }
private static void Main(string[] args) { int inpCount = 0; do { try { Console.Write("> "); string s = Console.ReadLine(); Lexer lexer = new Lexer(s); Parser parser = new Parser(lexer); ArrayItem item = parser.ParseArrayItem(); Console.WriteLine(item); Console.WriteLine(new ArrayItem(Item.GetYield(item))); } catch (ArgumentException argumentException) { Console.WriteLine(argumentException.Message); } } while (true); }
/// <summary> /// Attempt to remove a specific item from Array /// </summary> /// <param name="item">Item to try removing</param> /// <returns>True if item was found and removed; False otherwise</returns> public bool Remove(Object item) { ArrayItem target = ArrayItem.Empty(); bool found = true; try { target = items.Where <ArrayItem>(i => i.Value == item).First <ArrayItem>(); } catch (Exception e) { found = false; } // consider not found if target value is null found = found && (target.Value != null); if (found) { items.Remove(target); } return(found); }
public void TestConstruction() { ArrayItem val = new ArrayItem(); Assert.IsNotNull(val); }
public static int Write(ref ArrayItem item) { return(Copy(ref item, new WriteCopy())); }
public static int Read(ref ArrayItem item) { return(Copy(ref item, new ReadCopy())); }
private void SetBlock(int y, Block block) { lock (_lock) { int height = -1; for (int index = 0; index < _array.Count; index++) { var item = GetArrayItem(index); if (height + item.Count >= y) { if (item.Count == 1) { // Replace block item.BlockType = block.Type; } else if (height + 1 == y) { // At start of sequence item.Count--; item = new ArrayItem(block.Type, 1); _array.Insert(index, item); } else if (height + item.Count == y) { // At end of sequence item.Count--; item = new ArrayItem(block.Type, 1); index++; _array.Insert(index, item); } else { // mid sequence var h = item.Count; item.Count = y - height; var lowerItem = new ArrayItem(item.BlockType, y - height - 1); _array.Insert(index, lowerItem); var upperItem = item; upperItem.Count = height + h - y; item = new ArrayItem(block.Type, 1); index++; _array.Insert(index, new ArrayItem(block.Type, 1)); } if (index + 1 < _array.Count) { var nextItem = GetArrayItem(index + 1); if (nextItem.BlockType == item.BlockType) // Combine with above { item.Count += nextItem.Count; _array.Remove(nextItem); } } if (index - 1 >= 0) { var prevItem = GetArrayItem(index - 1); if (prevItem.BlockType == item.BlockType) // Combine with below { prevItem.Count += item.Count; _array.Remove(item); } } break; } height += item.Count; } } }
public GetRecipeListResponse(Recipe recipe, List <Food> List_Food, List <FoodType> List_Food_Type, List <Tag> List_Tag) { id = recipe.id; name = recipe.name; available = recipe.available; if (!recipe.foods.IsNullOrEmpty()) { foods = new List <List <Models.Food.FoodModel> >(); var ArrayListFood = recipe.foods.Split('|'); foreach (var ArrayListItem in ArrayListFood) { List <Models.Food.FoodModel> List_FoodModel = new List <Models.Food.FoodModel>(); var ArrayFoods = ArrayListItem.Split(';'); foreach (var ArrayItem in ArrayFoods) { var Array_Food = ArrayItem.Split(','); Models.Food.FoodModel foodModel = new Models.Food.FoodModel(); foodModel.FoodWeight = Array_Food[1]; var model = List_Food.Find(p => p.id.ToString() == Array_Food[0]); foodModel.FoodName = model == null ? null : model.name; List_FoodModel.Add(foodModel); } foods.Add(List_FoodModel); } } if (!recipe.foodtypes.IsNullOrEmpty()) { foodtypes = new ArrayList(); var ArrayFoodType = recipe.foodtypes.Split('|'); foreach (var ArrayItem in ArrayFoodType) { var model = List_Food_Type.Find(p => p.id.ToString() == ArrayItem); if (model != null) { foodtypes.Add(model.name); } } } if (!recipe.tags.IsNullOrEmpty()) { tags = new ArrayList(); var Arraytag = recipe.tags.Split('|'); List <Models.Tag.TagModel> Listscore = new List <Models.Tag.TagModel>(); List <Tag> ListTags = new List <Tag>(); foreach (var ArrayItem in Arraytag) { var model = List_Tag.Find(p => p.id.ToString() == ArrayItem); if (model != null) { ListTags.Add(model); tags.Add(model.name); } } Listscore = WebApi_Health.BLL.Function.StringHandle.Instance.ConstitutionCalulate(ListTags); score = Listscore; } if (!recipe.images.IsNullOrEmpty()) { images = new ArrayList(); foreach (var item in recipe.images.Split('|')) { images.Add(ImageUrl + item); } } sales = recipe.sales; double?Price = recipe.price.ParseDouble(); price = String.Format("{0:F}", Price); }