本文整理汇总了Golang中hash/crc64.Checksum函数的典型用法代码示例。如果您正苦于以下问题:Golang Checksum函数的具体用法?Golang Checksum怎么用?Golang Checksum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Checksum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Partition
func (id *Id) Partition(max uint64) uint64 {
b, err := id.Encode()
if err != nil {
panic(err)
}
return crc64.Checksum(b, partitionTable) % max
}
示例2: BenchmarkCRC64ISOShort
func BenchmarkCRC64ISOShort(b *testing.B) {
var bv uint64
k := []byte("Test-key-100")
for i := 0; i < b.N; i++ {
bv += crc64.Checksum(k, crc64ISO)
}
}
示例3: Hash
func (m M) Hash() int64 {
if m.X != nil {
return m.X.Hash()
} else if len(m.S) == 0 {
return m.N
}
return int64(crc64.Checksum([]byte(m.S), CrcPolynomial))
}
示例4: HashVbuuid
// HashVbuuid return crc64 value of list of 64-bit vbuuids.
func HashVbuuid(vbuuids []uint64) uint64 {
var bytes []byte
vbuuids_sl := (*reflect.SliceHeader)(unsafe.Pointer(&vbuuids))
bytes_sl := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
bytes_sl.Data = vbuuids_sl.Data
bytes_sl.Len = vbuuids_sl.Len * 8
bytes_sl.Cap = vbuuids_sl.Cap * 8
return crc64.Checksum(bytes, crc64.MakeTable(crc64.ECMA))
}
示例5: FileCRC64
func FileCRC64(filenameOrURL string) (uint64, error) {
data, err := FileGetBytes(filenameOrURL)
if err != nil {
return 0, err
}
if crc64Table == nil {
crc64Table = crc64.MakeTable(crc64.ECMA)
}
return crc64.Checksum(data, crc64Table), nil
}
示例6: Sum64
func (h *crcHash) Sum64() uint64 {
sort.Sort(h.factors)
data := make([]byte, len(h.factors)*8+1)
data[0] = h.prefix
for i, factor := range h.factors {
binary.LittleEndian.PutUint64(data[i*8+1:], factor)
}
return crc64.Checksum(data, crcTable)
}
示例7: hash
// compute a hashcode for ExecutorInfo that may be used as a reasonable litmus test
// with respect to compatibility across HA schedulers. the intent is that an HA scheduler
// should fail-fast if it doesn't pass this test, rather than generating (potentially many)
// errors at run-time because a Mesos master decides that the ExecutorInfo generated by a
// secondary scheduler doesn't match that of the primary scheduler.
//
// Note: We intentionally leave out the Resources in this hash because they are
// set during procurement and should not lead to a different ExecutorId.
// This also means that the Resources do not contribute to offer
// compatibility checking. But as we persist and restore the Resources
// through node anotation we make sure that the right resources are chosen
// during task launch.
//
// see https://github.com/apache/mesos/blob/0.22.0/src/common/type_utils.cpp#L110
func hash(info *mesos.ExecutorInfo) uint64 {
// !!! we specifically do NOT include:
// - Framework ID because it's a value that's initialized too late for us to use
// - Executor ID because it's a value that includes a copy of this hash
buf := &bytes.Buffer{}
buf.WriteString(info.GetName())
buf.WriteString(info.GetSource())
buf.Write(info.Data)
if info.Command != nil {
buf.WriteString(info.Command.GetValue())
buf.WriteString(info.Command.GetUser())
buf.WriteString(strconv.FormatBool(info.Command.GetShell()))
if sz := len(info.Command.Arguments); sz > 0 {
x := make([]string, sz)
copy(x, info.Command.Arguments)
sort.Strings(x)
for _, item := range x {
buf.WriteString(item)
}
}
if vars := info.Command.Environment.GetVariables(); len(vars) > 0 {
names := []string{}
e := make(map[string]string)
for _, v := range vars {
if name := v.GetName(); name != "" {
names = append(names, name)
e[name] = v.GetValue()
}
}
sort.Strings(names)
for _, n := range names {
buf.WriteString(n)
buf.WriteString("=")
buf.WriteString(e[n])
}
}
if uris := info.Command.GetUris(); len(uris) > 0 {
su := []string{}
for _, uri := range uris {
su = append(su, fmt.Sprintf("%s%t%t", uri.GetValue(), uri.GetExecutable(), uri.GetExtract()))
}
sort.Strings(su)
for _, uri := range su {
buf.WriteString(uri)
}
}
//TODO(jdef) add support for Container
}
table := crc64.MakeTable(crc64.ECMA)
return crc64.Checksum(buf.Bytes(), table)
}
示例8: NewRand
// NewRand returns a seeded random number generator, using a seed derived
// from the provided string.
//
// If the seed string is empty, the current time is used as a seed.
func NewRand(seed string) *rand.Rand {
var seedInt int64
if seed != "" {
crcTable := crc64.MakeTable(crc64.ISO)
seedInt = int64(crc64.Checksum([]byte(seed), crcTable))
} else {
seedInt = time.Now().Unix()
}
randSource := rand.NewSource(seedInt)
return rand.New(randSource)
}
示例9: WorBig
// WorBig generates string for multi-precision integer n, count of words
// calculated as:
// (bitLength(n) / 16) rounded towards infinity
func WorBig(n *big.Int) string {
switch {
case n.BitLen() <= 16:
return Wor(n.Int64(), 1)
case n.BitLen() <= 32:
return Wor(n.Int64(), 2)
case n.BitLen() <= 64:
return Wor(n.Int64(), 4)
default:
sum := crc64.Checksum(n.Bytes(), crc64.MakeTable(crc64.ECMA))
return Wor(int64(sum), (n.BitLen()+16)/16)
}
}
示例10: downloadJson
func (v *VagrantShareRemoteWatcher) downloadJson(table *crc64.Table) (uint64, *VagrantBoxDescripter, error) {
body, err := v.jsonGetter(v.url)
if err != nil {
return 0, nil, err
}
checksum64 := crc64.Checksum(body, table)
var descripter VagrantBoxDescripter
json.Unmarshal(body, &descripter)
return checksum64, &descripter, nil
}
示例11: calculateCRC64Hash
func calculateCRC64Hash(filename string) string {
var buffer []byte = make([]byte, 1024**NumberOfBytesToRead)
f, err := os.Open(filename)
defer f.Close()
if err != nil {
log.Panic(err)
}
_, err = f.Read(buffer)
if err != nil {
log.Panic(err)
}
return fmt.Sprintf("%d", crc64.Checksum(buffer, crc64.MakeTable(crc64.ISO)))
}
示例12: newUserPermission
func newUserPermission(fields []proto.Field, values []sqltypes.Value) *UserPermission {
up := &UserPermission{Privileges: make(map[string]string)}
for i, field := range fields {
switch field.Name {
case "Host":
up.Host = values[i].String()
case "User":
up.User = values[i].String()
case "Password":
up.PasswordChecksum = crc64.Checksum(([]byte)(values[i].String()), hashTable)
default:
up.Privileges[field.Name] = values[i].String()
}
}
return up
}
示例13: Lookup
// Lookup looks up a path
func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
logrus.WithField("name", name).Debug("handling Root.Lookup call")
// TODO: handle context cancellation
secret, err := r.logic.Read(path.Join(r.root, name))
if secret == nil && err == nil {
return nil, fuse.ENOENT
} else if err != nil {
logrus.WithError(err).WithFields(logrus.Fields{"root": r.root, "name": name}).Error("error reading key")
return nil, fuse.EIO
}
return Secret{
secret,
crc64.Checksum([]byte(name), table),
}, nil
}
示例14: Hash
func (o *JDict) Hash() int64 {
panic("TODO")
//#if 0
var z int64
//#if mudict
o.mu.Lock()
//#endif
for k, v := range o.ppp {
z += int64(crc64.Checksum([]byte(k), CrcPolynomial))
z += v.Hash() // TODO better
}
//#if mudict
o.mu.Unlock()
//#endif
return z
//#endif
}
示例15: TestNextPowerOf2
func TestNextPowerOf2(t *testing.T) {
test := []struct {
n uint64
next uint64
}{
{0, 0},
{1, 1},
{2, 2},
{3, 2},
{5, 3},
{16, 5},
{1 << 33, 34},
}
t.Log(crc64.Checksum([]byte("Paul Taysom"), hashTable))
for _, v := range test {
if nextPowerOf2(v.n) != v.next {
t.Errorf("nextPowerOf2(%d) != %d\n", v.n, v.next)
}
}
}