本文整理汇总了Golang中github.com/attic-labs/noms/go/hash.Hash类的典型用法代码示例。如果您正苦于以下问题:Golang Hash类的具体用法?Golang Hash怎么用?Golang Hash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeNamespacedKey
func (s *DynamoStore) makeNamespacedKey(h hash.Hash) []byte {
// This is semantically `return append(s.namespace, r.DigestSlice()...)`, but it seemed like we'd be doing this a LOT, and we know how much space we're going to need anyway. So, pre-allocate a slice and then copy into it.
hashSlice := h.DigestSlice()
key := make([]byte, s.namespaceLen+len(hashSlice))
copy(key, s.namespace)
copy(key[s.namespaceLen:], hashSlice)
return key
}
示例2: updateRootByKey
func (l *internalLevelDBStore) updateRootByKey(key []byte, current, last hash.Hash) bool {
l.mu.Lock()
defer l.mu.Unlock()
if last != l.rootByKey(key) {
return false
}
// Sync: true write option should fsync memtable data to disk
err := l.db.Put(key, []byte(current.String()), &opt.WriteOptions{Sync: true})
d.Chk.NoError(err)
return true
}
示例3: toDbKey
// toDbKey takes a refHeight and a hash and returns a binary key suitable for use with LevelDB. The default sort order used by LevelDB ensures that these keys (and their associated values) will be iterated in ref-height order.
func toDbKey(refHeight uint64, hash hash.Hash) []byte {
digest := hash.DigestSlice()
buf := bytes.NewBuffer(make([]byte, 0, uint64Size+binary.Size(digest)))
err := binary.Write(buf, binary.BigEndian, refHeight)
d.Chk.NoError(err)
err = binary.Write(buf, binary.BigEndian, digest)
d.Chk.NoError(err)
return buf.Bytes()
}
示例4: UpdateRoot
func (s *DynamoStore) UpdateRoot(current, last hash.Hash) bool {
s.requestWg.Wait()
putArgs := dynamodb.PutItemInput{
TableName: aws.String(s.table),
Item: map[string]*dynamodb.AttributeValue{
refAttr: {B: s.rootKey},
chunkAttr: {B: current.DigestSlice()},
compAttr: {S: aws.String(noneValue)},
},
}
if last.IsEmpty() {
putArgs.ConditionExpression = aws.String(valueNotExistsExpression)
} else {
putArgs.ConditionExpression = aws.String(valueEqualsExpression)
putArgs.ExpressionAttributeValues = map[string]*dynamodb.AttributeValue{
":prev": {B: last.DigestSlice()},
}
}
_, err := s.ddbsvc.PutItem(&putArgs)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "ConditionalCheckFailedException" {
return false
}
d.Chk.NoError(awsErr)
} else {
d.Chk.NoError(err)
}
}
return true
}
示例5: requestRoot
func (bhcs *httpBatchStore) requestRoot(method string, current, last hash.Hash) *http.Response {
u := *bhcs.host
u.Path = httprouter.CleanPath(bhcs.host.Path + constants.RootPath)
if method == "POST" {
d.Exp.False(current.IsEmpty())
params := u.Query()
params.Add("last", last.String())
params.Add("current", current.String())
u.RawQuery = params.Encode()
}
req := newRequest(method, bhcs.auth, u.String(), nil, nil)
res, err := bhcs.httpClient.Do(req)
d.Chk.NoError(err)
return res
}
示例6: EnsureHash
func EnsureHash(h *hash.Hash, v Value) hash.Hash {
if h.IsEmpty() {
*h = getHash(v)
}
return *h
}
示例7: toChunkKey
func (l *LevelDBStore) toChunkKey(r hash.Hash) []byte {
digest := r.DigestSlice()
out := make([]byte, len(l.chunkPrefix), len(l.chunkPrefix)+len(digest))
copy(out, l.chunkPrefix)
return append(out, digest...)
}
示例8: writeHash
func (rv *rollingValueHasher) writeHash(h hash.Hash) {
digest := h.Digest()
for _, b := range digest[:] {
rv.HashByte(b)
}
}
示例9: writeHash
func (w *nomsTestWriter) writeHash(h hash.Hash) {
w.writeString(h.String())
}
示例10: assertInputNotInStore
func assertInputNotInStore(input string, h hash.Hash, s ChunkStore, assert *assert.Assertions) {
data := s.Get(h)
assert.Nil(data, "Shouldn't have gotten data for %s", h.String())
}
示例11: assertInputInStore
func assertInputInStore(input string, h hash.Hash, s ChunkStore, assert *assert.Assertions) {
chunk := s.Get(h)
assert.False(chunk.IsEmpty(), "Shouldn't get empty chunk for %s", h.String())
assert.Equal(input, string(chunk.Data()))
}
示例12: writeHash
func (b *binaryNomsWriter) writeHash(h hash.Hash) {
b.ensureCapacity(sha1.Size)
digest := h.Digest()
copy(b.buff[b.offset:], digest[:])
b.offset += sha1.Size
}
示例13: CreateHashSpecString
func CreateHashSpecString(protocol, path string, h hash.Hash) string {
return fmt.Sprintf("%s:%s::#%s", protocol, path, h.String())
}
示例14: serializeHash
func serializeHash(w io.Writer, h hash.Hash) {
digest := h.Digest()
n, err := io.Copy(w, bytes.NewReader(digest[:]))
d.Chk.NoError(err)
d.Chk.True(int64(hash.ByteLen) == n)
}
示例15: writeHash
func (b *binaryNomsWriter) writeHash(h hash.Hash) {
b.ensureCapacity(hash.ByteLen)
digest := h.Digest()
copy(b.buff[b.offset:], digest[:])
b.offset += hash.ByteLen
}