如何将数组存储为Tokyo Cabinet中的值?
有什么方法可以在 Tokyo Cabinet 数据库中存储数字数组吗?例如,我有可预测的值数组,例如
1 => [1, 2, 444, 0.987],
2 => [2, 23, 123, -0.234],
3 => [3, 1, 34, 1.456]
我想将上面的值存储在 TC 固定长度数据库中。有没有办法将以上内容存储为数组而不是字符串?
Is there any way I can store an array of numbers in a Tokyo Cabinet db? For example, I have predictable arrays of values such as
1 => [1, 2, 444, 0.987],
2 => [2, 23, 123, -0.234],
3 => [3, 1, 34, 1.456]
I would like to store the above in a TC fixed length db. Is there a way to store the above as arrays instead of as strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tokyo Cabinet 允许任意字节序列作为键和值,因此模式实际上取决于您。第一步是决定如何存储每个数字。这可以是浮点型、双精度型或定点型(例如 BigDecimal)。
然后,您决定如何序列化数组。这可能是连续的:
TC 值只是连接在一起的所有数值。例如,使用 32 位浮点数:
另一种可能性是链表:
将当前值和数组中的下一个键连接起来
这提供了链表的传统优点,包括轻松地在中间插入。
Tokyo Cabinet allows arbitrary byte sequences as both key and value, so the schema is really up to you. The first step is to decide how to store each number. This could be float, double, or fixed point (e.g. BigDecimal).
Then, you decide how to serialize the array. This could be contiguous:
The TC value is simply all the numeric values concatenated together. E.g. using 32-bit floats:
Another possibility is a linked list:
You concatenate the current value and the next key in the array
This provides the traditional benefits of a linked list, including inserting in the middle easily.