Ai
1 Star 0 Fork 0

Saberml/sqlparser

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_driver_helper.go 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
20162180064 提交于 2019-12-16 11:30 +08:00 . remove dependency on TiDB (#679)
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
//+build !codes
package test_driver
import (
"math"
)
func isSpace(c byte) bool {
return c == ' ' || c == '\t'
}
func isDigit(c byte) bool {
return c >= '0' && c <= '9'
}
func myMin(a, b int) int {
if a < b {
return a
}
return b
}
func pow10(x int) int32 {
return int32(math.Pow10(x))
}
func Abs(n int64) int64 {
y := n >> 63
return (n ^ y) - y
}
// uintSizeTable is used as a table to do comparison to get uint length is faster than doing loop on division with 10
var uintSizeTable = [21]uint64{
0, // redundant 0 here, so to make function StrLenOfUint64Fast to count from 1 and return i directly
9, 99, 999, 9999, 99999,
999999, 9999999, 99999999, 999999999, 9999999999,
99999999999, 999999999999, 9999999999999, 99999999999999, 999999999999999,
9999999999999999, 99999999999999999, 999999999999999999, 9999999999999999999,
math.MaxUint64,
} // math.MaxUint64 is 18446744073709551615 and it has 20 digits
// StrLenOfUint64Fast efficiently calculate the string character lengths of an uint64 as input
func StrLenOfUint64Fast(x uint64) int {
for i := 1; ; i++ {
if x <= uintSizeTable[i] {
return i
}
}
}
// StrLenOfInt64Fast efficiently calculate the string character lengths of an int64 as input
func StrLenOfInt64Fast(x int64) int {
size := 0
if x < 0 {
size = 1 // add "-" sign on the length count
}
return size + StrLenOfUint64Fast(uint64(Abs(x)))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/saberml_finacia/sqlparser.git
git@gitee.com:saberml_finacia/sqlparser.git
saberml_finacia
sqlparser
sqlparser
v1.0.1

搜索帮助