如何将数组存储为Tokyo Cabinet中的值?

发布于 2024-09-04 09:06:13 字数 221 浏览 5 评论 0原文

有什么方法可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2024-09-11 09:06:13

Tokyo Cabinet 允许任意字节序列作为键和值,因此模式实际上取决于您。第一步是决定如何存储每个数字。这可以是浮点型、双精度型或定点型(例如 BigDecimal)。

然后,您决定如何序列化数组。这可能是连续的:

num => 1 2 444 0.987

TC 值只是连接在一起的所有数值。例如,使用 32 位浮点数:

num => 0x 3f 80 00 00 40 00 00 00 43 de 00 00 3f 7c ac 08

另一种可能性是链表:

key => num next_key

1 => 1.1 2
2 => 2 3
3 => 444 4
4 => 0.987 0

将当前值和数组中的下一个键连接起来

这提供了链表的传统优点,包括轻松地在中间插入。

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:

num => 1 2 444 0.987

The TC value is simply all the numeric values concatenated together. E.g. using 32-bit floats:

num => 0x 3f 80 00 00 40 00 00 00 43 de 00 00 3f 7c ac 08

Another possibility is a linked list:

key => num next_key

1 => 1.1 2
2 => 2 3
3 => 444 4
4 => 0.987 0

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文