LoneWolf_2106 Posted June 21, 2018 Posted June 21, 2018 Hi, I have an array with thousands empty elements, I have written a for loop to remove them, but it is very slow. For $i=UBound($aFile_Array) -1 To 0 Step -1 If $aFile_Array[$i] = "" Then _ArrayDelete($aFile_Array, $i) Next is there any way to improve the process? Thanks in advance for your support.
water Posted June 21, 2018 Posted June 21, 2018 When processing the Array, can't you just ignore empty elements? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
mikell Posted June 21, 2018 Posted June 21, 2018 The slowness is caused by the constant call to _ArrayDelete Here is a possible way - for 1D arrays #include <Array.au3> Local $array[50000] For $i = 0 To UBound($array)-1 step 2 $array[$i] = "This is a test" & $i Next _ArrayDisplay($array) Local $string For $i = 0 To UBound($array)-1 $string &= $array[$i] & @crlf Next $res = StringRegExp($string, '\V+', 3) _ArrayDisplay($res)
LarsJ Posted June 21, 2018 Posted June 21, 2018 $nFile_Array = UBound($aFile_Array) Dim $aTmp[$nFile_Array] $iFile_Array = 0 For $i = 0 To $nFile_Array - 1 If Not $aFile_Array[$i] Then ContinueLoop $aTmp[$iFile_Array] = $aFile_Array[$i] $iFile_Array += 1 Next ReDim $aTmp[$iFile_Array] $aFile_Array = $aTmp Bilgus and Hashim 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
AutoBert Posted June 21, 2018 Posted June 21, 2018 I think fastest solution is to sort the array in descending order, get the lowest value and then ReDim: #include <Array.au3> Dim $aArray[10000] For $i=0 To 100 $aArray[$i]=$i Next _ArrayShuffle($aArray) _arraydisplay($aArray,'Array with many empty elements') $tdStart=TimerInit() _ArraySort($aArray,1) $iMin= _ArrayMinIndex($aArray) ReDim $aArray[$iMin] $tdDiff=TimerDiff($tdStart) _ArrayDisplay($aArray,'TimerDiff = '&$tdDiff)
mikell Posted June 21, 2018 Posted June 21, 2018 2 hours ago, AutoBert said: I think fastest solution is ... Did you try a little comparison ?
LoneWolf_2106 Posted June 22, 2018 Author Posted June 22, 2018 I am trying to rewrite the structure of my software to reduce the number of those empty elements, I will let you know as soon as I have finished
LoneWolf_2106 Posted June 22, 2018 Author Posted June 22, 2018 (edited) I don't know if I have to open a new topic, anyway I ask you here. Is it possible to remove a XML node and its content from a file? I have tried this, but not all the values are removed, most likely because the indexes are not updated(found with _ArrayFindAll) during the the deletion: $test_start=_ArrayFindAll($Array_Test, "<test>",0,0,0,1) $test_End=_ArrayFindAll($Array_Test, "</test>",0,0,0,1) For $i=0 to UBound($test_start) -1 For $j=$test_start[$i] To $test_End[$i] _ArrayDelete($Array_Test, $j) Next Next Edit: The node is on multiple lines Edited June 22, 2018 by LoneWolf_2106
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now