From 592b11366eccf111dbf553753889ba38cfa57e87 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sun, 21 Nov 2021 03:06:00 +0800 Subject: [PATCH] =?UTF-8?q?table=E6=89=A9=E5=B1=95=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=A4=E4=B8=AA=E5=8E=BB=E9=87=8D=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8C=E5=8F=8D=E8=BD=AC=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/tableExtend.lua | 44 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Zframework/tableExtend.lua b/Zframework/tableExtend.lua index e64cdc53..7b5c46c5 100644 --- a/Zframework/tableExtend.lua +++ b/Zframework/tableExtend.lua @@ -1,4 +1,5 @@ local find=string.find +local rem=table.remove local next,type=next,type local TABLE={} @@ -83,7 +84,7 @@ function TABLE.complete(new,old) end end ---Remove positive integer index of table +--Remove [1~#] of table function TABLE.cut(G) for i=1,#G do G[i]=nil @@ -97,16 +98,53 @@ function TABLE.clear(G) end end +--Remove duplicated value of [1~#] +function TABLE.trimDuplicate(org) + local cache={} + for i=1,#org,-1 do + if cache[org[i]]then + rem(org,i) + else + cache[org[i]]=true + end + end +end + +--Discard duplicated value +function TABLE.remDuplicate(org) + local cache={} + for k,v in next,org do + if cache[v]then + org[k]=nil + else + cache[v]=true + end + end +end + + +--Reverse [1~#] +function TABLE.reverse(org) + local l=#org + for i=1,math.floor(l/2)do + org[i],org[l+1-i]=org[l+1-i],org[i] + end +end + +-------------------------- + --Find value in [1~#] function TABLE.find(t,val) for i=1,#t do if t[i]==val then return i end end end ---Retuen next value of [1~#] +--Return next value of [1~#] (by value) function TABLE.next(t,val) for i=1,#t do if t[i]==val then return t[i%#t+1]end end end +-------------------------- + --Find value in whole table function TABLE.search(t,val) for k,v in next,t do if v==val then return k end end @@ -121,6 +159,8 @@ function TABLE.reIndex(org) end end +-------------------------- + --Dump a simple lua table do--function TABLE.dump(L,t) local tabs={