Skip to content

Conversation

darosior
Copy link
Contributor

Based off a rebased #114

//! Returns true if the node contains at least one duplicate key.
bool ContainsDuplicateKey() const {
auto upfn = [](const Node& node, Span<std::set<Key>> subs) -> std::optional<std::set<Key>> {
size_t keys_count = node.keys.size();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add if (node.duplicate_key) return {};. That way no work is done in recomputing these sets all the time if we already know there is a duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but the boolean would be uninitialized for the current node. Isn't its value undefined?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, that's a bad idea. For the current node, we obviously don't know yet. But for any child nodes we do.

So what about if (&node != this && node.duplicate_key) return {};.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there isn't any point in actually computing the set for child, right? We just use the duplicate_key boolean: if one messed up with the keys after the Node was created they were really looking for troubles..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow.

@darosior darosior force-pushed the duplicate_keys branch 2 times, most recently from 6518ee3 to d10a9ca Compare April 15, 2022 07:53
@darosior
Copy link
Contributor Author

darosior commented Apr 15, 2022 via email

@sipa
Copy link
Owner

sipa commented Apr 15, 2022

It's because i didn't plug my brain before commenting, sorry about that.

It's ok. I just made coffee without putting a cup in the machine.

I'm away and back on Sunday, i'll push your optimization then. (If you need it before i think you have access to push to my PRs.)

No rush.

sipa and others added 2 commits April 20, 2022 11:24
As stated on the website, duplicate keys make it hard to reason about
malleability as a single signature may unlock multiple paths.
@darosior
Copy link
Contributor Author

Rebased on #114

@sipa
Copy link
Owner

sipa commented Apr 21, 2022

utACK 13edbef

@sipa sipa merged commit 833471d into sipa:master Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants