如何在 Lua 中序列化/反序列化二叉堆?

local binaryheap = require 'binaryheap'
local cjson = require "cjson.safe"

local heap = binaryheap.minUnique()

heap:insert(22, 'foo')
heap:insert(13, 'bar')
heap:insert(14, 'fubar')

local str = cjson.encode(heap)
heap = cjson.decode(str)
local mylow = heap:peek()

希望这可以解释我正在尝试做什么。

能否在不转存所有数据和重新创建二叉堆的情况下完成?

我想将我的二叉堆保存到存储中,然后稍后将其取回。这种可能吗?

二叉堆模块来自于这里:https://github.com/Tieske/binaryheap.lua

点赞