如何将字节数组递增
在RockSDB中,我们能够根据键执行范围扫描。我们首先通过初始化字节[]来寻求开始位置。例如,如果您的密钥由两种长数据类型组成,我们可以使用tobytes(long.minvalue,long.minvalue)初始化start byte [16]
然后通过做类似的tobytes来设置endkey (long.minvalue,long.maxvalue)
。请注意,我们只想从long.minvalue
long.maxvalue 使用此密钥作为例如表明我们可以部分扫描字节[]的最后64位。
示例代码可以在下面找到。 iter.next()
如何工作?从启动到达到末端密钥,我们本质上是从开始的字节[16]。换句话说,我们如何将字节[]递增? (或一次像Integer添加一样,一次增加一位?)检查源代码时,它会跳到本机
函数。
val iter = newRocksIterator()
new Iterator[Entry] {
override def hasNext: Boolean = {
if (iter.isValid) {
if (compareKeys(iter.key(), endKey) > 0) false else true
} else {
false
}
}
override def next(): Entry = {
val value = Entry(iter.key, iter.value())
iter.next()
value
}
}
In RocksDB, we are able to perform range scan based on a key. We first seek to the start position by initializing byte[]. For example if your key is composed of two Long data types, we can initialize start byte[16] with toBytes(Long.MinValue, Long.MinValue)
Then set endKey by doing something similar toBytes(Long.MinValue, Long.MaxValue)
. Note that we only want to scan last 64 bit from Long.MinValue
to Long.MaxValue
using this key as example to show we can scan byte[] partially.
Sample code can be found below. How does iter.next()
work below? We are essentially incrementing byte[16] from start until we hit the end key. In other words, how do we increment byte[] by one? (or increment one bit at a time just like integer addition??) When checking the source code, it jumps to native
function.
val iter = newRocksIterator()
new Iterator[Entry] {
override def hasNext: Boolean = {
if (iter.isValid) {
if (compareKeys(iter.key(), endKey) > 0) false else true
} else {
false
}
}
override def next(): Entry = {
val value = Entry(iter.key, iter.value())
iter.next()
value
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用事务数据库并进行读取 - 修改 - 写周期
,也可以使用INT64ADDITION合并操作员在密钥处进行增量
You can either use a transaction DB and do a read-modify-write cycle
or use the int64addition merge operator to do the increment at the key