保存哈希的最佳方法是什么!在 Rebol 中阻塞?

What is the best way to save a hash! block in Rebol?

我正在使用 Rebol2 并希望保留一个 HASH! 块。

目前我正在转换它 to-string 然后使用 save.

有没有更好的方法?例如:

r: make hash! ["one" "two"]

我想将其保存到文件中,然后将其加载回 r

您离目标很近了。只需使用 save/allload

>> r: make hash! ["one" "two"]
== make hash! ["one" "two"]
>> save/all  %htest r
>> r: load %htest
== make hash! ["one" "two"]

如果你想在 Red 中得到相同的结果,你只需要一个命令 more

>> r: do load %htest
== make hash! ["one" "two"]

您可以像处理任何其他值一样执行此操作 - save,然后是 load

顺便说一句,使用 hash! 进行持久存储的好处为零。 load 给你的是一个普通的 block! ([make hash! [...]])。与仅加载 block! 相比,从这个加载的数据填充哈希表需要更多时间,但此后查找速度更快。

换句话说,你可以:

>> save %database [one two]
>> make hash! load %database
== make hash! [one two]

如您链接的教程中所述。