Find the length of the longest branch
()
| 1270 | |
| 1271 | // Find the length of the longest branch |
| 1272 | func (tree RevTree) LongestBranch() int { |
| 1273 | |
| 1274 | longestBranch := 0 |
| 1275 | |
| 1276 | leafProcessor := func(leaf *RevInfo) { |
| 1277 | |
| 1278 | lengthOfBranch := 0 |
| 1279 | |
| 1280 | // Walk up the tree until we find a root, and append each node |
| 1281 | node := leaf |
| 1282 | for { |
| 1283 | |
| 1284 | // Increment length of branch |
| 1285 | lengthOfBranch += 1 |
| 1286 | |
| 1287 | // Reached a root, we're done -- if this branch is longer than the |
| 1288 | // current longest branch, record branch length as longestBranch |
| 1289 | if node.IsRoot() { |
| 1290 | if lengthOfBranch > longestBranch { |
| 1291 | longestBranch = lengthOfBranch |
| 1292 | } |
| 1293 | break |
| 1294 | } |
| 1295 | |
| 1296 | // Walk up the branch to the parent node |
| 1297 | node = tree[node.Parent] |
| 1298 | |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | tree.forEachLeaf(leafProcessor) |
| 1303 | |
| 1304 | return longestBranch |
| 1305 | |
| 1306 | } |
| 1307 | |
| 1308 | // Create body content as map of 100 byte entries. Rounds up to the nearest 100 bytes |
| 1309 | func createBodyContentAsMapWithSize(docSizeBytes int) map[string]string { |
no test coverage detected