comparison Main/jungle-main/store/impl/DefaultNodePath.cs @ 28:9588ad364fdd

Last commit before change.
author Kazuma Takeda
date Wed, 18 Jan 2017 19:53:29 +0900
parents 1f99e150f336
children f2ea780b3e80
comparison
equal deleted inserted replaced
27:9ff715ff8e09 28:9588ad364fdd
1 using UnityEngine; 1 using UnityEngine;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Collections; 3 using System.Collections;
4 4
5 public class DefaultNodePath : NodePath { 5 namespace JungleDB {
6 private List<int> path = new List<int>(); 6 public class DefaultNodePath : NodePath {
7 private List<int> path = new List<int>();
7 8
8 IEnumerator IEnumerable.GetEnumerator() 9 IEnumerator IEnumerable.GetEnumerator()
9 { 10 {
10 // call the generic version of the method 11 // call the generic version of the method
11 return this.GetEnumerator(); 12 return this.GetEnumerator();
13 }
14
15 public IEnumerator<int> GetEnumerator()
16 {
17 return path.iterator ();
18 }
19
20 public DefaultNodePath() {
21 path = new List<int> ().addLast (-1);
22 }
23
24 private DefaultNodePath(List<int> path) {
25 this.path = path;
26 }
27
28 /// <summary>
29 /// Listに追加します。
30 /// path = path.add(0)を2回する
31 /// path = path.add(0).add(0)する
32 /// これは同じ
33 /// </summary>
34 /// <param name="pos">Position.</param>
35
36 public NodePath add(int pos) {
37 List<int> newPath = path.addLast(pos);
38 return new DefaultNodePath(newPath);
39 }
40
41 public Pair<int, NodePath> pop() {
42 int head = path.headList();
43 List<int> tail = path.deleteHead();
44 return new Pair<int, NodePath>(head, new DefaultNodePath(tail));
45 }
46
47 public Pair<int, NodePath> last() {
48 int last = path.headList();
49 List<int> list = path.deleteHead();
50 return new Pair<int, NodePath>(last, new DefaultNodePath(list));
51 }
52
53 public override string ToString() {
54 string s = "List <";
55 int list_count = this.path.length();
56 int count = 0;
57 foreach(var i in this.path) {
58 if (count != list_count -1){
59 s += i.ToString() + ",";
60 } else {
61 s += i.ToString();
62 }
63 count++;
64 }
65 return s + ">";
66 }
67
68 public int size() {
69 return path.length();
70 }
71
72 public NodePath tail() {
73 List<int> tail = path.deleteLast ();
74 return new DefaultNodePath (tail);
75 }
76
77 public List<DefaultNodePath> inits() {
78 List<DefaultNodePath> paths = new List<DefaultNodePath> ();
79 List<int> coursePath = new List<int> ();
80 foreach (int tmpPath in path) {
81 List<int> tmp = coursePath.addLast (tmpPath);
82 paths = paths.addLast (new DefaultNodePath (tmp));
83 coursePath = tmp;
84 }
85 return paths;
86 }
12 } 87 }
13
14 public IEnumerator<int> GetEnumerator()
15 {
16 return path.iterator ();
17 }
18
19 public DefaultNodePath() {
20 path = new List<int> ().addLast (-1);
21 }
22
23 private DefaultNodePath(List<int> path) {
24 this.path = path;
25 }
26
27 /// <summary>
28 /// Listに追加します。
29 /// path = path.add(0)を2回する
30 /// path = path.add(0).add(0)する
31 /// これは同じ
32 /// </summary>
33 /// <param name="pos">Position.</param>
34
35 public NodePath add(int pos) {
36 List<int> newPath = path.addLast(pos);
37 return new DefaultNodePath(newPath);
38 }
39
40 public Pair<int, NodePath> pop() {
41 int head = path.headList();
42 List<int> tail = path.deleteHead();
43 return new Pair<int, NodePath>(head, new DefaultNodePath(tail));
44 }
45
46 public Pair<int, NodePath> last() {
47 int last = path.headList();
48 List<int> list = path.deleteHead();
49 return new Pair<int, NodePath>(last, new DefaultNodePath(list));
50 }
51
52 public override string ToString() {
53 string s = "List <";
54 int list_count = this.path.length();
55 int count = 0;
56 foreach(var i in this.path) {
57 if (count != list_count -1){
58 s += i.ToString() + ",";
59 } else {
60 s += i.ToString();
61 }
62 count++;
63 }
64 return s + ">";
65 }
66
67 public int size() {
68 return path.length();
69 }
70
71 public NodePath tail() {
72 List<int> tail = path.deleteLast ();
73 return new DefaultNodePath (tail);
74 }
75
76 public List<DefaultNodePath> inits() {
77 List<DefaultNodePath> paths = new List<DefaultNodePath> ();
78 List<int> coursePath = new List<int> ();
79 foreach (int tmpPath in path) {
80 List<int> tmp = coursePath.addLast (tmpPath);
81 paths = paths.addLast (new DefaultNodePath (tmp));
82 coursePath = tmp;
83 }
84 return paths;
85 }
86
87
88 } 88 }