Skip to content

getIndexDigit#1024

Merged
isaacbrodsky merged 6 commits intouber:masterfrom
isaacbrodsky:get-index-digit
Jul 13, 2025
Merged

getIndexDigit#1024
isaacbrodsky merged 6 commits intouber:masterfrom
isaacbrodsky:get-index-digit

Conversation

@isaacbrodsky
Copy link
Copy Markdown
Collaborator

#1022

This adds functions for retrieving index digits and the reserved bits from indexes. The reserved bits may be of interest for directedEdge / vertex mode where knowing which one it is are helpful.

Note that I chose to allow getIndexDigit to read unused digits; we could instead choose to disallow reading those digits from this function as they (probably) shouldn't be used as three-wide bit fields in that case.

Does not have CLI tests just yet.

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 30, 2025

Coverage Status

coverage: 98.934% (+0.02%) from 98.911%
when pulling f190a3c on isaacbrodsky:get-index-digit
into 73cf911 on uber:master.

Comment on lines +326 to +346
<TabItem value="python">

```py
h3.get_index_digit(h, digit)
```

</TabItem>
<TabItem value="go">

```go
cell.IndexDigit(digit)
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_get_index_digit(h, digit)
```

</TabItem>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we sure we want to add these to the docs before they're actually implemented in the bindings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it's helpful to show what it would look like in the bindings, and I would expect the bindings update very quickly to have these functions as they're quite simple.

Comment thread src/h3lib/lib/h3Index.c Outdated
int H3_EXPORT(getReservedBits)(H3Index h) { return H3_GET_RESERVED_BITS(h); }

/**
* Returns the index digits at `digit`, which starts with 1 for resolution
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would use "resolution" here to specify the function input, and "digit" as the function output. I think that's more in line with how we use resolution elsewhere.

From the docs:

This is followed by a sequence of r digits 0-6, where each ith digit di specifies one of the 7 cells
centered on the cell indicated by the coarser resolution digits d1 through di-1. A local hexagon
coordinate system is assigned to each of the resolution 0 base cells and is used to orient all
hierarchical indexing child cells of that base cell. The assignment of digits 0-6 at each resolution
uses a Central Place Indexing arrangement (see [Sahr, 2014](http://webpages.sou.edu/~sahrk/sqspc/pubs/autocarto14.pdf))

But maybe that's just me. What do others think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generally, a variable named res or resolution indicates to the user that it is an integer taking values 0--15. (In this case, its a little more restrictive at 1--15.) And digit indicates something taking values 0--6 (or 7 to indicate an invalid digit). I'd keep that same convention here.

Elsewhere in the codebase, we use res as the second argument to the H3_GET_INDEX_DIGIT macro, like here:

if (res == 0 || H3_GET_INDEX_DIGIT(cell, res) != CENTER_DIGIT) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As does the macro definition:

#define H3_GET_INDEX_DIGIT(h3, res) \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated to rename that parameter to res.

@zachasme
Copy link
Copy Markdown
Contributor

zachasme commented Jul 5, 2025

This would help resolve #277 (the inspection part).

Copy link
Copy Markdown
Collaborator

@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.

Looks good to me, thanks!

I have some non-blocking questions about the Doxygen comments, but we can handle those separately, since they're not particular to this PR---I'm just noticing them now. Basically, it looks like we generally split Doxygen comment information across .h and .c files. Should we combine them to a single source of truth (e.g., the .h file)? Or is there a reason we separate them?

Comment thread src/h3lib/lib/h3Index.c Outdated
* @param h The H3 index.
* @return The reserved bits of the H3 index argument.
*/
int H3_EXPORT(getReservedBits)(H3Index h) { return H3_GET_RESERVED_BITS(h); }
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do we have a better name here?

@isaacbrodsky isaacbrodsky changed the title getIndexDigit and getReservedBits getIndexDigit Jul 11, 2025
@isaacbrodsky
Copy link
Copy Markdown
Collaborator Author

I updated this PR to not include getReservedBits as I wasn't sure about that name.

@ajfriend ajfriend self-requested a review July 11, 2025 08:57
Copy link
Copy Markdown
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.

Couple of documentation comments, otherwise LGTM

Comment thread src/h3lib/lib/h3Index.c Outdated
Comment thread src/h3lib/include/h3api.h.in Outdated
Comment thread website/docs/api/inspection.mdx Outdated
Comment on lines +192 to +193
Returns an indexing digit of the index.
Works for cells, edges and vertexes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this need more info about what an indexing digit is, or a link to the bit layout docs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This could certainly use more content. Also please note I hid the other bindings until this version of H3 is released.

@isaacbrodsky isaacbrodsky merged commit 2257ace into uber:master Jul 13, 2025
45 checks passed
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