Page 1 of 1

### 用对象获取列表反集，速度飞快

Posted: 03 Mar 2015, 00:46

Code: Select all

``````SetBatchLines -1

; 生成 10 万个数字
Loop, 100000
fullList .= "," A_Index
fullList := Trim(fullList, ",")

; 生成 6 万个数字
Loop, 60000
subList .= "," A_Index
subList  := Trim(subList, ",")

; 获取 4 万个反集数字

; 方法一: InStr()
TickCount_Start := A_TickCount ; 计时开始

resultList := ""
Loop, Parse, fullList, CSV
If !InStr(subList, A_LoopField)
resultList .= "," A_LoopField

MsgBox, % "耗时: " (A_TickCount-TickCount_Start)/1000 " 秒" ; 我这里显示“耗时: 38.516000 秒”

; 方法二: Object
TickCount_Start := A_TickCount ; 计时开始

; 把 6 万个数字列表转为对象
oSubList := {}
Loop, Parse, subList, CSV
oSubList[A_LoopField] := 1

; 开始...
resultList := ""
Loop, Parse, fullList, CSV
If !oSubList[A_LoopField]
resultList .= "," A_LoopField

MsgBox, % "耗时: " (A_TickCount-TickCount_Start)/1000 " 秒" ; 我这里显示“耗时: 0.125000 秒”``````

### Re: 用对象获取列表反集，速度飞快

Posted: 15 Apr 2015, 02:33

• 如果期望的返回结果也是对象(数组)，可以oResultList:=objClone(oFullList)，遍历oSubList并删除oResultList中相应项。
• 感觉尽量用对象。且由于要遍历（而非索引SubList，可使用StrSplit进行列表至对象的转换。

Code: Select all

``````oSubList:=StrSplit(SubList,",")
oResultList:=objClone(oFullList)
for _,v in oSubList
objRemove(oResultList,v)``````

### Re: 用对象获取列表反集，速度飞快

Posted: 26 Jan 2019, 21:01

### Re: 用对象获取列表反集，速度飞快

Posted: 18 Oct 2019, 13:45