/// <summary> /// Default function /// <para> /// Calculates the length of a <see cref="DynamicList"/> and returns it as an <see cref="Integer"/> /// </para> /// </summary> /// <param name="list_expr"> The target <see cref="DynamicList"/></param> /// <returns> <see cref="Integer"/> which has the list's length as value</returns> private static Variable lengthFunction(Expression list_expr) { // evaluate every expression DynamicList list = list_expr.evaluate() as DynamicList; // length return(list.length()); }
public override int compare(Variable other) { Debugging.assert(hasSameParent(other)); DynamicList other_list = (DynamicList)other; if (length().compare(other_list.length()) != 0) { return(length().compare(other_list.length())); } List <Variable> other_list_value = other.getValue(); if (_list.Where((t, i) => other_list_value[i] != t).Any()) { return(-1); } return(0); }
/// <summary> /// Append a value to the end of a list /// </summary> /// <param name="list_expr"> The list</param> /// <param name="value_expr"> The value</param> /// <returns> <see cref="NullVar"/> (equivalent of null/void)</returns> private static NullVar appendValue(Expression list_expr, Expression value_expr) { // extract list Variable list_var = list_expr.evaluate(); Debugging.assert(list_var is DynamicList); // TypeError DynamicList list = list_var as DynamicList; // index Integer index = list.length(); Expression index_expr = new Expression(index.getValue().ToString()); // this should definitely be ok // insert return(insertValueAt(list_expr, index_expr, value_expr)); }
public void insert(Parser.Integer index, Parser.Variable value) { list.insertValue(value, index); float time_animation = 2f; GameObject[] obj_list = new GameObject[list.length().getValue() - index.getValue() - 1]; for (int i = index.getValue() + 1, u = 0; i < list.length().getValue(); i++, u++) { obj_list[u] = list_dict[list.atIndex(new Parser.Integer(i)).getName()]; } StartCoroutine(Animation.insertAnimation(obj_list, value.getName(), new Vector3(1, 0, 0), time_animation, 1, this)); }
public void Start() { GraphicalList graphList = gameObject.AddComponent <GraphicalList>(); List <int> testList = new List <int>() { 5, 4, 3, 2, 1 }; Parser.DynamicList list_test = Parser.VariableUtils.createDynamicList(testList); (list_test.atIndex(new Parser.Integer(0))).setName("int1"); (list_test.atIndex(new Parser.Integer(1))).setName("int2"); (list_test.atIndex(new Parser.Integer(2))).setName("int3"); (list_test.atIndex(new Parser.Integer(3))).setName("int4"); (list_test.atIndex(new Parser.Integer(4))).setName("int5"); Dictionary <string, GameObject> list_dict_test = new Dictionary <string, GameObject>(); graphList.list_dict = list_dict_test; graphList.list = list_test; graphList.drawObject(); // To update the dictionary /* INSERT DEMO * Parser.Integer insert_numb = new Parser.Integer(5); * insert_numb.setName("int6"); * * graphList.insert(new Parser.Integer(2), insert_numb); // tester avec les index qui se trouvent a l'extremite */ /* REMOVE DEMO * graphList.remove(new Parser.Integer(1)); */ /* SWAP DEMO * graphList.swap(new Parser.Integer(1), new Parser.Integer(4)); */ /*float t = Time.time; * * while (t < Time.time - 2) * { * * }*/ //Thread.Sleep(1000); //Debug.Log("Animation finished!"); StartCoroutine(testTimeDelay()); /* BUBBLE SORT DEMO * StartCoroutine(bubbleSort()); */ IEnumerator testTimeDelay() { graphList.swap(new Parser.Integer(1), new Parser.Integer(4)); yield return(new WaitForSeconds(10f)); graphList.remove(new Parser.Integer(1)); } IEnumerator bubbleSort() { for (int j = 0; j <= list_test.length().getValue() - 2; j++) { for (int i = 0; i <= list_test.length().getValue() - 2; i++) { if (list_test.atIndex(new Parser.Integer(i)).getValue() > list_test.atIndex(new Parser.Integer(i + 1)).getValue()) { graphList.swap(new Parser.Integer(i), new Parser.Integer(i + 1)); yield return(new WaitForSeconds(2.5f)); } } } } /*IEnumerator TimeDelayFunction() * { * * for (int j = 0; j <= list_test.length().getValue() - 2; j++) * { * for (int i = 0; i <= list_test.length().getValue() - 2; i++) * { * if (list_test.atIndex(new Parser.Integer(i)).getValue() > list_test.atIndex(new Parser.Integer(i + 1)).getValue()) * { * graphList.swap(new Parser.Integer(i), new Parser.Integer(i + 1)); * yield return new WaitForSeconds(1f); * } * } * } * /* * int smallest; * * for (int i = 0; i < list_test.length().getValue() - 1; i++) * { * smallest = i; * for (int j = i + 1; j < list_test.length().getValue(); j++) * { * if (list_test.atIndex(new Parser.Integer(j)).getValue() < list_test.atIndex(new Parser.Integer(smallest)).getValue()) * { * smallest = j; * } * } * * graphList.swap(new Parser.Integer(smallest), new Parser.Integer(i)); * yield return new WaitForSeconds(1f); * } * * Debug.Log("List is sorted !"); * } */ }