Jump to content
Ascer

[UDF] ArrayList - actions on huge arrays

Recommended Posts

1. Description.

  • Udf working with MSDN System.Collections.ArrayList.
  • Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd. 
  • Not prefered for small arrays < 600 items.

2. Requirements

  • .NET Framework 1.1 - 4.5 (on this version Microsoft destroy old rules)
  • System Windows

3. Possibilities.

;===============================================================================================================
; UDF Name:         List.au3
;
; Date:             2018-02-17, 10:52
; Description:      Simple udf to create System Collections as ArrayList and make multiple actions on them.
;
; Function(s):      _ListCreate         -> Creates a new list
;                   _ListCapacity       -> Gets a list size in bytes
;                   _ListCount          -> Gets items count in list
;                   _ListIsFixedSize    -> Get bool if list if fixed size
;                   _ListIsReadOnly     -> Get bool if list is read only
;                   _ListIsSynchronized -> Get bool if list is synchronized
;                   _ListGetItem        -> Get item on index
;                   _ListSetItem        -> Set item on index
;
;                   _ListAdd            -> Add item at end of list
;                   _ListClear          -> Remove all list items
;                   _ListClone          -> Duplicate list in new var
;                   _ListContains       -> Get bool if item is in list
;                   _ListGetHashCode    -> Get hash code for list
;                   _ListGetRange       -> Get list with items between indexs
;                   _ListIndexOf        -> Get index of item
;                   _ListInsert         -> Insert a new item on index
;                   _ListInsertRange    -> Insert list into list on index
;                   _ListLastIndexOf    -> Get index last of item
;                   _ListRemove         -> Remove first found item
;                   _ListRemoveAt       -> Remove item in index
;                   _ListRemoveRange    -> Remove items between indexs
;                   _ListReverse        -> Reverse all items in list
;                   _ListSetRange       -> Set new value for items in range
;                   _ListSort           -> Sort items in list (speed of reading)
;                   _ListToString       -> Get list object name
;                   _ListTrimToSize     -> Remove unused space in list
;
; Author(s):        Ascer
;===============================================================================================================

4. Downloads

5. Examples

 

Edited by Ascer

Share this post


Link to post
Share on other sites
  • SpeedTest  ArrayAdd  vs  ListAdd
#include <Array.au3>
#include <List.au3>

;==> _ListAdd()

Local $iItems = 5000

ConsoleWrite("[_ListAdd]" & @CRLF)
ConsoleWrite("Start adding " & $iItems & " items using _ListAdd func..." & @CRLF)

Local $aListAdd = _ListCreate()
Local $iListAddTime = TimerInit()

For $i = 1 To $iItems
    _ListAdd($aListAdd, $i)
Next

ConsoleWrite("Adding has end. Time spent on this action is " & Int(TimerDiff($iListAddTime)) & " ms." & @CRLF)
ConsoleWrite("UBound of $aListAdd is " & _ListCount($aListAdd) & "." & @CRLF & @CRLF & @CRLF)

;==> _ArrayAdd()

ConsoleWrite("[_ArrayAdd]" & @CRLF)
ConsoleWrite("Start adding " & $iItems & " items using _ArrayAdd func..." & @CRLF)

Dim $aArrayAdd[0]
Local $iArrayAddTime = TimerInit()

For $i = 1 To $iItems
    _ArrayAdd($aArrayAdd, $i)
Next

ConsoleWrite("Adding has end. Time spent on this action is " & Int(TimerDiff($iArrayAddTime)) & " ms." & @CRLF)
ConsoleWrite("UBound of $aArrayAdd is " & UBound($aArrayAdd) & "." & @CRLF)

 

Edited by Ascer

Share this post


Link to post
Share on other sites
  • TestSpeed ArraySearch vs ListIndexOf
#include <Array.au3>
#include <List.au3>

ConsoleWrite("Preparing array and list for later use..." & @CRLF)

Local $iSearchItem = 4999

Dim $aArray[0]

For $i = 0 To 5000
    _ArrayAdd($aArray, $i)
Next

Local $aList = _ListCreate()

For $i = 0 To 5000
    _ListAdd($aList, $i)
Next

ConsoleWrite("$aArray and $aList are ready." & @CRLF & @CRLF)

ConsoleWrite("Searching $aArray for item " & $iSearchItem & "..." & @CRLF)

Local $iArrayTime = TimerInit()
Local $iArrayFound = _ArraySearch($aArray, $iSearchItem)

If $iArrayFound <> - 1 Then
    ConsoleWrite("Found item in " & TimerDiff($iArrayTime) & " ms."  & @CRLF & @CRLF)
EndIf

ConsoleWrite("Searching $aList for item " & $iSearchItem & "..." & @CRLF)

Local $iListTime = TimerInit()
Local $vListFound = _ListIndexOf($aList, $iSearchItem)

If $vListFound <> Null Then
    ConsoleWrite("Found item in " & TimerDiff($iListTime) & " ms." & @CRLF)
EndIf

 

Share this post


Link to post
Share on other sites
  • Basic usage - creating guild with members
#include <List.au3>

ConsoleWrite("Creating list for guild members..." & @CRLF)

Local $aMembers = _ListCreate()
Local $iTotalMembers = 1000

ConsoleWrite("Successfully created list." & @CRLF)

ConsoleWrite("Creating guild members..." & @CRLF)

For $i = 1 To $iTotalMembers
    Local $aMember = _CreateMember( _
        "Member_" & $i, _
        "Vocation_" & Random(1, 4, 1), _
        Random(50, 250, 1), _
        "Rank_" & Random(1, 3, 1) _
    )
    _ListAdd($aMembers, $aMember)
Next

ConsoleWrite("Successfully created " & $iTotalMembers & " members." & @CRLF)
ConsoleWrite("Successfully added members to list." & @CRLF)

ConsoleWrite("Preparing for display list..." & @CRLF)

Local $sDisplay

For $aMember In $aMembers
    $sDisplay &= "Browse Member..." & @CRLF

    $sDisplay &= @TAB & "Name = " & _ListGetItem($aMember, 0) & @CRLF
    $sDisplay &= @TAB & "Vocation = " & _ListGetItem($aMember, 1) & @CRLF
    $sDisplay &= @TAB & "Level = " & _ListGetItem($aMember, 2) & @CRLF
    $sDisplay &= @TAB & "Rank = " & _ListGetItem($aMember, 3) & @CRLF

Next

ConsoleWrite($sDisplay)

Func _CreateMember($sName, $sVocation, $iLevel, $sRank)
    Local $aMember = _ListCreate()
    _ListAdd($aMember, $sName)
    _ListAdd($aMember, $sVocation)
    _ListAdd($aMember, $iLevel)
    _ListAdd($aMember, $sRank)
    Return $aMember
EndFunc ;==>_CreateMember

 

Edited by Ascer

Share this post


Link to post
Share on other sites

Speed example results on my system but would be interesting to see all native AutoIt and .NET  collections compared (including maps in beta AutoIt)
http://geekswithblogs.net/BlackRabbitCoder/archive/2011/06/16/c.net-fundamentals-choosing-the-right-collection-class.aspx

 

[_ListAdd]
Start adding 5000 items using _ListAdd func...
Adding has end. Time spent on this action is 103 ms.
UBound of $aListAdd is 5000.


[_ArrayAdd]
Start adding 5000 items using _ArrayAdd func...
Adding has end. Time spent on this action is 3424 ms.
UBound of $aArrayAdd is 5000.
  • TestSpeed ArraySearch vs ListIndexOf
Preparing array and list for later use...
$aArray and $aList are ready.

Searching $aArray for item 4999...
Found item in 3.74687017624091 ms.

Searching $aList for item 4999...
Found item in 0.311995511007418 ms.

And this one some nice VB .NET steps to the arrays in post#2

 

Edited by junkew

Share this post


Link to post
Share on other sites

Don't want to be spoiling the fun. 

But calling calling .Net collection calling using conventional COM will be faded out. :(

Usage of .NET Collections types in VBScript is not supported after .NET 4.5

Rgds,

ptrex


Share this post


Link to post
Share on other sites

@ptrex

I've added note about this in requiments.

Did you hear about OLEView.exe ? to check current available objects on your machine?

On my Windows 7 x64 and Windows Server 2008 R2. ArrayList working good.

What you tell about WIA.Vector ?  

 

Share this post


Link to post
Share on other sites

Vector Object seems to be working fine on Win7 and 10 , Performance not tested ...

local $v

$v = ObjCreate("WIA.vector")

$v.Add(1)
$v.Add(42)
$v.Add(3)

$v.Remove(1)
$v.Remove(2)

ConsoleWrite("$v(1) = " & $v(1) & @CRLF)

$v.Clear

$v.Add("This")
$v.Add("Is")
$v.Add("Cool")

$v.Remove(1)
$v.Remove(1)

ConsoleWrite("$v(1) = " & $v(1) & @CRLF)

 


Share this post


Link to post
Share on other sites

C# is my pick. Nothing you can’t do. Lists can be covert to array and back instantly. Tons of methods to use for anything you want. Now there is a new type Span<T> that lets us do even more in .net Core 2.1

https://msdn.microsoft.com/en-us/magazine/mt814808.aspx

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
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

  • Similar Content

    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By TheAutomator
      I'm working on a script that needs to work with a huge database inside a combobox.
      I'm looking for the best way to link a multidimensional array to that data to load that data on to textfields.

      example:
      combo item 0 = "A", data = [index linked to combo item 0] [1,0,5,4,87,9,"xyz"]
      combo item 1 = "B", data = [index linked to combo item 1] [1,6,5,4,87,9,"zzz"]
      combo item 3 = "A", data = [index linked to combo item 3] [1,6,4,4,87,9,"aaa"] ; yes also double items!
      Would also like to be able to delete and add items on the fly btw..
      Local $INDEX[0][10] ; ubound wil be resized like a stack while loading from a textfile ;inside gui: local $Combo = GUICtrlCreateCombo('...', 10, 10, 290, 25) ;gui loop: While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo display() ; how do i link my array index to the combo labels to know what to show in the textfields? ; NOTE: (there are duplicate items in the combobox!) EndSwitch WEnd Any toughs are welcome.
      I was thinking about using _GUICtrlComboBox_GetCurSel($Combo) and use that integer to refer to the index (dimension 1) of the array 
      Thanks, TheAutomator
       
    • By jmp
      Script running good but error in line 7.
      When i run this script :
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData = _IETableWriteToArray ($oTable) For $inumber = 1 To UBound($aTableData) -1 $table = $aTableData[4][$inumber] MsgBox(0, "", $table) Next I got Error: array variable has incorrect number of subscripts or subscript dimension range exceeded
    • By nacerbaaziz
      good morning all.
      first lit me give you all a thinks to your help
      you're help me allot thank you all.
      sirs today i've a new problem
      it's not a problem but thing i want to add it to blind accessability.
      the ListBox can send a notification when the user send a double click on it items
      but as we know that the blind users can't use the mouse for that they use the keybord to navigate.
      as we know that the enter replace the double click on the keybord
      for that i need when the user send a inter above any listBox item the list send a double click notification.
      i know some of you tell me that i can use the  GUISetAccelerators function
      but the enter has a other tasks such as leav a blanc line on edits and activate the defaultButton and other tasks.
      that what i need and i hope that you can help me
      this is a simple example.
      #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) global $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) global $DummyList = GUICtrlCreateDummy() GUICtrlSendToDummy($DummyList, 1) Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUIRegisterMsg($WM_command, "WM_command") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") Case $idButton_Clear GUICtrlSetData($idMylist, "") Case $idButton_Close MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit case $DummyList $g_iTemp = GUICtrlRead($DummyList) if $g_iTemp = $LBN_DBLCLK then ;$LBN_DBLCLK then msgBox(64, "", "") endIf GUICtrlSendToDummy($DummyList, 0) EndSwitch WEnd EndFunc ;==>Example Func WM_command($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case GUICtrlGetHandle($idMylist) Switch $iCode Case $LBN_SELCHANGE, $LBN_DBLCLK, $LBN_SELCANCEL, $LBN_SETFOCUS GUICtrlSendToDummy($DummyList, $iCode) case else ;GUICtrlSendToDummy($DummyTreeview, 1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
    • By nacerbaaziz
      Good morning guys, i hope that you're all well.
      guys, i have a problem and i hope that you can help me
      i've created an 3d array
      the array Contain a Categories info
      as folow
      $array[n][0][0] = Categorie name
      $array[n][0][1] = Categorie file path
      $array[n][0][2] = Categorie contents number
      $array[n][m][0] = link name
      $array[n][m][1] = link url
      $array[n][m][2] = link section name
      in my tool i want to add an option to delete a Category
      as you know the Categorie mean that must delete a region from the array
      when i tried to use _arrayDelete
      with the 2d array it work well
      but here i couldn't find any way to do that, can any one help me please?
      thanks in advance.
×
×
  • Create New...