首页  

aerospike udf 使用之 map     所属分类 aerospike 浏览量 1441
https://www.aerospike.com/docs/udf/api/map.html


The map module introduces the Map type and functions to Lua. 
It provides a consistent interface for maps, which is not provided by Lua tables. 
In stream and record UDFs the Map, which is a type supported by the database, should be used in place of Lua tables.

local m = map()

local m = map.create(1000)

local m = map { a = 1, b = 2, c = 3 }

function map.create(c: integer): Map
c – initial Map capacity.

function map.size(m: Map): Integer

function map.pairs(m: Map): iterator


for key, value in map.pairs(m) do
   info("%s = %d", key, value)
end

function map.keys(m: Map): iterator


for key in map.keys(m) do
   info("%s", key)
end

function map.values(m: Map): iterator

for value in map.values(m) do
   info("%d", value)
end

function map.remove(m: Map, key: string): nil


function map.clone(m: Map): Map

Merge two Maps, creating a new Map. When keys collide, call the merge function op to merge the values.

function map.merge(m1: Map, m2: Map, op: function): Map

op – The function to use when merging pairs with the same key.

function(a: Val, b: Val): Val


local m1 = map { a = 1, b = 2 }
Map( "a" => 1, "b" => 2 )

local m2 = map { a = 3 }
Map( "a" => 3 )

map.merge(m1, m2, function (v1, v2)
   return v1 + v2
 end)
Map( "a" => 4, "b" => 2 )

上一篇     下一篇
lua local function 与 function 区别

aerospike udf 使用之 record

aerospike udf 使用之 list

权益类与固收类基金

lua中pairs和ipairs的区别

lua动态方法调用实例