Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["jump_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//vendor/github.com/smartystreets/goconvey/convey:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["jump.go"],
importpath = "go-common/app/service/openplatform/abtest/model/jump",
tags = ["automanaged"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,30 @@
package jump
import (
"bytes"
"crypto/md5"
"encoding/binary"
)
//Hash get result by hash
func Hash(key uint64, numBuckets int) int32 {
var b int64 = -1
var j int64
for j < int64(numBuckets) {
b = j
key = key*2862933555777941757 + 1
j = int64(float64(b+1) * (float64(int64(1)<<31) / float64((key>>33)+1)))
}
return int32(b)
}
//Md5 get result by Md5
func Md5(key string) uint64 {
var x uint64
s := md5.Sum([]byte(key))
b := bytes.NewBuffer(s[:])
binary.Read(b, binary.BigEndian, &x)
return x
}

View File

@@ -0,0 +1,40 @@
package jump
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
type hashStruct struct {
value uint64
exp int32
}
func Test_Hash(t *testing.T) {
Convey("Test_Hash: ", t, func() {
h := hashStruct{
value: uint64(314978625),
exp: int32(18),
}
bucket := 100
v := Hash(h.value, bucket)
So(v, ShouldEqual, h.exp)
})
}
type md5Struct struct {
value string
exp uint64
}
func Test_Md5(t *testing.T) {
Convey("Test_Hash: ", t, func() {
h := md5Struct{
value: "987654321",
exp: uint64(7979946199622949865),
}
v := Md5(h.value)
So(v, ShouldEqual, h.exp)
})
}