-
Notifications
You must be signed in to change notification settings - Fork 108
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
Fix the order of the map #268
Conversation
@PumpkinSeed, thanks for the PR! Great improvement! There's a similar implementation in the It would be great if we could use just one implementation. Should we make the type exportable? I also appreciate the benchmark tests you've created! |
What do you think of put it into the utils package? Also I prefer the Please let me know your thoughts on it. |
field/ordered_map.go
Outdated
@@ -17,8 +18,7 @@ func (om OrderedMap) MarshalJSON() ([]byte, error) { | |||
for k := range om { | |||
keys = append(keys, k) | |||
} | |||
|
|||
sort.Strings(keys) | |||
sort.Sort(sorting.Numeric(keys)) |
There 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.
as example here it will be sort.AlphaNumeric
I'm a bit late with response. We already have What if we:
@PumpkinSeed @adamdecaf thoughts? |
I'll also think about how to solve the usage of |
I tested it and the
|
I'm leaning towards 2nd option and not using |
I checked it and mostly it's used by tests. I will check the others and see what can happen in case of this change. |
Or have something like this: func StringsByInt(x []string) {
sort.Slice(x, stringsByInt(x, func(i, j int) bool {
panic("failed to sort strings by int: failed to convert string to int")
}))
}
func StringsByIntOrString(x []string) {
sort.Slice(x, stringsByInt(x, func(i, j int) bool {
return x[i] < x[j]
}))
}
func stringsByInt(x []string, fn func(i, j int) bool) func(i, j int) bool {
return func(i, j int) bool {
valI, err := strconv.Atoi(x[i])
if err != nil {
return fn(i, j)
}
valJ, err := strconv.Atoi(x[j])
if err != nil {
return fn(i, j)
}
return valI < valJ
}
} but it feels like overengineering the problem. It is used in these places:
In the specs the |
Also, there are 5 panics left in the code. What can I do with them to satisfy the linter? I would recommend the new slog package, but the users of the library wouldn't be happy if they just randomly getting logs after a package update instead of panics what they are prepared for. |
You can ignore linter for now. I'll create a separate PR. I'll either ignore linter alerts for |
If you create an issue I can work on that part. |
@PumpkinSeed here it is: #269. Thank your for your help! btw, are you in Moov's Slack channel about #iso8583? If no, join https://moov-io.slack.com/archives/C014UT7C3ST I would want to know more about how and for what you are using iso8583 :) |
Thanks for the PR! The linter is from a separate improvement we're making across all of our repositories. |
Resolve #125
I wrote a custom sort implementation this scenario. I know that by the documentation it shouldn't have letters in that key, but I wanted to handle that case as well, where the map's key is a letter or non-numeric.
Benchmarks:
I think there can be a few performance improvements especially for the
strconv.ParseUint
.