For example please can you confirm that the following lua code that adds a list of strings (and removes dups) will not produce a sorted list.
function populate(rec, bin, val)
local l = rec[bin]
if l == nil then
l = list()
end
list.concat(l, val)
local hash = {}
local res = list()
for elem in list.iterator(l) do
if (not hash[elem]) then
list.append(res, elem)
hash[elem] = true
end
end
rec[bin] = res
return create_or_update(rec)
end
There is map internally implement as hashmap available in lua which can used to store set of items. example set.lua file which implements Redis like API would look something like
function sadd(rec, bin, member)
set = rec[bin]
if (set == nil) then
set = map.new(1)
end
set[member] = 1
rec[bin] = set
if (aerospike:exists(rec)) then
aerospike:update(rec)
else
aerospike:create(rec)
end
end
function scard(rec, bin)
set = rec[bin]
if (set == nil) then
return 0
end
if (type(set) ~= type(map())) then
return -1
end
return #set
end
function sismember(rec, bin, member)
set = rec[bin]
if (set == nil) then
return 0
end
if (type(set) ~= type(map())) then
return 0
end
if (not set[member]) then
return 0
else
return 1
end
end
function sscan(rec, bin, member)
set = rec[bin]
if (set == nil) then
return nil
end
if (type(set) ~= type(map())) then
return nil
end
result = list.new(#set)
for k,v in map.iterator(set) do
list.append(result, k)
end
return result
end