aerospike udf 使用之 list
所属分类 aerospike
浏览量 1383
https://www.aerospike.com/docs/udf/api/list.html
The list modules introduces a List type and functions to Lua.
It provides a consistent interface for working with a sequence of values, which is not provided by Lua Tables.
列表类型 , 为处理一组值提供一致的接口
Aerospike Lua list objects are usually returned in Aerospike functions,
and set as values in the Aerospike database.
local l = list()
create an empty List with a specific initial capacity
local l = list.create(100)
local l = list {1,2,3,4}
To create an empty List with an initial capacity of 50 and a step size of 25
local l = list.create(50, 25)
function list.size(l: List): Integer
function list.iterator(l: List): iterator
local l = list {1,2,3}
for value in list.iterator(l) do
info("%s", tostring(value))
end
access elements like a Lua Table:
> l[1]
1
> l[1] = 3
> l[1]
3
指定位置insert
function list.insert(l: List, i: Integer, v: Val): nil
i – The list index at which to insert the value.
v – The value to insert into the list.
local l = list {1,2,3,4}
List(1,2,3,4)
list.insert(l, 3, 55)
List(1,2,55,3,4)
尾部Insert
function list.append(l: List, v: Val): nil
头部Insert
function list.prepend(l: List, v: Val): nil
Select the first n elements of the List
function list.take(l: List, n: Integer): List
n – The number of values to select from the beginning of the list.
删除指定位置元素
Remove an element from the List at a specified position.
function list.remove(l: List, i: Integer): nil
i – The index of the list value to remove.
Select all elements except the first n elements of the List.
function list.drop(l: List, n: Integer): List
n – The number of values to skip from the beginning of the list.
A new list containing the values after the first n values of the list l.
local l = list {1,2,3}
List(1,2,3)
list.drop(l, 2)
List(3)
截掉指定位置之后的元素
Remove all elements at and beyond a specified position in the List.
function list.trim(l: List, i: Integer): nil
i – The index from which to trim the list.
local l = list {1,2,3,4,5}
List(1,2,3,4,5)
list.trim(l, 4)
List(1,2,3)
Create a new List as a shallow copy of another List. All elements are references to the elements of the original List, not copies.
function list.clone(l: List): List
list.concat()
Append all elements of one list, in order, to another list.
function list.concat(l1: List, l2: List): nil
l1 – The List to append to.
l2 – The List to be appended.
Merge the elements of given two lists and return the combined list.
function list.merge(l1: List, l2: List): List
l1 – One of the List to be merged
l2 – Another List to be merged
注意 concat 和 merge 的区别
concat 直接追到第一个列表
merge 合并两个列表,返回新的列表
上一篇
下一篇
go语言特性及优点
lua local function 与 function 区别
aerospike udf 使用之 record
aerospike udf 使用之 map
权益类与固收类基金
lua中pairs和ipairs的区别