refactor: introduce generics for toSet and findByKey helpers#20
Merged
AWaterColorPen merged 2 commits intomainfrom Apr 15, 2026
Merged
refactor: introduce generics for toSet and findByKey helpers#20AWaterColorPen merged 2 commits intomainfrom
AWaterColorPen merged 2 commits intomainfrom
Conversation
- Replace getKeySet() (returned map[any]struct{}) with toSet[T comparable]()
for type-safe O(1) membership tests
- Add generic findByKey[T models.IModel]() to eliminate repeated linear-search
loops in FileAdapter.GetDataSetByKey, GetMetricByKey, GetDimensionByKey
- Update .gitignore to exclude *.sh scripts
All existing tests pass.
AWaterColorPen
commented
Apr 14, 2026
| # vendor/ | ||
|
|
||
| .idea No newline at end of file | ||
| .idea*.sh |
Owner
Author
There was a problem hiding this comment.
.gitignore has a merge artifact: .idea and *.sh ended up concatenated on one line as .idea*.sh. This means neither pattern works correctly — .idea directory is no longer ignored, and only *.sh files adjacent to .idea would match (they don't). Should be split into two lines:
.idea
*.sh
I'll push a fix.
Owner
Author
There was a problem hiding this comment.
Fixed in ace4638 — split into two separate lines:
.idea
*.sh
The previous commit accidentally concatenated .idea and *.sh onto one line as '.idea*.sh', which broke both patterns. Separate them so that the .idea directory and *.sh files are both properly ignored.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR completes the generics modernization task from Phase 1 of the olap-sql modernization plan.
Changes
toSet[T comparable]([]T) map[T]struct{}: Replaces the oldgetKeySet([]string) map[any]struct{}. Now type-safe and pre-sized withmake(..., len(items))for better allocation efficiency.findByKey[T models.IModel](items []T, key, kind string) (T, error): A generic linear-search helper that eliminates three identicalforloops inFileAdapter(GetDataSetByKey,GetMetricByKey,GetDimensionByKey)..gitignore: Added*.shto exclude leftover shell scripts.Why generics here?
The old
getKeySetreturnedmap[any]struct{}— usinganyfor string keys lost type safety. The newtoSet[T]is properly typed.The three
GetXByKeymethods were copy-paste identical except for the element type. The genericfindByKeycollapses them into a single implementation backed by the existingmodels.IModelinterface.Tests
All existing tests pass (
go test ./...).