Skip to content

Conversation

@peterstace
Copy link
Owner

Description

The rtree package previously hardcoded record IDs as integers, requiring users to maintain separate mappings between their records and integer IDs. This added unnecessary indirection and made the API less ergonomic.

By making RTree generic over the record type T, users can now store their actual records directly in the tree (or use integers if they prefer to keep the existing behaviour). This simplifies usage patterns and eliminates the need for separate index mappings in consuming code.

Note: This is a breaking change. The easiest way for users to upgrade is to simply replace all occurrences of *rtree.RTree with *rtree.RTree[int] in their codebase.

Check List

Have you:

  • Added unit tests? Yes.

  • Add cmprefimpl tests? (if appropriate?) N/A

  • Updated release notes? (if appropriate?) Yes.

The `rtree` package previously hardcoded record IDs as integers,
requiring users to maintain separate mappings between their records and
integer IDs. This added unnecessary indirection and made the API less
ergonomic.

By making `RTree` generic over the record type T, users can now store
their actual records directly in the tree (or use integers if they
prefer to keep the existing behaviour). This simplifies usage patterns
and eliminates the need for separate index mappings in consuming code.

Note: This is a breaking change. The easiest way for users to upgrade is
to simply replace all occurrences of `*rtree.RTree` with
`*rtree.RTree[int]` in their codebase.
@peterstace peterstace self-assigned this Nov 7, 2025
@peterstace peterstace requested a review from Copilot November 7, 2025 05:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR makes the rtree package generic over record type, eliminating the need for users to maintain separate mappings between integer IDs and their actual records. Previously, the package hardcoded record IDs as integers; now users can store records of any type directly in the tree.

Key changes:

  • Made RTree, node, entry, and BulkItem generic over type parameter T
  • Renamed RecordID field to Record and changed callback signatures from func(recordID int) to func(record T)
  • Updated all consumers in the geom package to use RTree[int] to maintain existing behavior

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rtree/rtree.go Core rtree types made generic with type parameter T
rtree/bulk.go BulkLoad functions updated to support generic record types
rtree/nearest.go Nearest neighbor search functions updated for generic records
rtree/box.go Helper function updated to work with generic nodes
rtree/rtree_internal_test.go Tests updated to use RTree[int] and new Record field
rtree/perf_internal_test.go Performance tests updated for generic API
rtree/nearest_internal_test.go Nearest neighbor tests updated for generic API
rtree/golden_internal_test.go Golden tests updated to reference record field
rtree/quick_partition_internal_test.go Partition tests updated for BulkItem[int]
geom/*.go All rtree consumers updated to use RTree[int]
.golangci.yaml Linter configuration adjusted for generic types
CHANGELOG.md Breaking change documented with migration guidance

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

errcheck:
exclude-functions:
- io.Copy(os.Stdout)
- (*github.com/peterstace/simplefeatures/rtree.RTree).RangeSearch
Copy link
Owner Author

Choose a reason for hiding this comment

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

errcheck seems to get a bit confused when generics are introduced... I can longer specify funcs in exclude-functions section. Instead, I've opted to just use _ = ... whenever I want to ignore an error.

- gomnd
- inamedparam
- interfacebloat
- ireturn
Copy link
Owner Author

Choose a reason for hiding this comment

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

I return has a false positive when using generics. Seems like not really that useful for this project, so disabled.

Copy link
Owner Author

Choose a reason for hiding this comment

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

TODOs:

  • Run benchmarks tests to check for a performance regression.
  • Update geom package to make better use of the generic RTree (we shouldn't need the separate arrays to hold the records any more!).

@peterstace peterstace marked this pull request as draft November 21, 2025 03:08
@peterstace peterstace changed the title Make rtree package generic over record type DRAFT/WIP: Make rtree package generic over record type Nov 21, 2025
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