-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.0] Fix semantics of AvlTree.insert & new AvlTree.insertOrUpdate method #1038
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but see comments.
* | ||
* @param key key to look up | ||
* @param value value to check it was inserted or updated | ||
* @return Success(Some(value)), Success(None), or Failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense to describe each case of returned result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
def insertOrUpdate( | ||
entries: Coll[(Coll[Byte], Coll[Byte])], | ||
proof: Coll[Byte]): Option[AvlTree] = { | ||
if (!tree.isInsertAllowed || !tree.isUpdateAllowed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both flags are required, however for each given tree it will either be insert or update (but not both).
Is it possible to make it more flexible and require the flag only if the corresponding operation is happening for a given tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" for each given tree it will either be insert or update (but not both)" - no, it could be insert for one key and update for another
@@ -146,7 +146,7 @@ class CErgoTreeEvaluator( | |||
val insertRes = bv.performInsert(key.toArray, value.toArray) | |||
// TODO v6.0: throwing exception is not consistent with update semantics | |||
// however it preserves v4.0 semantics (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
operations.forall { case (key, value) => | ||
var res = true | ||
// the cost of tree update is O(bv.treeHeight) | ||
addSeqCost(UpdateAvlTree_Info, nItems) { () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addSeqCost(UpdateAvlTree_Info, nItems) { () => | |
// Here (and in the previous methods) the cost is not properly approximated. | |
// When the tree is small (or empty), but there are many `operations`, the treeHeight will grow on every iteration. | |
// So should the cost on every iteration. | |
addSeqCost(UpdateAvlTree_Info, nItems) { () => |
…TreeEvaluator.scala Co-authored-by: Alexander Slesarenko <[email protected]>
close #908
In this PR, semantics of AvlTree.insert fixed, and new AvlTree.insertOrUpdate method added