Created
May 28, 2017 15:07
-
-
Save cstockton/186a2e83d68cba221d3ced2eace6eef0 to your computer and use it in GitHub Desktop.
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
| package conv | |
| // Example of fastest possible atoi in Go aside from ASM, the unsightly | |
| // parenthesis and grouping is because I wrote this before the bounds check | |
| // elimination improvements so having them all on one was much faster I'm not | |
| // sure if this is still necessary, at least in the switch statement version I | |
| // think the length check should be enough. | |
| // | |
| // FastInt64-24 5000000 293 ns/op | |
| // Switch64-24 5000000 218 ns/op | |
| // Stdlib-24 500000 3085 ns/op | |
| // StdlibTyped-24 2000000 644 ns/op | |
| import ( | |
| "errors" | |
| "math" | |
| "strconv" | |
| "testing" | |
| ) | |
| var strToInt64 = []struct { | |
| from string | |
| to int64 | |
| }{ | |
| {"0", 0}, | |
| // {"-0", 0}, | |
| {"1", 1}, | |
| // {"-1", -1}, | |
| {"12", 12}, | |
| // {"-12", -12}, | |
| {"123", 123}, | |
| // {"-123", -123}, | |
| {"1234", 1234}, | |
| // {"-1234", -1234}, | |
| {"12345", 12345}, | |
| // {"-12345", -12345}, | |
| {"123456", 123456}, | |
| // {"-123456", -123456}, | |
| {"1234567", 1234567}, | |
| // {"-1234567", -1234567}, | |
| {"12345678", 12345678}, | |
| // {"-12345678", -12345678}, | |
| {"123456789", 123456789}, | |
| // {"-123456789", -123456789}, | |
| {"1234567890", 1234567890}, | |
| // {"-1234567890", -1234567890}, | |
| {"12345678901", 12345678901}, | |
| // {"-12345678901", -12345678901}, | |
| {"123456789012", 123456789012}, | |
| // {"-123456789012", -123456789012}, | |
| {"1234567890123", 1234567890123}, | |
| // {"-1234567890123", -1234567890123}, | |
| {"12345678901234", 12345678901234}, | |
| // {"-12345678901234", -12345678901234}, | |
| {"123456789012345", 123456789012345}, | |
| // {"-123456789012345", -123456789012345}, | |
| {"1234567890123456", 1234567890123456}, | |
| // {"-1234567890123456", -1234567890123456}, | |
| {"12345678901234567", 12345678901234567}, | |
| // {"-12345678901234567", -12345678901234567}, | |
| {"123456789012345678", 123456789012345678}, | |
| // {"-123456789012345678", -123456789012345678}, | |
| {"1234567890123456789", 1234567890123456789}, | |
| // {"-1234567890123456789", -1234567890123456789}, | |
| {"9223372036854775807", 1<<63 - 1}, | |
| // {"-9223372036854775808", -1 << 63}, | |
| } | |
| // Summary: | |
| // | |
| // BenchmarkInt/<slice size>/<from> to <to>/Conv: | |
| // Measures the most convenient form of conversion using this library. | |
| // | |
| // BenchmarkSlice/<slice size>/<from> to <to>/Conv: | |
| // Measures not using this library at all, pure Go implementation. | |
| // | |
| func BenchmarkInt(b *testing.B) { | |
| b.Run("string to int64", func(b *testing.B) { | |
| l := len(strToInt64) | |
| b.Run("LutInt64", func(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| for z := 0; z < l; z++ { | |
| v, err := LutInt64(strToInt64[z].from) | |
| if err != nil { | |
| b.Error(err) | |
| } | |
| if strToInt64[z].to != v { | |
| b.Errorf("(%T) %[1]v != %v (%[2]T)", strToInt64[z].to, v) | |
| } | |
| } | |
| } | |
| }) | |
| b.Run("Switch64", func(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| for z := 0; z < l; z++ { | |
| v := SwitchInt64(strToInt64[z].from) | |
| if strToInt64[z].to != v { | |
| b.Errorf("(%T) %[1]v != %v (%[2]T)", strToInt64[z].to, v) | |
| } | |
| } | |
| } | |
| }) | |
| b.Run("Stdlib", func(b *testing.B) { | |
| parseInt := func(from interface{}) (int64, error) { | |
| if T, ok := from.(string); ok { | |
| return strconv.ParseInt(T, 10, 0) | |
| } | |
| b.Fatal("expected string") | |
| return 0, nil | |
| } | |
| for i := 0; i < b.N; i++ { | |
| for z := 0; z < l; z++ { | |
| v, err := parseInt(strToInt64[z].from) | |
| if err != nil { | |
| b.Error(err) | |
| } | |
| if strToInt64[z].to != v { | |
| b.Errorf("(%T) %[1]v != %v (%[2]T)", strToInt64[z].to, v) | |
| } | |
| } | |
| } | |
| }) | |
| b.Run("StdlibTyped", func(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| for z := 0; z < l; z++ { | |
| v, err := strconv.ParseInt(strToInt64[z].from, 10, 0) | |
| if err != nil { | |
| b.Error(err) | |
| } | |
| if strToInt64[z].to != v { | |
| b.Errorf("(%T) %[1]v != %v (%[2]T)", strToInt64[z].to, v) | |
| } | |
| } | |
| } | |
| }) | |
| }) | |
| } | |
| var ( | |
| ErrRange = errors.New("value out of range") | |
| ErrEmpty = errors.New("value had no length") | |
| ) | |
| func LutInt64(from string) (int64, error) { | |
| switch { | |
| case len(from) == 0: | |
| return 0, ErrEmpty | |
| case from[0] == '+' || from[0] == '-': | |
| if len(from) > 19 { | |
| return math.MaxInt64, ErrRange | |
| } | |
| return int64(fastIntLut[len(from)-1](from[1:])), nil | |
| case len(from) > 19: | |
| return math.MaxInt64, ErrRange | |
| } | |
| return fastIntLut[len(from)](from), nil | |
| } | |
| var fastIntLut = []func(string) int64{ | |
| func(string) int64 { return 0 }, | |
| fastInt1, | |
| fastInt2, | |
| fastInt3, | |
| fastInt4, | |
| fastInt5, | |
| fastInt6, | |
| fastInt7, | |
| fastInt8, | |
| fastInt9, | |
| fastInt10, | |
| fastInt11, | |
| fastInt12, | |
| fastInt13, | |
| fastInt14, | |
| fastInt15, | |
| fastInt16, | |
| fastInt17, | |
| fastInt18, | |
| fastInt19, | |
| } | |
| func fastInt1(s string) int64 { | |
| return (int64(s[0]) - 48) | |
| } | |
| func fastInt2(s string) int64 { | |
| return ((int64(s[0]) - 48) * 10) + (int64(s[1]) - 48) | |
| } | |
| func fastInt3(s string) int64 { | |
| return ((int64(s[0]) - 48) * 100) + ((int64(s[1]) - 48) * 10) + (int64(s[2]) - 48) | |
| } | |
| func fastInt4(s string) int64 { | |
| return (((int64(s[0]) - 48) * 1000) + ((int64(s[1]) - 48) * 100)) + (((int64(s[2]) - 48) * 10) + (int64(s[3]) - 48)) | |
| } | |
| func fastInt5(s string) int64 { | |
| return (((int64(s[0]) - 48) * 10000) + ((int64(s[1]) - 48) * 1000)) + (((int64(s[2]) - 48) * 100) + ((int64(s[3]) - 48) * 10) + (int64(s[4]) - 48)) | |
| } | |
| func fastInt6(s string) int64 { | |
| return (((int64(s[0]) - 48) * 100000) + ((int64(s[1]) - 48) * 10000) + ((int64(s[2]) - 48) * 1000)) + (((int64(s[3]) - 48) * 100) + ((int64(s[4]) - 48) * 10) + (int64(s[5]) - 48)) | |
| } | |
| func fastInt7(s string) int64 { | |
| return (((int64(s[0]) - 48) * 1000000) + ((int64(s[1]) - 48) * 100000) + ((int64(s[2]) - 48) * 10000) + ((int64(s[3]) - 48) * 1000)) + (((int64(s[4]) - 48) * 100) + ((int64(s[5]) - 48) * 10) + (int64(s[6]) - 48)) | |
| } | |
| func fastInt8(s string) int64 { | |
| return (((int64(s[0]) - 48) * 10000000) + ((int64(s[1]) - 48) * 1000000) + ((int64(s[2]) - 48) * 100000) + ((int64(s[3]) - 48) * 10000) + ((int64(s[4]) - 48) * 1000)) + (((int64(s[5]) - 48) * 100) + ((int64(s[6]) - 48) * 10) + (int64(s[7]) - 48)) | |
| } | |
| func fastInt9(s string) int64 { | |
| return ((int64(s[0]) - 48) * 100000000) + ((int64(s[1]) - 48) * 10000000) + ((int64(s[2]) - 48) * 1000000) + ((int64(s[3]) - 48) * 100000) + ((int64(s[4]) - 48) * 10000) + ((int64(s[5]) - 48) * 1000) + ((int64(s[6]) - 48) * 100) + ((int64(s[7]) - 48) * 10) + (int64(s[8]) - 48) | |
| } | |
| func fastInt10(s string) int64 { | |
| return (((int64(s[0]) - 48) * 1000000000) + ((int64(s[1]) - 48) * 100000000) + ((int64(s[2]) - 48) * 10000000) + ((int64(s[3]) - 48) * 1000000) + ((int64(s[4]) - 48) * 100000)) + (((int64(s[5]) - 48) * 10000) + ((int64(s[6]) - 48) * 1000) + ((int64(s[7]) - 48) * 100) + ((int64(s[8]) - 48) * 10) + (int64(s[9]) - 48)) | |
| } | |
| func fastInt11(s string) int64 { | |
| return (((int64(s[0]) - 48) * 10000000000) + ((int64(s[1]) - 48) * 1000000000) + ((int64(s[2]) - 48) * 100000000) + ((int64(s[3]) - 48) * 10000000) + ((int64(s[4]) - 48) * 1000000) + ((int64(s[5]) - 48) * 100000)) + (((int64(s[6]) - 48) * 10000) + ((int64(s[7]) - 48) * 1000) + ((int64(s[8]) - 48) * 100) + ((int64(s[9]) - 48) * 10) + (int64(s[10]) - 48)) | |
| } | |
| func fastInt12(s string) int64 { | |
| return (((int64(s[0]) - 48) * 100000000000) + ((int64(s[1]) - 48) * 10000000000) + ((int64(s[2]) - 48) * 1000000000) + ((int64(s[3]) - 48) * 100000000) + ((int64(s[4]) - 48) * 10000000) + ((int64(s[5]) - 48) * 1000000) + ((int64(s[6]) - 48) * 100000)) + (((int64(s[7]) - 48) * 10000) + ((int64(s[8]) - 48) * 1000) + ((int64(s[9]) - 48) * 100) + ((int64(s[10]) - 48) * 10) + (int64(s[11]) - 48)) | |
| } | |
| func fastInt13(s string) int64 { | |
| return (((int64(s[0]) - 48) * 1000000000000) + ((int64(s[1]) - 48) * 100000000000) + ((int64(s[2]) - 48) * 10000000000) + ((int64(s[3]) - 48) * 1000000000) + ((int64(s[4]) - 48) * 100000000) + ((int64(s[5]) - 48) * 10000000) + ((int64(s[6]) - 48) * 1000000)) + (((int64(s[7]) - 48) * 100000) + ((int64(s[8]) - 48) * 10000) + ((int64(s[9]) - 48) * 1000) + ((int64(s[10]) - 48) * 100) + ((int64(s[11]) - 48) * 10) + (int64(s[12]) - 48)) | |
| } | |
| func fastInt14(s string) int64 { | |
| return (((int64(s[0]) - 48) * 10000000000000) + ((int64(s[1]) - 48) * 1000000000000) + ((int64(s[2]) - 48) * 100000000000) + ((int64(s[3]) - 48) * 10000000000) + ((int64(s[4]) - 48) * 1000000000) + ((int64(s[5]) - 48) * 100000000) + ((int64(s[6]) - 48) * 10000000) + ((int64(s[7]) - 48) * 1000000)) + (((int64(s[8]) - 48) * 100000) + ((int64(s[9]) - 48) * 10000) + ((int64(s[10]) - 48) * 1000) + ((int64(s[11]) - 48) * 100) + ((int64(s[12]) - 48) * 10) + (int64(s[13]) - 48)) | |
| } | |
| func fastInt15(s string) int64 { | |
| return (((int64(s[0]) - 48) * 100000000000000) + ((int64(s[1]) - 48) * 10000000000000) + ((int64(s[2]) - 48) * 1000000000000) + ((int64(s[3]) - 48) * 100000000000) + ((int64(s[4]) - 48) * 10000000000) + ((int64(s[5]) - 48) * 1000000000) + ((int64(s[6]) - 48) * 100000000) + ((int64(s[7]) - 48) * 10000000)) + (((int64(s[8]) - 48) * 1000000) + ((int64(s[9]) - 48) * 100000) + ((int64(s[10]) - 48) * 10000) + ((int64(s[11]) - 48) * 1000) + ((int64(s[12]) - 48) * 100) + ((int64(s[13]) - 48) * 10) + (int64(s[14]) - 48)) | |
| } | |
| func fastInt16(s string) int64 { | |
| return (((int64(s[0]) - 48) * 1000000000000000) + ((int64(s[1]) - 48) * 100000000000000) + ((int64(s[2]) - 48) * 10000000000000) + ((int64(s[3]) - 48) * 1000000000000) + ((int64(s[4]) - 48) * 100000000000) + ((int64(s[5]) - 48) * 10000000000) + ((int64(s[6]) - 48) * 1000000000) + ((int64(s[7]) - 48) * 100000000) + ((int64(s[8]) - 48) * 10000000)) + (((int64(s[9]) - 48) * 1000000) + ((int64(s[10]) - 48) * 100000) + ((int64(s[11]) - 48) * 10000) + ((int64(s[12]) - 48) * 1000) + ((int64(s[13]) - 48) * 100) + ((int64(s[14]) - 48) * 10) + (int64(s[15]) - 48)) | |
| } | |
| func fastInt17(s string) int64 { | |
| return (((int64(s[0]) - 48) * 10000000000000000) + ((int64(s[1]) - 48) * 1000000000000000) + ((int64(s[2]) - 48) * 100000000000000) + ((int64(s[3]) - 48) * 10000000000000) + ((int64(s[4]) - 48) * 1000000000000) + ((int64(s[5]) - 48) * 100000000000) + ((int64(s[6]) - 48) * 10000000000) + ((int64(s[7]) - 48) * 1000000000) + ((int64(s[8]) - 48) * 100000000)) + (((int64(s[9]) - 48) * 10000000) + ((int64(s[10]) - 48) * 1000000) + ((int64(s[11]) - 48) * 100000) + ((int64(s[12]) - 48) * 10000) + ((int64(s[13]) - 48) * 1000) + ((int64(s[14]) - 48) * 100) + ((int64(s[15]) - 48) * 10) + (int64(s[16]) - 48)) | |
| } | |
| func fastInt18(s string) int64 { | |
| return (((int64(s[0]) - 48) * 100000000000000000) + ((int64(s[1]) - 48) * 10000000000000000) + ((int64(s[2]) - 48) * 1000000000000000) + ((int64(s[3]) - 48) * 100000000000000) + ((int64(s[4]) - 48) * 10000000000000) + ((int64(s[5]) - 48) * 1000000000000) + ((int64(s[6]) - 48) * 100000000000) + ((int64(s[7]) - 48) * 10000000000) + ((int64(s[8]) - 48) * 1000000000) + ((int64(s[9]) - 48) * 100000000)) + (((int64(s[10]) - 48) * 10000000) + ((int64(s[11]) - 48) * 1000000) + ((int64(s[12]) - 48) * 100000) + ((int64(s[13]) - 48) * 10000) + ((int64(s[14]) - 48) * 1000) + ((int64(s[15]) - 48) * 100) + ((int64(s[16]) - 48) * 10) + (int64(s[17]) - 48)) | |
| } | |
| func fastInt19(s string) int64 { | |
| return (((int64(s[0]) - 48) * 1000000000000000000) + ((int64(s[1]) - 48) * 100000000000000000) + ((int64(s[2]) - 48) * 10000000000000000) + ((int64(s[3]) - 48) * 1000000000000000) + ((int64(s[4]) - 48) * 100000000000000) + ((int64(s[5]) - 48) * 10000000000000) + ((int64(s[6]) - 48) * 1000000000000) + ((int64(s[7]) - 48) * 100000000000) + ((int64(s[8]) - 48) * 10000000000) + ((int64(s[9]) - 48) * 1000000000)) + (((int64(s[10]) - 48) * 100000000) + ((int64(s[11]) - 48) * 10000000) + ((int64(s[12]) - 48) * 1000000) + ((int64(s[13]) - 48) * 100000) + ((int64(s[14]) - 48) * 10000) + ((int64(s[15]) - 48) * 1000) + ((int64(s[16]) - 48) * 100) + ((int64(s[17]) - 48) * 10) + (int64(s[18]) - 48)) | |
| } | |
| func SwitchInt64(s string) int64 { | |
| switch len(s) { | |
| case 0: | |
| return 0 | |
| case 1: | |
| return (int64(s[0]) - 48) | |
| case 2: | |
| return ((int64(s[0]) - 48) * 10) + (int64(s[1]) - 48) | |
| case 3: | |
| return ((int64(s[1]) - 48) * 10) + ((int64(s[2]) - 48) + ((int64(s[0]) - 48) * 100)) | |
| case 4: | |
| return (int64(s[3]) - 48) + (((int64(s[0]) - 48) * 1000) + ((int64(s[1]) - 48) * 100)) + ((int64(s[2]) - 48) * 10) | |
| case 5: | |
| return (int64(s[4]) - 48) + (((int64(s[0]) - 48) * 10000) + ((int64(s[1]) - 48) * 1000)) + (((int64(s[2]) - 48) * 100) + ((int64(s[3]) - 48) * 10)) | |
| case 6: | |
| return (((int64(s[0]) - 48) * 100000) + ((int64(s[1]) - 48) * 10000) + ((int64(s[2]) - 48) * 1000)) + (((int64(s[3]) - 48) * 100) + ((int64(s[4]) - 48) * 10) + (int64(s[5]) - 48)) | |
| case 7: | |
| return (((int64(s[0]) - 48) * 1000000) + ((int64(s[1]) - 48) * 100000) + ((int64(s[2]) - 48) * 10000) + ((int64(s[3]) - 48) * 1000)) + (((int64(s[4]) - 48) * 100) + ((int64(s[5]) - 48) * 10) + (int64(s[6]) - 48)) | |
| case 8: | |
| return (int64(s[7]) - 48) + (((int64(s[0]) - 48) * 10000000) + ((int64(s[1]) - 48) * 1000000) + ((int64(s[2]) - 48) * 100000) + ((int64(s[3]) - 48) * 10000) + ((int64(s[4]) - 48) * 1000)) + (((int64(s[5]) - 48) * 100) + ((int64(s[6]) - 48) * 10)) | |
| case 9: | |
| return (int64(s[8]) - 48) + ((int64(s[0]) - 48) * 100000000) + ((int64(s[1]) - 48) * 10000000) + ((int64(s[2]) - 48) * 1000000) + ((int64(s[3]) - 48) * 100000) + ((int64(s[4]) - 48) * 10000) + ((int64(s[5]) - 48) * 1000) + ((int64(s[6]) - 48) * 100) + ((int64(s[7]) - 48) * 10) | |
| case 10: | |
| return (int64(s[9]) - 48) + (((int64(s[0]) - 48) * 1000000000) + ((int64(s[1]) - 48) * 100000000) + ((int64(s[2]) - 48) * 10000000) + ((int64(s[3]) - 48) * 1000000) + ((int64(s[4]) - 48) * 100000)) + (((int64(s[5]) - 48) * 10000) + ((int64(s[6]) - 48) * 1000) + ((int64(s[7]) - 48) * 100) + ((int64(s[8]) - 48) * 10)) | |
| case 11: | |
| return (int64(s[10]) - 48) + (((int64(s[0]) - 48) * 10000000000) + ((int64(s[1]) - 48) * 1000000000) + ((int64(s[2]) - 48) * 100000000) + ((int64(s[3]) - 48) * 10000000) + ((int64(s[4]) - 48) * 1000000) + ((int64(s[5]) - 48) * 100000)) + (((int64(s[6]) - 48) * 10000) + ((int64(s[7]) - 48) * 1000) + ((int64(s[8]) - 48) * 100) + ((int64(s[9]) - 48) * 10)) | |
| case 12: | |
| return (int64(s[11]) - 48) + (((int64(s[0]) - 48) * 100000000000) + ((int64(s[1]) - 48) * 10000000000) + ((int64(s[2]) - 48) * 1000000000) + ((int64(s[3]) - 48) * 100000000) + ((int64(s[4]) - 48) * 10000000) + ((int64(s[5]) - 48) * 1000000) + ((int64(s[6]) - 48) * 100000)) + (((int64(s[7]) - 48) * 10000) + ((int64(s[8]) - 48) * 1000) + ((int64(s[9]) - 48) * 100) + ((int64(s[10]) - 48) * 10)) | |
| case 13: | |
| return (int64(s[12]) - 48) + (((int64(s[0]) - 48) * 1000000000000) + ((int64(s[1]) - 48) * 100000000000) + ((int64(s[2]) - 48) * 10000000000) + ((int64(s[3]) - 48) * 1000000000) + ((int64(s[4]) - 48) * 100000000) + ((int64(s[5]) - 48) * 10000000) + ((int64(s[6]) - 48) * 1000000)) + (((int64(s[7]) - 48) * 100000) + ((int64(s[8]) - 48) * 10000) + ((int64(s[9]) - 48) * 1000) + ((int64(s[10]) - 48) * 100) + ((int64(s[11]) - 48) * 10)) | |
| case 14: | |
| return (int64(s[13]) - 48) + (((int64(s[0]) - 48) * 10000000000000) + ((int64(s[1]) - 48) * 1000000000000) + ((int64(s[2]) - 48) * 100000000000) + ((int64(s[3]) - 48) * 10000000000) + ((int64(s[4]) - 48) * 1000000000) + ((int64(s[5]) - 48) * 100000000) + ((int64(s[6]) - 48) * 10000000) + ((int64(s[7]) - 48) * 1000000)) + (((int64(s[8]) - 48) * 100000) + ((int64(s[9]) - 48) * 10000) + ((int64(s[10]) - 48) * 1000) + ((int64(s[11]) - 48) * 100) + ((int64(s[12]) - 48) * 10)) | |
| case 15: | |
| return (int64(s[14]) - 48) + (((int64(s[0]) - 48) * 100000000000000) + ((int64(s[1]) - 48) * 10000000000000) + ((int64(s[2]) - 48) * 1000000000000) + ((int64(s[3]) - 48) * 100000000000) + ((int64(s[4]) - 48) * 10000000000) + ((int64(s[5]) - 48) * 1000000000) + ((int64(s[6]) - 48) * 100000000) + ((int64(s[7]) - 48) * 10000000)) + (((int64(s[8]) - 48) * 1000000) + ((int64(s[9]) - 48) * 100000) + ((int64(s[10]) - 48) * 10000) + ((int64(s[11]) - 48) * 1000) + ((int64(s[12]) - 48) * 100) + ((int64(s[13]) - 48) * 10)) | |
| case 16: | |
| return (int64(s[15]) - 48) + (((int64(s[0]) - 48) * 1000000000000000) + ((int64(s[1]) - 48) * 100000000000000) + ((int64(s[2]) - 48) * 10000000000000) + ((int64(s[3]) - 48) * 1000000000000) + ((int64(s[4]) - 48) * 100000000000) + ((int64(s[5]) - 48) * 10000000000) + ((int64(s[6]) - 48) * 1000000000) + ((int64(s[7]) - 48) * 100000000) + ((int64(s[8]) - 48) * 10000000)) + (((int64(s[9]) - 48) * 1000000) + ((int64(s[10]) - 48) * 100000) + ((int64(s[11]) - 48) * 10000) + ((int64(s[12]) - 48) * 1000) + ((int64(s[13]) - 48) * 100) + ((int64(s[14]) - 48) * 10)) | |
| case 17: | |
| return (int64(s[16]) - 48) + (((int64(s[0]) - 48) * 10000000000000000) + ((int64(s[1]) - 48) * 1000000000000000) + ((int64(s[2]) - 48) * 100000000000000) + ((int64(s[3]) - 48) * 10000000000000) + ((int64(s[4]) - 48) * 1000000000000) + ((int64(s[5]) - 48) * 100000000000) + ((int64(s[6]) - 48) * 10000000000) + ((int64(s[7]) - 48) * 1000000000) + ((int64(s[8]) - 48) * 100000000)) + (((int64(s[9]) - 48) * 10000000) + ((int64(s[10]) - 48) * 1000000) + ((int64(s[11]) - 48) * 100000) + ((int64(s[12]) - 48) * 10000) + ((int64(s[13]) - 48) * 1000) + ((int64(s[14]) - 48) * 100) + ((int64(s[15]) - 48) * 10)) | |
| case 18: | |
| return (int64(s[17]) - 48) + (((int64(s[0]) - 48) * 100000000000000000) + ((int64(s[1]) - 48) * 10000000000000000) + ((int64(s[2]) - 48) * 1000000000000000) + ((int64(s[3]) - 48) * 100000000000000) + ((int64(s[4]) - 48) * 10000000000000) + ((int64(s[5]) - 48) * 1000000000000) + ((int64(s[6]) - 48) * 100000000000) + ((int64(s[7]) - 48) * 10000000000) + ((int64(s[8]) - 48) * 1000000000) + ((int64(s[9]) - 48) * 100000000)) + (((int64(s[10]) - 48) * 10000000) + ((int64(s[11]) - 48) * 1000000) + ((int64(s[12]) - 48) * 100000) + ((int64(s[13]) - 48) * 10000) + ((int64(s[14]) - 48) * 1000) + ((int64(s[15]) - 48) * 100) + ((int64(s[16]) - 48) * 10)) | |
| case 19: | |
| return (int64(s[18]) - 48) + (((int64(s[0]) - 48) * 1000000000000000000) + ((int64(s[1]) - 48) * 100000000000000000) + ((int64(s[2]) - 48) * 10000000000000000) + ((int64(s[3]) - 48) * 1000000000000000) + ((int64(s[4]) - 48) * 100000000000000) + ((int64(s[5]) - 48) * 10000000000000) + ((int64(s[6]) - 48) * 1000000000000) + ((int64(s[7]) - 48) * 100000000000) + ((int64(s[8]) - 48) * 10000000000) + ((int64(s[9]) - 48) * 1000000000)) + (((int64(s[10]) - 48) * 100000000) + ((int64(s[11]) - 48) * 10000000) + ((int64(s[12]) - 48) * 1000000) + ((int64(s[13]) - 48) * 100000) + ((int64(s[14]) - 48) * 10000) + ((int64(s[15]) - 48) * 1000) + ((int64(s[16]) - 48) * 100) + ((int64(s[17]) - 48) * 10)) | |
| default: | |
| return math.MaxInt64 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment