Jump to content
Sign in to follow this  
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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By nacerbaaziz
      hello evrybody
      here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number
      e.g
      you have a long text and you want to split it in an array
      that evry colum have a number (n) of lines
      i made a function that do that for you
      just call it with a three params
      $s_text
      your text
      $i_number
      the number that you want to put in each col
      $s_siparator
      the siparator
      default is "|"
      here is the function with example
      i hope that it will be useful for you
       
      ****
       
      #include <Array.au3> $s_txt = "some text1some text2|some text3|some text4|some text5|some text6" $array = splitText($s_txt, 2) _ArrayDisplay($array) Func splitText($s_text, $i_number, $s_siparator = "|") Local $a_TXT = StringSplit($s_text, $s_siparator) Local $a_Return[$a_TXT[0] + 1] If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then ReDim $a_Return[2] $a_Return[0] = 1 $a_Return[1] = $s_text Return $a_Return EndIf Local $i_Processed = 1, $i_arrayProcessed = 1 Do For $i = $i_Processed To ($i_Processed + $i_number) - 1 If ($a_TXT[0] < $i) Then ExitLoop If Not ($a_Return[$i_arrayProcessed]) Then $a_Return[$i_arrayProcessed] = $a_TXT[$i] Else $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i] EndIf $i_Processed += 1 Next $i_arrayProcessed += 1 Until ($a_TXT[0] < $i_Processed) ReDim $a_Return[$i_arrayProcessed] $a_Return[0] = $i_arrayProcessed - 1 Return $a_Return EndFunc ;==>splitText
      accept my greetings
      thanks to
      @Dan_555
      for his notes
       
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
    • By nooneclose
      I need to dynamically resize my 2d array while looping. 
      I know this code:
      ReDim $rArray[UBound($rArray) + 1] works for the rows, however, I also need to increase the columns. How would i go about increasing both rows and columns while looping? 
×
×
  • Create New...