当前位置: 首页>>代码示例>>Golang>>正文


Golang hash.Hash64类代码示例

本文整理汇总了Golang中hash.Hash64的典型用法代码示例。如果您正苦于以下问题:Golang Hash64类的具体用法?Golang Hash64怎么用?Golang Hash64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Hash64类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: new_docsummary_internal

func new_docsummary_internal(n *html.Node, f hash.Hash64) *DocumentSummary {
	rtn := &DocumentSummary{}
	if n == nil {
		return rtn
	}
	foreach_child(n, func(child *html.Node) {
		switch {
		case child.Type == html.CommentNode:
		case child.Type == html.DoctypeNode:
		case child.Type == html.TextNode:
			c, _ := f.Write([]byte(child.Data))
			rtn.WordCount += c
			if node_is_in_a(child) {
				rtn.LinkWordCount += c
			}
			rtn.Text += child.Data
		case child.Data == "img":
			rtn.Images = append(rtn.Images, make_mediasummary(child))
		case node_is_media(child):
			rtn.Medias = append(rtn.Medias, make_mediasummary(child))
		case child.Data == "a":
			rtn.LinkCount++
			ac := new_docsummary_internal(child, f)
			rtn.Images = append(rtn.Images, ac.Images...)
			rtn.Medias = append(rtn.Medias, ac.Medias...)
		default:
			sc := new_docsummary_internal(child, f)
			rtn.add(sc)
		}
	})
	return rtn
}
开发者ID:heartszhang,项目名称:famous,代码行数:32,代码来源:summary_score.go

示例2: TestRef

func TestRef(t *testing.T) {
	for _, elem := range data {

		var h32 hash.Hash32 = New32()
		h32.Write([]byte(elem.s))
		if v := h32.Sum32(); v != elem.h32 {
			t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
		}

		if v := Sum32([]byte(elem.s)); v != elem.h32 {
			t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
		}

		var h64 hash.Hash64 = New64()
		h64.Write([]byte(elem.s))
		if v := h64.Sum64(); v != elem.h64_1 {
			t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h64_1)
		}

		var h128 Hash128 = New128()
		h128.Write([]byte(elem.s))
		if v1, v2 := h128.Sum128(); v1 != elem.h64_1 || v2 != elem.h64_2 {
			t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
		}

		if v1, v2 := Sum128([]byte(elem.s)); v1 != elem.h64_1 || v2 != elem.h64_2 {
			t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
		}
	}
}
开发者ID:venliong,项目名称:murmur3,代码行数:30,代码来源:murmur_test.go

示例3: makeHashes

func makeHashes(d []byte, h hash.Hash64) ([]uint32, error) {
	_, err := h.Write(d)
	if err != nil {
		return nil, err
	}
	hashed := h.Sum64()
	lower := uint32(hashed)
	upper := uint32(hashed >> 32)
	return []uint32{lower, upper}, nil
}
开发者ID:uluyol,项目名称:misc,代码行数:10,代码来源:bloom.go

示例4: ID

// ID with which you can identify a daemon connection to the same SMTP server
// independent of the scope ID.
func (dm *Daemon) ID() uint64 {
	var h hash.Hash64
	h = fnv.New64()
	data := []byte(dm.getHost() + strconv.Itoa(dm.getPort()) + dm.getUsername())
	if _, err := h.Write(data); err != nil {
		log.Error("mail.daemon.ID", "err", err, "hashWrite", string(data))
		return 0
	}
	return h.Sum64()
}
开发者ID:optimuse,项目名称:csfw,代码行数:12,代码来源:daemon.go

示例5: TestRef

func TestRef(t *testing.T) {
	for _, elem := range data {

		var h32 hash.Hash32 = New32()
		h32.Write([]byte(elem.s))
		if v := h32.Sum32(); v != elem.h32 {
			t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
		}

		var h32_byte hash.Hash32 = New32()
		h32_byte.Write([]byte(elem.s))
		target := fmt.Sprintf("%08x", elem.h32)
		if p := fmt.Sprintf("%x", h32_byte.Sum(nil)); p != target {
			t.Errorf("'%s': %s (want %s)", elem.s, p, target)
		}

		if v := Sum32([]byte(elem.s)); v != elem.h32 {
			t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
		}

		var h64 hash.Hash64 = New64()
		h64.Write([]byte(elem.s))
		if v := h64.Sum64(); v != elem.h64_1 {
			t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h64_1)
		}

		var h64_byte hash.Hash64 = New64()
		h64_byte.Write([]byte(elem.s))
		target = fmt.Sprintf("%016x", elem.h64_1)
		if p := fmt.Sprintf("%x", h64_byte.Sum(nil)); p != target {
			t.Errorf("Sum64: '%s': %s (want %s)", elem.s, p, target)
		}

		if v := Sum64([]byte(elem.s)); v != elem.h64_1 {
			t.Errorf("Sum64: '%s': 0x%x (want 0x%x)", elem.s, v, elem.h64_1)
		}

		var h128 Hash128 = New128()
		h128.Write([]byte(elem.s))
		if v1, v2 := h128.Sum128(); v1 != elem.h64_1 || v2 != elem.h64_2 {
			t.Errorf("New128: '%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
		}

		var h128_byte Hash128 = New128()
		h128_byte.Write([]byte(elem.s))
		target = fmt.Sprintf("%016x%016x", elem.h64_1, elem.h64_2)
		if p := fmt.Sprintf("%x", h128_byte.Sum(nil)); p != target {
			t.Errorf("New128: '%s': %s (want %s)", elem.s, p, target)
		}

		if v1, v2 := Sum128([]byte(elem.s)); v1 != elem.h64_1 || v2 != elem.h64_2 {
			t.Errorf("Sum128: '%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
		}
	}
}
开发者ID:twmb,项目名称:murmur3,代码行数:55,代码来源:murmur_test.go

示例6: benchmarkHash

func benchmarkHash(b *testing.B, h hash.Hash64) {
	uids := getUids(b.N)
	var s uint64
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		h.Reset()
		io.WriteString(h, uids[i])
		s = h.Sum64()
	}
	result = s
}
开发者ID:dgraph-io,项目名称:experiments,代码行数:11,代码来源:hash_test.go

示例7: hashUpdateOrdered

func hashUpdateOrdered(h hash.Hash64, a, b uint64) uint64 {
	// For ordered updates, use a real hash function
	h.Reset()

	// We just panic if the binary writes fail because we are writing
	// an int64 which should never be fail-able.
	e1 := binary.Write(h, binary.LittleEndian, a)
	e2 := binary.Write(h, binary.LittleEndian, b)
	if e1 != nil {
		panic(e1)
	}
	if e2 != nil {
		panic(e2)
	}

	return h.Sum64()
}
开发者ID:PagerDuty,项目名称:nomad,代码行数:17,代码来源:hashstructure.go

示例8: Get

// ID with which you can identify a daemon connection to the same SMTP server
// independent of the scope ID.
func (u *uniqueID) Get() (id uint64, hasChanged bool) {
	var h hash.Hash64
	h = fnv.New64()
	data := []byte(u.getHost() + strconv.Itoa(u.getPort()) + u.getUsername())
	if _, err := h.Write(data); err != nil {
		log.Error("mail.daemon.ID", "err", err, "hashWrite", string(data))
		return
	}
	if u.lastID != h.Sum64() {
		u.lastID = h.Sum64()
		return u.lastID, true // ID has changed, means some one updated the configuration.
	}
	return h.Sum64(), false // has not changed
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:16,代码来源:daemon_unique_id.go

示例9: testCollissions

func testCollissions(t *testing.T, h hash.Hash64) {
	uids := getUids(uidSize)
	results := make(map[uint64]bool)
	cols := 0

	for i := 0; i < uidSize; i++ {
		h.Reset()
		io.WriteString(h, uids[i])
		s := h.Sum64()
		if _, col := results[s]; col {
			cols += 1
		} else {
			results[s] = true
		}
	}
	if cols > 0 {
		t.Errorf("Found %v collissions for uidSize %v\n", cols, uidSize)
	}
}
开发者ID:dgraph-io,项目名称:experiments,代码行数:19,代码来源:hash_test.go

示例10: writeChecksumBlock

func writeChecksumBlock(hash hash.Hash64, output io.Writer) error {
	// file path length... zero
	err := binary.Write(output, binary.BigEndian, uint16(0))
	if err == nil {
		blockType := []byte{byte(blockTypeChecksum)}
		_, err = output.Write(blockType)
	}
	if err == nil {
		err = binary.Write(output, binary.BigEndian, hash.Sum64())
	}
	return err
}
开发者ID:KnowNo,项目名称:fast-archiver,代码行数:12,代码来源:archiver.go

示例11: Hash64

// Hash64 is a convenience method for hashing a string against a hash.Hash64
func Hash64(s string, h hash.Hash64) uint64 {
	h.Reset()
	h.Write([]byte(s))
	return h.Sum64()
}
开发者ID:iNamik,项目名称:go_pkg,代码行数:6,代码来源:hasher64.go

示例12: Get

func (ds *Directory) Get(key string, opts store.GetOptions) ([]byte, store.Stat, error) {
	ds.mu.RLock()
	defer ds.mu.RUnlock()

	select {
	case <-opts.Cancel:
		return nil, store.Stat{}, store.ErrCancelled
	default:
	}

	fh, path, err := ds.findAndOpen(key)
	if err != nil {
		return nil, store.Stat{}, err
	}
	if fh == nil {
		return nil, store.Stat{}, store.ErrNotFound
	}
	defer fh.Close()

	var expectedFNV [8]byte
	_, err = io.ReadFull(fh, expectedFNV[:])
	if err != nil {
		return nil, store.Stat{}, err
	}

	var rdr io.Reader
	var fnver hash.Hash64
	if opts.NoVerify {
		rdr = fh
	} else {
		fnver = fnv.New64a()
		rdr = io.TeeReader(fh, fnver)
	}

	var expectedSHA256 [32]byte
	_, err = io.ReadFull(rdr, expectedSHA256[:])
	if err != nil {
		return nil, store.Stat{}, err
	}

	fi, err := fh.Stat()
	if err != nil {
		return nil, store.Stat{}, err
	}

	size := fi.Size() - 40

	if int64(int(size)) != size {
		return nil, store.Stat{}, errors.New("file is too big")
	}

	writeTime := fi.ModTime().Unix()

	data := make([]byte, int(size))
	at := 0
	for at < len(data) {
		readInto := data[at:]
		if len(readInto) > 1024*1024 {
			readInto = readInto[:1024*1024]
		}

		n, err := rdr.Read(readInto)
		at += n
		if err != nil {
			if err == io.EOF {
				break
			}
			return nil, store.Stat{}, err
		}

		select {
		case <-opts.Cancel:
			return nil, store.Stat{}, store.ErrCancelled
		default:
		}
	}

	if at != len(data) {
		return nil, store.Stat{}, errors.New("file was shortened during read")
	}

	if !opts.NoVerify {
		actualFNV := fnver.Sum(nil)

		if !bytes.Equal(actualFNV, expectedFNV[:]) {
			fh.Close()

			// TODO: this relocking is fucked and racy
			ds.mu.RUnlock()
			ds.mu.Lock()
			ds.quarantine(key, path)
			ds.mu.Unlock()
			ds.mu.RLock()
			return nil, store.Stat{}, ErrCorruptObject
		}
	}

	return data, store.Stat{
		SHA256:    expectedSHA256,
		Size:      size,
//.........这里部分代码省略.........
开发者ID:encryptio,项目名称:slime,代码行数:101,代码来源:directory.go

示例13: hashKernel

// hashKernel returns the upper and lower base hash values from which the k
// hashes are derived.
func hashKernel(data []byte, hash hash.Hash64) (uint32, uint32) {
	hash.Write(data)
	sum := hash.Sum(nil)
	hash.Reset()
	return binary.BigEndian.Uint32(sum[4:8]), binary.BigEndian.Uint32(sum[0:4])
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:8,代码来源:boom.go


注:本文中的hash.Hash64类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。