-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow nullptr to be a valid item in the tree
- Loading branch information
Showing
2 changed files
with
16 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ad01225There 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.
If we can not support sorting
nullptrin the tree, I'd prefer that. In the tree implementation I'm working on a node uses 64 bytes, and supportingnullptras an item will, I think, push that up to 72 bytes which is not so nicely aligned.The use case for storing
nullptrseems to PyGEOS casting an integer to a pointer to store integers in the tree: https://github.com/pygeos/pygeos/blob/master/src/strtree.c#L175I'd be surprised if this isn't undefined behavior.
@jorisvandenbossche
ad01225There 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.
I take that back, looks like I'm still at 56 bytes. Not sure that changes my doubt about the need to store
nullptrthough.ad01225There 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.
I we can fix it on the PyGEOS side, I am certainly fine with GEOS not supporting storing null pointers. PyGEOS is a young enough project that it is fine to have us do a new release to correctly support GEOS 3.9, I think.
Now, I suppose the reason we cast the int to
void*is because that's the signature ofGEOSSTRtree_insert_rin the C API. But we're not experienced C programmers, so we might misinterpreted / miscoded this.ad01225There 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.
GEOS doesn't provide a way to store values in the tree, only pointers to values. Casting an
inttovoid*probably usually works, since they're usually the same size. But the compiler is not required to make it work. (That's what I mean by "undefined behavior"). To store integers in the tree, you need to keep the integers themselves in memory somewhere and store pointers to the integers in the tree.