Skip to content

Commit

Permalink
Convert balancer.js to Cadence 0.4.1.
Browse files Browse the repository at this point in the history
See #513.
  • Loading branch information
flatheadmill committed Nov 6, 2015
1 parent a27be59 commit 7e38a7f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions balancer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var ok = require('assert').ok
var cadence = require('cadence/redux')
var cadence = require('./cadence')
var Script = require('./script')
var Descent = require('./descent')

Expand Down Expand Up @@ -250,7 +250,7 @@ Balancer.prototype.splitLeafAndUnlock = cadence(function (async, address, key, g
split = leaf.page
if (split.items.length - split.ghosts <= this.sheaf.options.leafSize) {
this.sheaf.unbalanced(split, true)
return [ splitter, false ]
return [ splitter.break, false ]
}
}, function () {
pages = Math.ceil(split.items.length / this.sheaf.options.leafSize)
Expand All @@ -263,7 +263,7 @@ Balancer.prototype.splitLeafAndUnlock = cadence(function (async, address, key, g

var splits = 0
var loop = async(function () {
if (splits++ == pages - 1) return [ loop ]
if (splits++ == pages - 1) return [ loop.break ]
page = locker.encache(this.sheaf.createPage(1))
encached.push(page)

Expand Down Expand Up @@ -305,7 +305,7 @@ Balancer.prototype.splitLeafAndUnlock = cadence(function (async, address, key, g
}, function () {
this.sheaf.unbalanced(leaf.page, true)
this.sheaf.unbalanced(page, true)
return [ splitter, true, penultimate.page, encached[0].items[0].key ]
return [ splitter.break, true, penultimate.page, encached[0].items[0].key ]
})()
})

Expand Down Expand Up @@ -621,7 +621,7 @@ Balancer.prototype.mergePagesAndUnlock = cadence(function (
}, function () {
merger.call(this, script, pages, ghosted, async())
}, function (dirty) {
if (!dirty) return [ merge, false ]
if (!dirty) return [ merge.break, false ]
}, function () {
var index = parents.right.indexes[ancestor.address]

Expand Down Expand Up @@ -649,7 +649,7 @@ Balancer.prototype.mergePagesAndUnlock = cadence(function (
})
script.commit(async())
}, function () {
return [ merge, true, ancestor, designation.key ]
return [ merge.break, true, ancestor, designation.key ]
})()
})

Expand Down Expand Up @@ -709,7 +709,7 @@ Balancer.prototype.mergeLeaves = function (key, leftKey, unbalanced, ghostly, ca
var count = leaves.right.page.items.length - leaves.right.page.ghosts
var index = 0
var loop = async(function () {
if (index == count) return [ loop ]
if (index == count) return [ loop.break ]
var item = leaves.right.page.items[index + ghosts]
leaves.left.page.splice(leaves.left.page.items.length, 0, item)
index++
Expand Down Expand Up @@ -774,11 +774,11 @@ Balancer.prototype.chooseBranchesToMergeAndUnlock = cadence(function (async, key
designator.index = 0
designator.descend(designator.left, designator.leaf, async())
} else {
return [ choose , false ]
return [ choose.break, false ]
}
}, function () {
var item = designator.page.items[0]
return [ choose, true, item.key, item.heft, choice.page.address ]
return [ choose.break, true, item.key, item.heft, choice.page.address ]
})
})()
})
Expand Down

0 comments on commit 7e38a7f

Please sign in to comment.