-
-
Notifications
You must be signed in to change notification settings - Fork 0
🐛 enhance Utils with overflow handling and list limit enforcement #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
430f84c
:bug: enhance Utils with overflow handling and list limit enforcement
techouse f2ec764
:white_check_mark: add test for Utils.refreshOverflowMaxIndex to veri…
techouse 24fc76d
:bug: enhance Utils.combine to flatten arrays when appending to overf…
techouse 647fb58
:bug: refactor Utils to use intIndex for key conversion and update te…
techouse f467266
:bug: optimize array appending in Utils.appendCombineValue to improve…
techouse ede5dbc
:bug: update overflow max index handling in Utils.merge to account fo…
techouse 2085143
:bug: simplify overflow key handling in Utils by removing unnecessary…
techouse ef812dc
:bug: update ReerKit dependency version to 1.2.2 in Package.swift and…
techouse 12dee9c
:bug: add documentation for refreshOverflowMaxIndex to clarify its pu…
techouse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import Foundation | ||
|
|
||
| extension Utils { | ||
| internal struct OverflowKey: Hashable, Sendable {} | ||
|
|
||
| @usableFromInline | ||
| internal static let overflowKey = OverflowKey() | ||
|
|
||
| @inline(__always) | ||
| @usableFromInline | ||
| internal static func intIndex(_ key: AnyHashable) -> Int? { | ||
| if let intValue = key.base as? Int { return intValue } | ||
| if let number = key.base as? NSNumber { return number.intValue } | ||
| return nil | ||
| } | ||
|
|
||
| @usableFromInline | ||
| internal static func isOverflow(_ value: Any?) -> Bool { | ||
| guard let dict = value as? [AnyHashable: Any] else { return false } | ||
| return dict[overflowKey] is Int | ||
| } | ||
|
|
||
| @usableFromInline | ||
| internal static func overflowMaxIndex(_ dict: [AnyHashable: Any]) -> Int? { | ||
| dict[overflowKey] as? Int | ||
| } | ||
|
|
||
| @usableFromInline | ||
| internal static func setOverflowMaxIndex(_ dict: inout [AnyHashable: Any], _ maxIndex: Int) { | ||
| dict[overflowKey] = maxIndex | ||
| } | ||
|
|
||
| @usableFromInline | ||
| internal static func markOverflow( | ||
| _ dict: [AnyHashable: Any], | ||
| maxIndex: Int | ||
| ) -> [AnyHashable: Any] { | ||
| var copy = dict | ||
| copy[overflowKey] = maxIndex | ||
| return copy | ||
| } | ||
|
|
||
| @usableFromInline | ||
| internal static func isOverflowKey(_ key: AnyHashable) -> Bool { | ||
| key.base is OverflowKey | ||
| } | ||
|
|
||
| @usableFromInline | ||
| /// Scans non-overflow keys to compute the maximum integer index and stores it. | ||
| /// Sets -1 if no integer keys are present. | ||
| internal static func refreshOverflowMaxIndex(_ dict: inout [AnyHashable: Any]) { | ||
| var maxIndex = -1 | ||
| for key in dict.keys where !isOverflowKey(key) { | ||
| if let idx = intIndex(key), idx > maxIndex { | ||
| maxIndex = idx | ||
| } | ||
| } | ||
| setOverflowMaxIndex(&dict, maxIndex) | ||
| } | ||
techouse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.