示例#1
0
func BenchmarkXxhash64CgoMultiWrites(b *testing.B) {
	h := C.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
	}
	_ = h.Sum64()
}
示例#2
0
func TestHash64Cgo(t *testing.T) {
	h := C.New64()
	h.Write(in)
	r := h.Sum64()
	if r != expected64 {
		t.Errorf("expected 0x%x, got 0x%x.", expected64, r)
	}
}
示例#3
0
文件: roshi.go 项目: ello/streams
//MarshalJSON takes a roshiquery and creates a list of base64 encoded bytes, hashing the StreamID with xxhash
func (q RoshiQuery) MarshalJSON() ([]byte, error) {
	ids := make([][]byte, len(q.Streams))
	for i := 0; i < len(q.Streams); i++ {
		h := xxhash.New64()
		io.Copy(h, strings.NewReader(q.Streams[i]))
		ids[i] = h.Sum(nil)
	}
	return json.Marshal(ids)
}
示例#4
0
func BenchmarkXX64CgoMultiWrites(b *testing.B) {
	var bv uint64
	h := CGO.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
		bv += h.Sum64()
		h.Reset()
	}
}
示例#5
0
func BenchmarkXxhash64CgoMultiWrites(b *testing.B) {
	var bv uint64
	h := C.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
		bv = h.Sum64()
		h.Reset()
	}
	benchVal64 = bv
}
示例#6
0
文件: roshi.go 项目: ello/streams
//MarshalJSON converts from a RoshiStreamItem to the expected json for Roshi, hashing the StreamID with xxhash
func (item RoshiStreamItem) MarshalJSON() ([]byte, error) {
	member, _ := MemberJSON(item)
	h := xxhash.New64()
	io.Copy(h, strings.NewReader(item.StreamID))
	return json.Marshal(&roshiItem{
		Key:    []byte(h.Sum(nil)),
		Score:  float64(item.Timestamp.UnixNano()),
		Member: []byte(member),
	})
}
示例#7
0
// ###### *Implementation*
func Create(file *os.File, filename string, config common.Config) (common.WriteAheadLog, error) {

	// try to open index file, return error on fail
	idxFile, err := os.OpenFile(filename+".idx", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
	if err != nil {
		return nil, err
	}

	// hash
	hash := xxhash.New64()
	io.Copy(hash, idxFile)
	idxFile.Seek(0, 0)

	index, err := VersionOneIndexFactory(idxFile, config.Version, config.Flags, config.TimeToLive)
	if err != nil {
		file.Close()
		return nil, err
	}

	// Stat the file to get the size. If unsuccessful, close the file and return the error.
	stat, err := file.Stat()
	if err != nil {
		file.Close()
		return nil, err
	}

	// create log writer
	writer, err := m3.NewMemMapAppender(file, 512*1024, stat.Size())
	if err != nil {
		return nil, err
	}

	logRecordEncoder, err := NewLogRecordEncoder(64*1024, writer)
	if err != nil {
		return nil, err
	}

	return &wal{
		filename:           filename,
		logWriter:          writer,
		index:              index,
		logRecordEncoder:   logRecordEncoder,
		indexRecordEncoder: NewIndexRecordEncoder(index),
		hashWriter:         NewIndexRecordEncoder(hash),
		hash:               hash,
		lastWriteTime:      0,
		flags:              config.Flags,
		logSize:            stat.Size(),
	}, nil
}