【问题标题】:How I can get hash from random tuple or array in Tarantool?如何从 Tarantool 中的随机元组或数组中获取哈希?
【发布时间】:2020-11-22 17:10:31
【问题描述】:

我有一个函数(random_typle)参数作为随机元组,那么如何从元组的所有字段中获取哈希? 我可以使用 tuple:bsize() 之类的东西还是应该迭代所有字段并计算哈希?

【问题讨论】:

    标签: lua tarantool


    【解决方案1】:

    Tarantool 具有内置的 digest 模块和哈希函数集合。下面我举一个函数来计算一个元组的 crc32 哈希。

    local digest = require('digest')
    local function calc_hash(tuple)
        local crc32 = digest.crc32.new()
        for _, v in ipairs(tuple) do
            crc32:update(tostring(v))
        end
        return crc32:result()
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      • 2010-09-15
      • 2010-09-08
      • 2013-01-23
      • 2012-08-17
      • 1970-01-01
      • 2021-07-16
      相关资源
      最近更新 更多