--======================================================================================================LocalSet={[1]=2,[2]=3,[3]=5,[4]=7,[5]= One,[6]= -,[7]= -,[8]= +,[9]= at,[Ten]= in,[ One]= to,[ A]=Panax Notoginseng,[ -]= A,[ -]= +,[ the]= -,[ -]= -,[ -]= -,[ -]= A,[ +]= the,[ -]= in,[ +]= the,[ A]= -,[ at]= the,[ -]= the,[ -]= the,[ -]=101}; Local reverse={[2]=1,[3]=2,[5]=3,[7]=4,[ One]=5,[ -]=6,[ -]=7,[ +]=8,[ at]=9,[ in]=Ten,[ to]= One,[Panax Notoginseng]= A,[ A]= -,[ +]= -,[ -]= the,[ -]= -,[ -]= -,[ A]= -,[ the]= +,[ in]= -,[ the]= +,[ -]= A,[ the]= at,[ the]= -,[ the]= -,[101]= -}; Ngx.say ("The current value is: 7, the next prime number is:"..Set[reverse[7]+1]); Ngx.say ("The current value is: 23, the next prime number is:"..Set[reverse[ at]+1]); Ngx.say ("The current value is: 41, the next prime number is:"..Set[reverse[ A]+1]); Ngx.say ("====================================="); forKey, ValueinchPairsSet) DoNgx.say ("Key:".. Key:", Value:".. Value); End Ngx.say ("====================================="); forKey, ValueinchPairs (reverse) DoNgx.say ("Key:".. Key:", Value:".. Value); End--====================================================================================================== --[function Newset () Local reverse= {} --with data as key, the position of the data in set is value localSet= {}; --an array in which value is the data to be managedreturnSetmetatable (Set, {__index ={Insert= function (Set, value)ifNot Reverse[value] then Table.insert (Set, value) Reverse[value]= TABLE.GETN (Set) end end, remove= function (Set, value) Local index=Reverse[value]ifindex then Reverse[value]=Nil Local Top= Table.remove (Set) --Delete the last element in an arrayifTop ~=value Then--Replace the value if it is not to be deleted Reverse[top]=IndexSet[Index] =Top End End end, find= function (Set, value) Local index=Reverse[value]returnindex; End,}}) endlocal n=Newset (); N:insert (5);]]
O (2) prime number queries in Lua scripts