internal void removeFirst() { if (Head == Tail) { Head = Tail = null; } else { Head = Head.Next; } }
private IEnumerable <T> getDataAsEnumerable() { SNode traversal = Head; while (traversal != null) { yield return(traversal.Data); traversal = traversal.Next; } }
private void AssignNeighbor(int nodeRow, int nodeCol, List <SNode> neighbors) { if (nodeRow != -1 && nodeCol != -1 && nodeRow < numRows && nodeCol < numCols) { SNode nodeToAdd = nodes[nodeRow, nodeCol]; if (!nodeToAdd.bObstacle) { neighbors.Add(nodeToAdd); } } }
public SNode GetMetaData() { SNode x = new SNode(); x.position = transform.position; x.radius = radius; x.distortion = distortion; x.cubePortion = cubePortion; return(x); }
bool IsFullSN(SNode S) { if (MAXSIZE == S.rear) { return(true); } else { return(false); } }
public void RemoveNode(Node n) { if (!Contains(n)) { return; } SNode node = GetSNode(n); nodes.Remove(node); Destroy(node.road); }
bool IsEmptySN(SNode S) { if (S.front == S.rear) { return(true); } else { return(false); } }
private static void UpdateUnitIds(SNode symbol, string symbolName, string partValue) { var unitIds = symbol.Childs .Where(child => child.Name == "symbol") .Select(unit => unit.Childs[0]); foreach (var unitId in unitIds) { unitId.Name = unitId.Name?.Replace(symbolName, partValue, StringComparison.Ordinal); } }
internal void insertFirst(SNode sNode) { if (Head == null && Tail == null) { Head = Tail = sNode; } else { sNode.Next = Head; Head = sNode; } }
int CountNodes(SNode n) { int count = 0; while (n != null) { count++; n = n.Next; } return(count); }
/// <summary> /// 执行插入任务菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnAtvNode(object sender, Mi e) { SNode node = new SNode(_sketch) { Title = "任务项", Shape = "任务", Width = 120, Height = 60 }; Insert(node); }
internal void insertLast(SNode sNode) { if (Head == null && Tail == null) { Head = Tail = sNode; } else { Tail.Next = sNode; Tail = sNode; } }
public void Echo() { // Arrange var input = "((data \"quoted data\" \"\\\"quote\\\"\" 123 4.5) (data (!@# (4.5) \"(more\" \"data)\")))"; // Act var sNode = SNode.Parse(input); var output = sNode.ToString(); // Assert Assert.Equal(input, output); }
public void CreateNodeWithIntegerValue_StoresValue(int value) { // Arrange SNode node; int expected = value; // Act node = new SNode(value); // Assert Assert.Equal(expected, node.Value); }
public Node Pop() { if (m_first == null) { throw new Exception(); } SNode first = m_first; m_first = m_first.N; return(first.Item); }
static void CollectChildren(SNode node, List <SNode> children) { foreach (SNode c in node.children) { if (IsSuitableNode(c)) { children.Add(c); } CollectChildren(c, children); } }
//static public List<SNode> asyncPath; private static List <SNode> CalculatePath(SNode sn) { List <SNode> list = new List <SNode>(); while (sn != null) { list.Add(sn); sn = (SNode)sn.parent; } list.Reverse(); return(list); }
public static List <int> ToList(SNode node) { var result = new List <int>(); while (node != null) { result.Add(node.Value); node = node.Next; } return(result); }
public override Node Duplicate() { SNode sn = new SNode(Frame, Id); sn.Name = Name; sn.Edges.AddRange(Edges); sn.CustomData = new Dictionary <string, object>(this.CustomData); sn.Tags.AddRange(this.Tags); sn.Frame = this.Frame; return(sn); }
public static List <SNode> FindPath(SNode start, SNode goal) { openList = new SortedQueue <SNode>(); openList.Push(start); start.initialCost = 0.0f; start.estimatedCost = GetHeuristicEstimateCost(start, goal); start.nodeTotalCost = start.initialCost + start.estimatedCost; closedList = new HashSet <SNode>(); SNode sNode = null; while (openList.Length != 0) { sNode = openList.First; if (sNode.position == goal.position) { return(CalculatePath(sNode)); } List <SNode> neighbors = new List <SNode>(); GridHandler.S.GetNeighbors(sNode, neighbors); for (int i = 0; i < neighbors.Count; i++) { SNode neighborNode = neighbors[i]; if (!closedList.Contains(neighborNode)) { neighborNode.estimatedCost = GetHeuristicEstimateCost(neighborNode, goal); neighborNode.initialCost = sNode.initialCost + 1; neighborNode.nodeTotalCost = neighborNode.estimatedCost + neighborNode.initialCost; neighborNode.parent = sNode; if (!openList.Contains(neighborNode)) { openList.Push(neighborNode); } } } closedList.Add(sNode); openList.Remove(sNode); } //If finished looping and cannot find the goal then return null if (sNode.position != goal.position) { Debug.LogError("Goal Not Found"); return(null); } //Calculate the path based on the final node return(CalculatePath(sNode)); }
public void TestMethod15() { SNode head = null; head = SinglyLinkedListOps.AddTail(head, 1); head = SinglyLinkedListOps.AddTail(head, 2); head = SinglyLinkedListOps.AddTail(head, 3); head = SinglyLinkedListOps.DeleteAll(head, 2); ValidateList(head, new List <int> { 1, 3 }); }
public void Serialize_Non_Primitive_Node(string expectedOutput, string key, params string[] childs) { // Arrange var childNodes = childs.Select(child => new SNode(child)).ToArray(); var node = new SNode(key, childNodes); // Act var output = node.ToString(); // Assert output.Should().Be(expectedOutput); }
/// <summary> /// 执行插入开始菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnStartNode(object sender, Mi e) { SNode node = new SNode(_sketch) { Title = "开始", Shape = "开始", Width = 80, Height = 60 }; Insert(node); }
public void Parse_Non_Primitive_Node(string input, string key, params string[] childs) { // Arrange var childNodes = childs.Select(child => new SNode(child)).ToArray(); var expectedNode = new SNode(key, childNodes); // Act var node = SNode.Parse(input); // Assert node.Should().BeEquivalentTo(expectedNode); }
public void GetNeighbors(SNode node, List <SNode> neighbors) { Vector3 neighborPos = node.position; int neighborIndex = GetGridIndex(neighborPos); int row = GetRow(neighborIndex); int col = GetColumn(neighborIndex); //Bottom int nodeRow = row - 1; int nodeCol = col; AssignNeighbor(nodeRow, nodeCol, neighbors); //Top nodeRow = row + 1; nodeCol = col; AssignNeighbor(nodeRow, nodeCol, neighbors); //Right nodeRow = row; nodeCol = col + 1; AssignNeighbor(nodeRow, nodeCol, neighbors); //Left nodeRow = row; nodeCol = col - 1; AssignNeighbor(nodeRow, nodeCol, neighbors); if (useDiagonal) { //BottomLeft nodeRow = row - 1; nodeCol = col - 1; AssignNeighbor(nodeRow, nodeCol, neighbors); //TopLeft nodeRow = row + 1; nodeCol = col - 1; AssignNeighbor(nodeRow, nodeCol, neighbors); //TopRight nodeRow = row + 1; nodeCol = col + 1; AssignNeighbor(nodeRow, nodeCol, neighbors); //BottomRight nodeRow = row - 1; nodeCol = col + 1; AssignNeighbor(nodeRow, nodeCol, neighbors); } }
public void TestMethod6() { SNode head = null; head = SinglyLinkedListOps.AddTail(head, 1); head = SinglyLinkedListOps.AddTail(head, 2); head = SinglyLinkedListOps.AddTail(head, 3); Assert.AreEqual(1, head.data); Assert.AreEqual(2, head.next.data); Assert.AreEqual(3, head.next.next.data); Assert.IsNull(head.next.next.next); }
public void TestMethod11() { SNode head = null; head = SinglyLinkedListOps.InsertAt(head, 1, 0); head = SinglyLinkedListOps.InsertAt(head, 2, 0); head = SinglyLinkedListOps.InsertAt(head, 3, 100); Assert.AreEqual(2, head.data); Assert.AreEqual(1, head.next.data); Assert.AreEqual(3, head.next.next.data); Assert.IsNull(head.next.next.next); }
public SNode DeepCopy() { SNode copy = (SNode)MemberwiseClone(); copy.Possibles = new OrderedSet <int>(); foreach (int value in this.Possibles) { copy.Possibles.Add(value); } return(copy); }
void _DetachFromDeleted(SNode Node_) { _Detach(Node_); if (Node_.Prev == null) { _DeletedHead = Node_.Next; } if (Node_.Next == null) { _DeletedTail = Node_.Prev; } }
internal void clear() { SNode traversal = Head; while (traversal != null) { SNode temp = traversal.Next; traversal.Next = null; traversal = temp; } Head = Tail = null; }
public bool Match(SNode node) { if (!parts_of_speech.Contains(node.word.part_of_speech)) return false; for (int i = 0; i < children.Count; ++i) { bool child_found = false; for (int j = 0; j < node.children.Count; ++j) if (node.edge_types[j].Equals(edge_type[i], StringComparison.CurrentCultureIgnoreCase)) { if (children[i].Match(node.children[j])) { child_found = true; break; } } if (!child_found) return false; } return true; }
public Sentence(XmlNode n_sent) { text = n_sent.SelectSingleNode("text").InnerText; // токены tokens = new List<SToken>(); int token_index = 0; foreach (XmlNode n_token in n_sent.SelectNodes("tokens/token")) { SToken t = new SToken(token_index, n_token); tokens.Add(t); token_index++; } // дерево зависимостей List<int> root_index = new List<int>(); Dictionary<int, int> child2parent = new Dictionary<int, int>(); Dictionary<KeyValuePair<int, int>, string> edge_type = new Dictionary<KeyValuePair<int, int>, string>(); Dictionary<int, List<int>> parent2child = new Dictionary<int, List<int>>(); foreach (XmlNode n_token in n_sent.SelectNodes("syntax_tree/node")) { int child_index = int.Parse(n_token["token"].InnerText); if (n_token.Attributes["is_root"] != null && n_token.Attributes["is_root"].Value == "true") root_index.Add(child_index); else { int parent_index = int.Parse(n_token["parent"].InnerText); child2parent.Add(child_index, parent_index); edge_type.Add(new KeyValuePair<int, int>(child_index, parent_index), n_token["link_type"].InnerText); List<int> child_idx; if (!parent2child.TryGetValue(parent_index, out child_idx)) { child_idx = new List<int>(); parent2child.Add(parent_index, child_idx); } child_idx.Add(child_index); } } nodes = new List<SNode>(); for (int inode = 0; inode < tokens.Count; ++inode) { SNode n = new SNode(); n.index = inode; n.word = tokens[inode]; nodes.Add(n); } // проставим родителей и детей в каждом узле for (int inode = 0; inode < nodes.Count; ++inode) { SNode node = nodes[inode]; if (!root_index.Contains(node.index)) { SNode parent_node = nodes[child2parent[node.index]]; node.parent = parent_node; parent_node.children.Add(node); parent_node.edge_types.Add(edge_type[new KeyValuePair<int, int>(node.index, parent_node.index)]); } else { root = node; } } }
/// <summary> /// Extract SNode.Argument[] into system object[] data. /// </summary> /// <param name="args">SNode arguments.</param> /// <returns></returns> public static object[] extract(SNode.Argument[] args) { object[] ret = new object[args.Length]; for(int i = 0; i < args.Length; ++i) { if(args[i].data is SNode.Argument[]) { ret[i] = extract((SNode.Argument[])args[i].data); continue; } ret[i] = args[i].data; #if DEBUG Log.Trace("Value.extract: SNode.Argument - '{0}'", ret[i]); #endif } return ret; }