-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow batches to write to a nondescendant sublevel (#81)
- Loading branch information
Showing
8 changed files
with
137 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
'use strict' | ||
|
||
exports.prefixDescendantKey = function (key, keyFormat, descendant, ancestor) { | ||
// TODO: optimize | ||
// TODO: throw when ancestor is not descendant's ancestor? | ||
while (descendant !== null && descendant !== ancestor) { | ||
key = descendant.prefixKey(key, keyFormat, true) | ||
descendant = descendant.parent | ||
} | ||
|
||
return key | ||
} | ||
|
||
// Check if db is a descendant of ancestor | ||
// TODO: optimize, when used alongside prefixDescendantKey | ||
// which means we visit parents twice. | ||
exports.isDescendant = function (db, ancestor) { | ||
while (true) { | ||
if (db.parent == null) return false | ||
if (db.parent === ancestor) return true | ||
db = db.parent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters