8000 Feature: clear unused memory for pentagon children by zachasme · Pull Request #84 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature: clear unused memory for pentagon children #84

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

Merged
merged 5 commits into from
Jun 28, 2018

Conversation

zachasme
Copy link
Contributor

This is a fantastic library!

I've encountered an inconsistency between h3ToChildren and kRing: The later sets memory to zero for pentagons. This left me confused when using h3ToChildren on pentagons which in my case returned valid indices (left over in memory from other calls) for the children that are skipped.

This pull request zeroes out memory for the unused slots.

Alternatively, the difference should at least be documented to let us know to use calloc.

@CLAassistant
Copy link
CLAassistant commented Jun 26, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator
@isaacbrodsky isaacbrodsky left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! I think the approach is good, but I'm not sure it will zero out deleted pentagon children in all cases.

8000
@@ -194,6 +194,8 @@ void H3_EXPORT(h3ToChildren)(H3Index h, int childRes, H3Index* children) {
for (int i = 0; i < 7; i++) {
if (!isAPentagon || i != K_AXES_DIGIT) {
H3_EXPORT(h3ToChildren)(makeDirectChild(h, i), childRes, children);
} else {
*children = H3_INVALID_INDEX;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this will zero enough of the buffer, since the recursive call to h3ToChildren could have generated more than one index. I think it needs to zero out bufferChildStep indexes.

Here is the test case I used:

TEST(pentagonChildrenMultires) {
    H3Index pentagon;
    setH3Index(&pentagon, 1, 4, 0);

    const int expectedCount = (5 * 7) + (6);
    const int paddedCount = H3_EXPORT(maxH3ToChildrenSize)(pentagon, 3);

    H3Index* children = calloc(paddedCount, sizeof(H3Index));
    H3_EXPORT(h3ToChildren)(sfHex8, 10, children);
    H3_EXPORT(h3ToChildren)(pentagon, 3, children);

    // just for testing:
    for (int i = 0; i < paddedCount; i++) {
        printf("test: %llx\n", children[i]);
    }

    verifyCountAndUniqueness(children, paddedCount, expectedCount);
    free(children);
}

@zachasme
Copy link
Contributor Author

Thanks! I've updated the PR accordingly.

CHANGELOG.md Outdated
@@ -8,6 +8,7 @@ The public API of this library consists of the functions declared in file
## [Unreleased]
### Added
- Added Direction enum, replacing int and defined constants (#77)
- Ensured unused memory is cleared for pentagon children.
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny nit: i'd put this under Fixed instead of Added

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 498e65d on zachasme:feature-pentagon-zeroed-child into 518b324 on uber:master.

@isaacbrodsky isaacbrodsky merged commit 7d36b83 into uber:master Jun 28, 2018
@zachasme zachasme deleted the feature-pentagon-zeroed-child branch June 29, 2018 09:18
mrdvt92 pushed a commit to mrdvt92/h3 that referenced this pull request Jun 19, 2022
Feature: clear unused memory for pentagon children
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.

5 participants
0