Jump to content

[UDF] ArrayList - actions on huge arrays


Ascer
 Share

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

 

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

Link to comment
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)

 

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

 

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

×
×
  • Create New...