コード例 #1
0
// getLocked performs a get operation assuming that the caller
// is already holding the mutex.
func (in *InMem) getLocked(key Key, data llrb.Tree) ([]byte, error) {
	if len(key) == 0 {
		return nil, emptyKeyError()
	}

	val := data.Get(proto.RawKeyValue{Key: key})
	if val == nil {
		return nil, nil
	}
	return val.(proto.RawKeyValue).Value, nil
}
コード例 #2
0
// scanLocked is intended to be called within at least a read lock.
func (in *InMem) scanLocked(start, end Key, max int64, data llrb.Tree) ([]proto.RawKeyValue, error) {
	var scanned []proto.RawKeyValue
	if bytes.Compare(start, end) >= 0 {
		return scanned, nil
	}
	data.DoRange(func(kv llrb.Comparable) (done bool) {
		if max != 0 && int64(len(scanned)) >= max {
			done = true
			return
		}
		scanned = append(scanned, kv.(proto.RawKeyValue))
		return
	}, proto.RawKeyValue{Key: start}, proto.RawKeyValue{Key: end})

	return scanned, nil
}
コード例 #3
0
func cloneTree(a llrb.Tree) llrb.Tree {
	var newTree = llrb.Tree{Count: a.Count}
	newTree.Root = cloneNode(a.Root)
	return newTree
}