-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's not possible to make it work correctly in the face of NaNs without MapRange, but we do the best we can.
- Loading branch information
Showing
5 changed files
with
75 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ import "reflect" | |
func Compare(a, b reflect.Value) int { | ||
return compare(a, b) | ||
} | ||
|
||
const BrokenNaNs = brokenNaNs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// +build go1.12 | ||
|
||
package fmtsort | ||
|
||
import "reflect" | ||
|
||
const brokenNaNs = false | ||
|
||
func mapElems(mapValue reflect.Value) ([]reflect.Value, []reflect.Value) { | ||
key := make([]reflect.Value, mapValue.Len()) | ||
value := make([]reflect.Value, len(key)) | ||
iter := mapValue.MapRange() | ||
for i := 0; iter.Next(); i++ { | ||
key[i] = iter.Key() | ||
value[i] = iter.Value() | ||
} | ||
return key, value | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// +build !go1.12 | ||
|
||
package fmtsort | ||
|
||
import "reflect" | ||
|
||
const brokenNaNs = true | ||
|
||
func mapElems(mapValue reflect.Value) ([]reflect.Value, []reflect.Value) { | ||
key := mapValue.MapKeys() | ||
value := make([]reflect.Value, len(key)) | ||
for i, k := range key { | ||
v := mapValue.MapIndex(k) | ||
if !v.IsValid() { | ||
// Note: we can't retrieve the value, probably because | ||
// the key is NaN, so just do the best we can and | ||
// add a zero value of the correct type in that case. | ||
v = reflect.Zero(mapValue.Type().Elem()) | ||
} | ||
value[i] = v | ||
} | ||
return key, value | ||
} |
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