當前位置: 首頁>>代碼示例>>Golang>>正文


Golang crc64.Checksum函數代碼示例

本文整理匯總了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
}
開發者ID:ryandotsmith,項目名稱:l2met,代碼行數:7,代碼來源:id.go

示例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)
	}
}
開發者ID:wheelcomplex,項目名稱:xxhash-1,代碼行數:7,代碼來源:xxhash_test.go

示例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))
}
開發者ID:strickyak,項目名稱:rye,代碼行數:9,代碼來源:fast.pre.go

示例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))
}
開發者ID:jchris,項目名稱:indexing,代碼行數:10,代碼來源:util.go

示例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
}
開發者ID:vincecima,項目名稱:just-install,代碼行數:10,代碼來源:file.go

示例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)
}
開發者ID:dolzenko,項目名稱:flood,代碼行數:10,代碼來源:util.go

示例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)
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:67,代碼來源:id.go

示例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)
}
開發者ID:RezaDKhan,項目名稱:terraform,代碼行數:16,代碼來源:seed.go

示例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)
	}
}
開發者ID:niksaak,項目名稱:worgen,代碼行數:16,代碼來源:worgen.go

示例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
}
開發者ID:mdevilliers,項目名稱:golang-bestiary,代碼行數:15,代碼來源:watcher.go

示例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)))
}
開發者ID:caglar10ur,項目名稱:godup,代碼行數:16,代碼來源:dup.go

示例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
}
開發者ID:rrudduck,項目名稱:golang-stuff,代碼行數:16,代碼來源:permissions.go

示例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
}
開發者ID:asteris-llc,項目名稱:vaultfs,代碼行數:18,代碼來源:root.go

示例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
}
開發者ID:strickyak,項目名稱:rye,代碼行數:17,代碼來源:runtime2.pre.go

示例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)
		}
	}
}
開發者ID:taysom,項目名稱:va,代碼行數:20,代碼來源:bloom_test.go


注:本文中的hash/crc64.Checksum函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。