| 59 | | // [parent, idx, childs[]] |
|---|
| 60 | | |
|---|
| 61 | | addNode(new TreeNode(p, i)); |
|---|
| 62 | | addEdge(new Edge(p, i)); |
|---|
| 63 | | a = a[2]; |
|---|
| 64 | | var b:Boolean, e:Edge; |
|---|
| 65 | | for each(c in a){ |
|---|
| 66 | | if(nodes_[c] == undefined) idxs.push(addNode(new TreeNode(i, c))); |
|---|
| 67 | | b = true; |
|---|
| 68 | | for each(e in edges_[i]){ |
|---|
| 69 | | if(e.dst == c) b = false; |
|---|
| | 59 | if(nodes_[target.index] == undefined){ |
|---|
| | 60 | addedIdx = addNode(target); |
|---|
| | 61 | addEdge(new Edge(parent.index, target.index)); |
|---|
| | 62 | }else{ |
|---|
| | 63 | var exist:Boolean = false; |
|---|
| | 64 | for each(var edge:Edge in edges_[parent.index]){ |
|---|
| | 65 | if(edge.dst == target.index){ |
|---|
| | 66 | exist = true; |
|---|
| | 67 | break; |
|---|
| | 68 | } |
|---|
| | 73 | return addedIdx; |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| | 76 | |
|---|
| | 77 | public function idxBundle(parentIdx:int, targetIdx:int):int |
|---|
| | 78 | { |
|---|
| | 79 | var addedIdx:int = -1; |
|---|
| | 80 | |
|---|
| | 81 | if(nodes_[targetIdx] == undefined){ |
|---|
| | 82 | addedIdx = addNode(new Node(targetIdx)); |
|---|
| | 83 | addEdge(new Edge(parentIdx, parentIdx)); |
|---|
| | 84 | }else{ |
|---|
| | 85 | var exist:Boolean = false; |
|---|
| | 86 | for each(var edge:Edge in edges_[parentIdx]){ |
|---|
| | 87 | if(edge.dst == targetIdx){ |
|---|
| | 88 | exist = true; |
|---|
| | 89 | break; |
|---|
| | 90 | } |
|---|
| | 91 | } |
|---|
| | 92 | if(!exist) addEdge(new Edge(parentIdx, targetIdx)); |
|---|
| | 93 | } |
|---|
| | 94 | |
|---|
| | 95 | return addedIdx; |
|---|
| | 96 | } |
|---|
| | 97 | |
|---|
| | 98 | |
|---|
| | 99 | public function domino(set1:Array, ...rest):Array |
|---|
| | 100 | { |
|---|
| | 101 | var addedIdxs:Array = [], added:int; |
|---|
| | 102 | |
|---|
| | 103 | var parent:TreeNode, target:TreeNode, childs:Array; |
|---|
| | 104 | var child:TreeNode; |
|---|
| | 105 | |
|---|
| | 106 | // set1 = [parent, target, childs[]]を追加 |
|---|
| | 107 | parent = set1[0]; |
|---|
| | 108 | target = set1[1]; |
|---|
| | 109 | childs = set1[2]; |
|---|
| | 110 | added = bundle(parent, target); |
|---|
| | 111 | if(added > 0) addedIdxs.push(added); |
|---|
| | 112 | for each(child in childs){ |
|---|
| | 113 | added = bundle(target, child); |
|---|
| | 114 | if(added > 0) addedIdxs.push(added); |
|---|
| | 115 | } |
|---|
| | 116 | |
|---|
| | 117 | // rest = [set2, set3, ...]を追加 |
|---|
| 75 | | p = r[0]; |
|---|
| 76 | | i = r[1]; |
|---|
| 77 | | if(nodes_[i] == undefined) idxs.push(addNode(new TreeNode(p, i))); |
|---|
| 78 | | b = true; |
|---|
| 79 | | for each(e in edges_[p]){ |
|---|
| 80 | | if(e.dst == i) b = false; |
|---|
| 81 | | } |
|---|
| 82 | | if(b) addEdge(new Edge(p, i)); |
|---|
| 83 | | r = r[2]; |
|---|
| 84 | | for each(c in r){ |
|---|
| 85 | | if(nodes_[c] == undefined) idxs.push(addNode(new TreeNode(i, c))); |
|---|
| 86 | | if(edges_[i][c] == undefined) addEdge(new Edge(i, c)); |
|---|
| 87 | | b = true; |
|---|
| 88 | | for each(e in edges_[i]){ |
|---|
| 89 | | if(e.dst == c) b = false; |
|---|
| 90 | | } |
|---|
| 91 | | if(b) addEdge(new Edge(i, c)); |
|---|
| | 119 | parent = r[0]; |
|---|
| | 120 | target = r[1]; |
|---|
| | 121 | childs = r[2]; |
|---|
| | 122 | added = bundle(parent, target); |
|---|
| | 123 | if(added > 0) addedIdxs.push(added); |
|---|
| | 124 | for each(child in childs){ |
|---|
| | 125 | added = bundle(target, child); |
|---|
| | 126 | if(added > 0) addedIdxs.push(added); |
|---|
| 95 | | return idxs; |
|---|
| | 130 | return addedIdxs; |
|---|
| | 131 | } |
|---|
| | 132 | |
|---|
| | 133 | |
|---|
| | 134 | public function idxDomino(idxSet1:Array, ...rest):Array |
|---|
| | 135 | { |
|---|
| | 136 | var addedIdxs:Array = [], added:int; |
|---|
| | 137 | |
|---|
| | 138 | var parentIdx:int, targetIdx:int, childIdxs:Array; |
|---|
| | 139 | var childIdx:int; |
|---|
| | 140 | |
|---|
| | 141 | // idxSet1 = [parentIdx, targetIdx, childIdxs[]]を追加 |
|---|
| | 142 | parentIdx = idxSet1[0]; |
|---|
| | 143 | targetIdx = idxSet1[1]; |
|---|
| | 144 | childIdxs = idxSet1[2]; |
|---|
| | 145 | added = idxBundle(parentIdx, targetIdx); |
|---|
| | 146 | if(added > 0) addedIdxs.push(added); |
|---|
| | 147 | for each(childIdx in childIdxs){ |
|---|
| | 148 | added = idxBundle(targetIdx, childIdx); |
|---|
| | 149 | if(added > 0) addedIdxs.push(added); |
|---|
| | 150 | } |
|---|
| | 151 | |
|---|
| | 152 | // rest = [idxSet2, idxSet3, ...]を追加 |
|---|
| | 153 | for each(var idxSet:Array in rest){ |
|---|
| | 154 | parentIdx = idxSet[0]; |
|---|
| | 155 | targetIdx = idxSet[1]; |
|---|
| | 156 | childIdxs = idxSet[2]; |
|---|
| | 157 | added = idxBundle(parentIdx, targetIdx); |
|---|
| | 158 | if(added > 0) addedIdxs.push(added); |
|---|
| | 159 | for each(childIdx in childIdxs){ |
|---|
| | 160 | added = idxBundle(targetIdx, childIdx); |
|---|
| | 161 | if(added > 0) addedIdxs.push(added); |
|---|
| | 162 | } |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | return addedIdxs; |
|---|