111 |
111 |
112 /* reachability */ |
112 /* reachability */ |
113 |
113 |
114 /*reachable nodes with length of longest path*/ |
114 /*reachable nodes with length of longest path*/ |
115 def reachable_length( |
115 def reachable_length( |
116 count: Key => Int, |
116 count: Key => Long, |
117 next: Key => Keys, |
117 next: Key => Keys, |
118 xs: List[Key]): Map[Key, Int] = |
118 xs: List[Key]): Map[Key, Long] = |
119 { |
119 { |
120 def reach(length: Int)(rs: Map[Key, Int], x: Key): Map[Key, Int] = |
120 def reach(length: Long)(rs: Map[Key, Long], x: Key): Map[Key, Long] = |
121 if (rs.get(x) match { case Some(n) => n >= length case None => false }) rs |
121 if (rs.get(x) match { case Some(n) => n >= length case None => false }) rs |
122 else ((rs + (x -> length)) /: next(x))(reach(length + count(x))) |
122 else ((rs + (x -> length)) /: next(x))(reach(length + count(x))) |
123 (Map.empty[Key, Int] /: xs)(reach(0)) |
123 (Map.empty[Key, Long] /: xs)(reach(0)) |
124 } |
124 } |
125 def node_height(count: Key => Int): Map[Key, Int] = |
125 def node_height(count: Key => Long): Map[Key, Long] = |
126 reachable_length(count, imm_preds(_), maximals) |
126 reachable_length(count, imm_preds(_), maximals) |
127 def node_depth(count: Key => Int): Map[Key, Int] = |
127 def node_depth(count: Key => Long): Map[Key, Long] = |
128 reachable_length(count, imm_succs(_), minimals) |
128 reachable_length(count, imm_succs(_), minimals) |
129 |
129 |
130 /*reachable nodes with size limit*/ |
130 /*reachable nodes with size limit*/ |
131 def reachable_limit( |
131 def reachable_limit( |
132 limit: Int, |
132 limit: Long, |
133 count: Key => Int, |
133 count: Key => Long, |
134 next: Key => Keys, |
134 next: Key => Keys, |
135 xs: List[Key]): Keys = |
135 xs: List[Key]): Keys = |
136 { |
136 { |
137 def reach(res: (Int, Keys), x: Key): (Int, Keys) = |
137 def reach(res: (Long, Keys), x: Key): (Long, Keys) = |
138 { |
138 { |
139 val (n, rs) = res |
139 val (n, rs) = res |
140 if (rs.contains(x)) res |
140 if (rs.contains(x)) res |
141 else ((n + count(x), rs + x) /: next(x))(reach _) |
141 else ((n + count(x), rs + x) /: next(x))(reach _) |
142 } |
142 } |
143 |
143 |
144 @tailrec def reachs(size: Int, rs: Keys, rest: List[Key]): Keys = |
144 @tailrec def reachs(size: Long, rs: Keys, rest: List[Key]): Keys = |
145 rest match { |
145 rest match { |
146 case Nil => rs |
146 case Nil => rs |
147 case head :: tail => |
147 case head :: tail => |
148 val (size1, rs1) = reach((size, rs), head) |
148 val (size1, rs1) = reach((size, rs), head) |
149 if (size > 0 && size1 > limit) rs |
149 if (size > 0 && size1 > limit) rs |