Skip to content
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

Handle empty (zero length) input to compact #278

Merged
merged 4 commits into from
Sep 9, 2019

Conversation

isaacbrodsky
Copy link
Collaborator

compact, maxUncompactSize, and uncompact should handle the
case where empty input is provided. In this case the arrays
should not be dereferenced, since the first index is already out
of range.

This also adds tests for some uncovered branches.

Isaac Brodsky added 3 commits September 3, 2019 16:38
`compact`, `maxUncompactSize`, and `uncompact` should handle the
case where empty input is provided. In this case the arrays
should not be dereferenced, since the first index is already out
of range.

This also adds tests for some uncovered branches.
Copy link
Collaborator

@nrabinowitz nrabinowitz left a comment

Choose a reason for hiding this comment

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

LG when green

t_assert(countLinkedPolygons(&polygon) == 1, "Polygon count correct");
t_assert(countLinkedLoops(&polygon) == 1,
"Loop count on first polygon correct");
t_assert(polygon.first == outer, "Got expected outer loop");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it worth asserting output here? My assumption would be that if we are returning error codes, we relinquish all guarantees about output when you get one - so no behavior after an error code is returned should be assertable, because it's all undefined.

Copy link
Collaborator Author

@isaacbrodsky isaacbrodsky Sep 4, 2019

Choose a reason for hiding this comment

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

It may not be, since the polygon doesn't have all the features anymore.

edit: removed the asserts about the properties of the polygon.

@@ -266,6 +266,9 @@ H3Index H3_EXPORT(h3ToCenterChild)(H3Index h, int childRes) {
*/
int H3_EXPORT(compact)(const H3Index* h3Set, H3Index* compactedSet,
const int numHexes) {
if (numHexes == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need similar handling on uncompact?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uncompact and maxUncompactSize have for loops like for (int i = 0; i < numHexes; i++), so they are already exiting when the number of hexagons is 0. I added tests in this PR to confirm this.

@@ -266,6 +266,9 @@ H3Index H3_EXPORT(h3ToCenterChild)(H3Index h, int childRes) {
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be explicit about what codes are returned in success and failure cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So far we haven't done that in the public API, I think with the idea that the error codes might change in patch changes. The error codes have been used in some of the bindings to generate exception messages, though, so they are useful.

Copy link
Contributor

@ajfriend ajfriend left a comment

Choose a reason for hiding this comment

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

One small documentation comment. Otherwise, looks good to me!

@isaacbrodsky isaacbrodsky merged commit 4bdb15c into uber:master Sep 9, 2019
@isaacbrodsky isaacbrodsky deleted the compact-zero-length branch September 9, 2019 23:13
mrdvt92 pushed a commit to mrdvt92/h3 that referenced this pull request Jun 19, 2022
Handle empty (zero length) input to `compact`
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.

6 participants