示例#1
0
func NewChunkQ(size int64, chunk int64) *ChunkQ {
	if !powerOfTwo(size) {
		panic(fmt.Sprintf("Size must be a power of two, size = %d", size))
	}
	if size%chunk != 0 {
		panic(fmt.Sprintf("Size must be neatly divisible by chunk, (size) %d rem (chunk) %d = %d", size, chunk, size%chunk))
	}
	ringBuffer := padded.ByteSlice(int(size))
	readBuffer := padded.ByteSlice(int(chunk))
	writeBuffer := padded.ByteSlice(int(chunk))
	q := &ChunkQ{ringBuffer: ringBuffer, readBuffer: readBuffer, writeBuffer: writeBuffer, size: size, chunk: chunk, mask: size - 1}
	return q
}
示例#2
0
func NewByteChunkQ(size, chunk int64) *ByteChunkQ {
	if size%chunk != 0 {
		panic(fmt.Sprintf("Size must be neatly divisible by chunk, (size) %d rem (chunk) %d = %d", size, chunk, size%chunk))
	}
	ringBuffer := padded.ByteSlice(int(size))
	q := &ByteChunkQ{ringBuffer: ringBuffer, commonQ: newCommonQ(size), chunk: chunk}
	return q
}
示例#3
0
文件: byteq.go 项目: jmptrader/queues
func NewByteQ(size int64) *ByteQ {
	if !powerOfTwo(size) {
		panic(fmt.Sprintf("Size (%d) must be a power of two", size))
	}
	ringBuffer := padded.ByteSlice(int(size))
	q := &ByteQ{ringBuffer: ringBuffer, size: size, mask: size - 1}
	return q
}
示例#4
0
文件: byteq.go 项目: roger2000hk/flib
func NewByteQ(size int64) *ByteQ {
	ringBuffer := padded.ByteSlice(int(size))
	q := &ByteQ{ringBuffer: ringBuffer, commonQ: newCommonQ(size)}
	return q
}