public static IEnumerable <T> Browse <T>(QNode node, Func <QNode, T> f) { var r = f(node); return(Enumerable.Repeat(r, ((object)r != null) ? 1 : 0) .Concat(node.Nodes().Skip(1).SelectMany(child => Browse(child, f)))); }
public T RemoveFromFront() { if (_head == null) { return(default(T)); } if (_count == 1) { var tempHead1 = _head; _head = null; _tail = null; _count--; return(tempHead1.Data); } var tempHead = _head; _head = _head.Next; _head.Prev = null; if (_head == null) { _tail = null; } _count--; return(tempHead.Data); }
public static QNode Normalizator4(QNode typedNode, Func <QNode, QNode> normalize) { var s = typedNode.AsString(); switch (s) { case "eq": { var childType = typedNode.C(1).C(0).P("type").QValue().AsString(); var childType2 = typedNode.C(2).C(0).P("type").QValue().AsString(); if (childType == "int" && childType2 == "number") { childType = "number"; } if (childType == "int" && childType2 == "set") { childType = "int-s"; } if (childType == "int" && childType2 == "int-s") { childType = "int-s"; } if (childType == "int-s" && childType2 == "int") { childType = "int-s"; } return(q.Q(typedNode.RawValue(), MetaType("bool", interType: childType), typedNode.Nodes().Skip(1).Select(child => normalize(child) ?? child))); } } return(typedNode); }
public void Unlock() { QNode qnode = myNode.Value; //получаем наше состояние qnode.Locked = false; //скидываем флаг занятости myNode.Value = myPred.Value; //повторно использует ноду предшественника в качестве нового узла для блокировки }
/// <summary> /// The visit new. /// </summary> /// <param name="exp"> /// The exp. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected override Expression VisitNew(NewExpression exp) { // Typisierte Select if (exp.Members == null) { return(exp); } // anonymes Type QNode bindingNode = null; for (int i = 0; i < exp.Members.Count; i++) { var bindingProperty = exp.Members[i].Name; var builder = new MemberNodeBuilder(); builder.Visit(exp.Arguments[i]); var node = new QNode() { Type = NodeType.Member, Value = bindingProperty + ":" + builder.GetPath() }; if (bindingNode == null) { bindingNode = node; } else { bindingNode.Left = node; } } this.Context.Push(bindingNode); return(exp); }
/// <summary> /// The visit member init. /// </summary> /// <param name="exp"> /// The exp. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected override Expression VisitMemberInit(MemberInitExpression exp) { QNode bindingNode = null; for (int i = 0; i < exp.Bindings.Count; i++) { var builder = new MemberNodeBuilder(); builder.Visit(((MemberAssignment)exp.Bindings[i]).Expression); var node = new QNode() { Type = NodeType.Member, Value = exp.Bindings[i].Member.Name + ":" + builder.GetPath() }; if (bindingNode == null) { bindingNode = node; } else { bindingNode.Left = node; } } this.Context.Push(bindingNode); return(exp); }
public static QNode Transform(QNode node, Func <QNode, Func <QNode, QNode>, QNode> f) { if (node == null) { return(null); } var r = f(node, n => Transform(n, f)); if (r != null && r != node) { return(r); } List <QNode> childs = null; var nodes = node.Nodes(); //for (var i = 1; i < nodes.Length; ++i) foreach (var pair in nodes.Select((n, i) => new { child = n, i }).Skip(1)) { var child = pair.child; var r_child = Transform(child, f); if (r_child != null && r_child != child && childs == null) { childs = new List <QNode>(nodes.Take(pair.i)); } childs?.Add(r_child ?? child); } if (childs != null) { return(new QNode(node.RawValue(), childs.ToArray())); } return(node); }
public Action MentorMove() { int Boardstate = HashBoardState(); if (!ListOfStates.ContainsKey(Boardstate)) { UnknownStates++; QNode qn = new QNode(Boardstate); for (int pawn = 0; pawn < 3; pawn++) { AIPawns[pawn].CheckForOptions(); for (int move = 0; move < 5; move++) { if (AIPawns[pawn].Options[move]) { qn.Actions.Add(new Action(pawn, move)); } } } ListOfStates.Add(Boardstate, qn); // MakeMove(qn.Actions[Random.Range(0, qn.Actions.Count)]); } List <Action> SortedList = ListOfStates[Boardstate].Actions.OrderBy(o => o.Score).ToList(); SortedList.Reverse(); usedActions.Add(SortedList[0]); return(SortedList[0]); }
public static void AcceptProjection(QNode node, QNodeConverter visitor) { node.Operand.Accept(visitor); visitor.EnterContext(node); visitor.VisitProjection(node); visitor.LeaveContext(node); }
public Obstacle(GameObject go, Bound b) : base(go, b) { Type = ObjType.Obstacle; isLoaded = false; BelongedNode = null; obsNode = Obss.AddLast(this); }
/// <summary> /// The visit binary. /// </summary> /// <param name="b"> /// The b. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected override Expression VisitBinary(BinaryExpression expression) { NodeType op; if (!NodeType.TryParse(expression.NodeType.ToString(), out op)) { if (expression.NodeType == ExpressionType.OrElse) { op = NodeType.Or; } else if (expression.NodeType == ExpressionType.AndAlso) { op = NodeType.And; } else { throw new Exception(expression.NodeType.ToString()); } } var node = new QNode() { Type = op }; this.Visit(expression.Left); node.Operand = this.Context.Pop(); this.Visit(expression.Right); node.Argument = this.Context.Pop(); this.Context.Push(node); return(expression); }
/// <summary> /// The visit member init. /// </summary> /// <param name="exp"> /// The exp. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected override Expression VisitMemberInit(MemberInitExpression exp) { QNode lambdaNode = null; foreach (var binding in exp.Bindings) { this.Visit(((MemberAssignment)binding).Expression); var bindingNode = this.Context.Pop(); var node = new QNode() { Type = NodeType.Member, Value = binding.Member.Name, Argument = bindingNode }; if (lambdaNode == null) { lambdaNode = node; } else { lambdaNode.Operand = node; } } this.Context.Push(lambdaNode); return(exp); }
public void WriteToFile(Queue queue) { QNode tmd = queue.head; if (queue.head.data % 2 != 0) { StreamWriter writer = new StreamWriter(OddNumberFilePath); while (tmd != queue.tail) { writer.Write(queue.dequeue().data.ToString("X2") + " "); tmd = tmd.next; } writer.Write(queue.dequeue().data.ToString("X2") + " "); writer.Close(); } else { StreamWriter writer = new StreamWriter(EvenNumberFilePath); while (tmd != queue.tail) { writer.Write(queue.dequeue().data.ToString("X2") + " "); tmd = tmd.next; } writer.Write(queue.dequeue().data.ToString("X2") + " "); writer.Close(); } }
public virtual Expression ConvertToConstant(QNode node) { var valueType = node.Value.GetType(); var nullableUnderlyingType = Nullable.GetUnderlyingType(target); if (nullableUnderlyingType == null) { if (target == valueType) { return(Expression.Constant(node.Value)); } var value = Convert.ChangeType(node.Value, target); return(Expression.Constant(value, target)); } if (nullableUnderlyingType != valueType) { var value = Convert.ChangeType(node.Value, nullableUnderlyingType); var exp1 = Expression.Constant(value); return(Expression.Convert(exp1, target)); } else { var exp1 = Expression.Constant(node.Value); return(Expression.Constant(Expression.Convert(exp1, target))); } }
private static void Save(XmlTextWriter writter, QNode qnode, string path) { if (qnode == null) { return; } writter.WriteStartElement("QNode"); { writter.WriteAttributeString("Id", qnode.Id.ToString()); writter.WriteAttributeString("Level", qnode.Level.ToString()); writter.WriteAttributeString("X", qnode.Bound.X.ToString()); writter.WriteAttributeString("Y", qnode.Bound.Y.ToString()); writter.WriteAttributeString("Width", qnode.Bound.Width.ToString()); writter.WriteAttributeString("Height", qnode.Bound.Height.ToString()); if (qnode.isLeaf() == true && qnode.ListObject.Any()) { string str = String.Empty; foreach (var obj in qnode.ListObject) { str += obj.Name + " "; } writter.WriteStartElement("Objects"); writter.WriteString(str); writter.WriteEndElement(); } else { for (int i = 0; i < 4; i++) { Save(writter, qnode.Childs[i], path); } } } writter.WriteEndElement(); }
private void drawQuadTreeNode(QNode node, Graphics graphics) { if (node == null) { return; } if (node.isLeaf() == true) { if (node.ListObject.Any()) { graphics.FillRectangle(brush_quadnode, node.Bound); } else { graphics.FillRectangle(brush_quadnode_noobject, node.Bound); } graphics.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(255, 45, 45, 45))), node.Bound); } else { for (int i = 0; i < 4; i++) { drawQuadTreeNode(node.Childs[i], graphics); } } }
public void VisitMember(QNode node) { var field = new Field(ToCamelCase(Convert.ToString(node.Value))); this.ContextField.Push(field); this.AllField.Add(field); }
public QNode Prepare(QNode node) { var convertedNode = new MemberNodeExpander().ConvertNode(node); convertedNode = new QueryStringPreConverter().ConvertNode(convertedNode); return(convertedNode); }
public void Unlock() { QNode qnode = myNode.Value; qnode.Locked = false; myNode.Value = myPred.Value; }
public DynamicSource() { this.query = new QNode() { Type = NodeType.Querable }; }
public QTreeMap(TreeMapModel model) { control = new TreemapControl { IsZoomable = true }; Child = control; control.NodeDoubleClick += (s, e) => { var qNode = nodeMap[e.Node]; if (!qNode.hasChildren()) { return; } control.Clear(); zoomedNode = qNode; addToControl(control.Nodes, visibleNodes(), 2); guiNodes = Objects.list <Node>(control.Nodes); }; control.MinColorMetric = -5000F; control.MaxColorMetric = 5000F; control.MinColor = Color.SpringGreen; control.MaxColor = Color.Red; control.PaddingPx = 1; refreshContextMenus(); control.BeginUpdate(); modelNodes = model.nodes(); addToControl(control.Nodes, modelNodes); control.EndUpdate(); guiNodes = Objects.list <Node>(control.Nodes); setRefreshRate(5000); }
public void VisitMember(QNode node) { this.ContextExpression.Push( node.Operand == null ? Expression.PropertyOrField(this.ContextParameters.Peek(), Convert.ToString(node.Value)) : Expression.PropertyOrField(this.ContextExpression.Pop(), Convert.ToString(node.Value))); }
private void SetNodePosition(QNode node) { float halfWidth = flowPanelRect.rect.width / 2; node.GetComponent <RectTransform>().localScale = new Vector3(0.1f, 0.1f, 0.1f); if (node.GetParent() == null) { if (instructions.Count > 0) { node.GetComponent <RectTransform>().localPosition = new Vector2(halfWidth, instructions[instructions.Count - 1].GetComponent <RectTransform>().localPosition.y - _spacing); } else // first entry { node.GetComponent <RectTransform>().localPosition = new Vector2(halfWidth, 0); } } else { float parentNodeYPosition = ((QNode)node.GetParent()).GetComponent <RectTransform>().localPosition.y; if (node.GetParent().GetChild() == node) { node.GetComponent <RectTransform>().localPosition = new Vector2(halfWidth - _spacing, parentNodeYPosition - _spacing); } else { node.GetComponent <RectTransform>().localPosition = new Vector2(halfWidth + _spacing, parentNodeYPosition - _spacing); } } }
public void VisitEmptyMethod(QNode node) { var left = this.ContextExpression.Pop(); var method = EnumResolver.ResolveNodeType(node.Type); if (method == NodeType.ToString) { var toStringMethod = typeof(object).GetMethod("ToString", new Type[] { }); var exp = Expression.Call(left, toStringMethod, null); this.ContextExpression.Push(exp); } else if (method == NodeType.ToLower) { var exp = Expression.Call(left, Methods.ToLower, null); this.ContextExpression.Push(exp); } else { var types = new List <Type> { left.Type.GetTypeInfo().IsGenericType ? left.Type.GenericTypeArguments[0] : left.Type }; var exp = Expression.Call(typeof(Enumerable), method.ToString(), types.ToArray(), left); this.ContextExpression.Push(exp); } }
public bool TryLock(long patienceInMs) { DateTime startTime = DateTime.Now; QNode qnode = new QNode(); myNode.Value = qnode; qnode.Pred = null; QNode myPred = Interlocked.Exchange(ref tail, qnode); if (myPred == null || myPred.Pred == AVAILABLE) { return(true); } while (DateTime.Now.Subtract(startTime).TotalMilliseconds < patienceInMs) { QNode predPred = myPred.Pred; // it's free if (predPred == AVAILABLE) { return(true); } // it's abandoned else if (predPred != null) { myPred = predPred; } } if (Interlocked.CompareExchange(ref tail, myPred, qnode) != qnode) { qnode.Pred = myPred; } return(false); }
public static void AcceptProjection(QNode node, IQNodeVisitor visitor) { node.Left.Accept(visitor); visitor.EnterContext(node); visitor.VisitProjection(node); visitor.LeaveContext(node); }
private static QNode ResolveFunction(QNode qs_function) { var cs_name = qs_function.P_("cs", "name", "*").AsString(); var assemblyName = qs_function.P_("cs", "assembly", "*").AsString(); QNode q_method = null; QNode error = null; if (cs_name != null && assemblyName != null) { try { var index = cs_name.LastIndexOf('.'); if (index < 0) { throw new Exception($"Invalid name: '{cs_name}'"); } var argCount = qs_function.P_s("arg", "*").Count(); //var fullName = $"{cs_name.Substring(0, index)}, {assemblyName}"; var fullName = cs_name.Substring(0, index); var type = Type.GetType(fullName); if (type == null) { throw new Exception($"Не найден тип '{fullName}'"); } var methodName = cs_name.Substring(index + 1); var methods = type.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public) .Where(_method => _method.Name == methodName) .Where(_method => _method.GetParameters().Length == argCount) .ToArray(); var method = methods.FirstOrDefault(); var argType = qs_function.P_("arg", 0, "cs-type", "*").AsString(); if (argType != null) { var argCsType = Type.GetType(argType); method = methods.FirstOrDefault(_method => _method.GetParameters().FirstOrDefault()?.ParameterType == argCsType) ?? method; } if (method == null) { throw new Exception($"Не найден метод '{methodName}' в типе '{fullName}'"); } q_method = q.Q("method", method); } catch (Exception exc) { error = q.Q("error", exc.ToDisplayMessage()); } } if (q_method != null) { qs_function = qs_function.To_s().W_s(new object[] { "cs", q.Q("method", "+") }, q_method).FirstOrDefault(); } if (error != null) { qs_function = qs_function.To_s().W_s(new object[] { "cs", q.Q("error", "+") }, error).FirstOrDefault(); } return(qs_function); }
public static void AcceptLambdaArgumentMethod(QNode node, QNodeConverter visitor) { node.Operand.Accept(visitor); visitor.EnterContext(node); node.Argument.Accept(visitor); visitor.VisitLambdaMethod(node); visitor.LeaveContext(node); }
public static void AcceptMethod(QNode node, IQNodeVisitor visitor) { node.Left.Accept(visitor); visitor.EnterContext(node); node.Right.Accept(visitor); visitor.VisitMethod(node); visitor.LeaveContext(node); }
public override string BuildExpression(QNode node) { if (node is Query) { return(BuildQueryString((Query)node, false)); } return(base.BuildExpression(node)); }