O (2) prime number queries in Lua scripts

Source: Internet
Author: User

--======================================================================================================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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.