/// <summary> /// Sorts the list of Nodes. /// </summary> public void Sort() { GameObject runner = null, leftNode = null; if (theList.Count() < 2) { return; } // Execute the sorting algorithm. O(n^2) for (int i = theList.Count() - 1; i > 0; i--) { leftNode = theList.GetComponent <NodeList>().NodeAtIndex(0); for (int j = 1; j <= i; j++) { runner = theList.GetComponent <NodeList>().NodeAtIndex(j); // Bubble sort swaps on every instance of i+1 > i. if (leftNode.GetComponent <Node>().nodeValue > runner.GetComponent <Node>().nodeValue) { theList.Swap(leftNode.GetComponent <Node>().nodeIndex, runner.GetComponent <Node>().nodeIndex); Debug.Log("Bubble sort: " + theList.ToString()); } leftNode = runner; } // Reset temp variables. leftNode = null; } }
private void AnalyzeNodes() { var openBracketsCount = nodes.Count(x => x.NodeType == NodeType.OpenBracket); var closeBracketsCount = nodes.Count(x => x.NodeType == NodeType.CloseBracket); var exception = new Exception("Could not parse where clause correctly"); if (openBracketsCount != closeBracketsCount) { throw exception; } for (int i = 0; i < nodes.Count; i++) { //The order should be field condition value operator field condition value .... if (nodes[i].NodeType == NodeType.Field) { if (nodes[i + 1].NodeType != NodeType.Condition || !(nodes[i + 2].NodeType == NodeType.Constant || nodes[i + 2].NodeType == NodeType.Parameter || nodes[i + 2].NodeType == NodeType.ArrayOfValues)) { throw exception; } } //Next node should be operator or end, skip close brackets if (nodes[i].NodeType == NodeType.Constant || nodes[i].NodeType == NodeType.Parameter || nodes[i].NodeType == NodeType.ArrayOfValues) { bool found = true; for (int j = i + 1; j < nodes.Count; j++) { if (nodes[j].NodeType == NodeType.CloseBracket) { continue; } if (nodes[j].NodeType == NodeType.Operator) { break; } if (nodes[j].NodeType == NodeType.Field || nodes[j].NodeType == NodeType.Condition || nodes[j].NodeType == NodeType.Parameter || nodes[j].NodeType == NodeType.Constant || nodes[j].NodeType == NodeType.ArrayOfValues || nodes[j].NodeType == NodeType.OpenBracket) { found = false; break; } } if (!found) { throw exception; } } } }
/// <summary> /// Sorts the list of Nodes. /// </summary> public void Sort() { GameObject runner = null, currentNode = null; int currentNodeValue = int.MaxValue; // Execute the sorting algorithm. O(n^2) for (int i = 0; i < theList.Count(); i++) { // Current node = theList[i] currentNode = theList.GetComponent <NodeList>().NodeAtIndex(i); currentNodeValue = currentNode.GetComponent <Node>().nodeValue; // Runner node = theList[i - 1] runner = currentNode.GetComponent <Node>().prevNode; while (runner != null) { if (currentNodeValue < runner.GetComponent <Node>().nodeValue) { // If the current node's value is less than the runner;s, then we keep going. // runnerNode = theList[runnerNode.Index - 1] runner = runner.GetComponent <Node>().prevNode; } else { // If the current node's value is greater than the runner's, // remove the node and place it at the index after the runner's. theList.RemoveAtIndex(i); theList.InsertAtIndex(runner.GetComponent <Node>().nodeIndex + 1, currentNode); break; } } // If we get here, then that means the current value is the smallest in the sorted list. // Insert at the head. if (runner == null) { currentNode = theList.RemoveAtIndex(i); theList.InsertAtIndex(0, currentNode); } // Reset temp variables. currentNode = runner = null; currentNodeValue = int.MaxValue; Debug.Log("Insertion sort: " + theList.ToString()); } }
public MixinDefinition(string name, NodeList<Rule> parameters, List<Node> rules) { Name = name; Params = parameters; Rules = rules; Selectors = new NodeList<Selector> {new Selector(new NodeList<Element>(new Element(null, name)))}; _arity = Params.Count; _required = Params.Count(r => String.IsNullOrEmpty(r.Name) || r.Value == null); }
public MixinDefinition(string name, NodeList <Rule> parameters, NodeList rules) { Name = name; Params = parameters; Rules = rules; Selectors = new NodeList <Selector> { new Selector(new NodeList <Element>(new Element(null, name))) }; _arity = Params.Count; _required = Params.Count(r => String.IsNullOrEmpty(r.Name) || r.Value == null); }
public MixinDefinition(string name, NodeList<Rule> parameters, NodeList rules, Condition condition, bool variadic) { Name = name; Params = parameters; Rules = rules; Condition = condition; Variadic = variadic; Selectors = new NodeList<Selector> {new Selector(new NodeList<Element>(new Element(null, name)))}; _arity = Params.Count; _required = Params.Count(r => String.IsNullOrEmpty(r.Name) || r.Value == null); }
internal void AssertTagRulesViolation(List <IRenderable> rootNodeList) { if (!(rootNodeList[0] is Layout)) { throw new SyntaxException(Liquid.ResourceManager.GetString("LayoutTagMustBeFirstTagException")); } if (NodeList.Count(o => o is Layout) > 0) { throw new SyntaxException(Liquid.ResourceManager.GetString("LayoutTagCanBeUsedOneException")); } }
internal override void AssertTagRulesViolation(List <object> rootNodeList) { if (!(rootNodeList[0] is Extends)) { throw new SyntaxException(Liquid.ResourceManager.GetString("ExtendsTagMustBeFirstTagException")); } NodeList.ForEach(n => { if (!((n is string && ((string)n).IsNullOrWhiteSpace()) || n is Block || n is Comment || n is Extends)) { throw new SyntaxException(Liquid.ResourceManager.GetString("ExtendsTagUnallowedTagsException")); } }); if (NodeList.Count(o => o is Extends) > 0) { throw new SyntaxException(Liquid.ResourceManager.GetString("ExtendsTagCanBeUsedOneException")); } }
internal override void AssertTagRulesViolation(List <object> rootNodeList) { if (!(rootNodeList[0] is Extends)) { throw new SyntaxException("Liquid Error - 'extends' must be the first tag in an extending template"); } NodeList.ForEach(n => { if (!((n is string && ((string)n).IsNullOrWhiteSpace()) || n is Block || n is Comment || n is Extends)) { throw new SyntaxException("Liquid Error - Only 'comment' and 'block' tags are allowed in an extending template"); } }); if (NodeList.Count(o => o is Extends) > 0) { throw new SyntaxException("Liquid Error - 'extends' tag can be used only once"); } }
public int NumberOfActiveNodes() { return(NodeList.Count(x => x.Index >= 0)); }