MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / LongestBranch

Method LongestBranch

db/revtree_test.go:1272–1306  ·  view source on GitHub ↗

Find the length of the longest branch

()

Source from the content-addressed store, hash-verified

1270
1271// Find the length of the longest branch
1272func (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
1309func createBodyContentAsMapWithSize(docSizeBytes int) map[string]string {

Calls 2

forEachLeafMethod · 0.95
IsRootMethod · 0.80

Tested by

no test coverage detected