Jump to content

Remove empty elements in array - slowness problem


Recommended Posts

When processing the Array, can't you just ignore empty elements?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

$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

 

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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 by LoneWolf_2106
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...