Jump to content

Recommended Posts

Posted (edited)

A globally unique identifier (GUID) is a unique reference number used as an identifier in computer software. The chance of 2 GUIDs being generated is highly unlikely, though not impossible.

Source: https://en.wikipedia.org/wiki/Globally_unique_identifier

#include <Array.au3>
#include <StringConstants.au3>
#include <WinAPICom.au3>

Example()

Func Example()
    Local $aArray[1000]
    For $i = 0 To UBound($aArray) - 1
        $aArray[$i] = _WinAPI_CreateGUID()
    Next

    Local $hTimer = TimerInit()
    Local $bReturn = _ArrayUniqueFast($aArray, True) ; The standard _ArrayUnqiue() is very slow when using large arrays.
    ConsoleWrite('Time: ' & TimerDiff($hTimer) & @CRLF)
    ConsoleWrite('Return: ' & $bReturn & @CRLF)
    _ArrayDisplay($aArray) ; The last index should be 9999. This shows that _WinAPI_CreateGUID is unique.
EndFunc   ;==>Example

Func _ArrayUniqueFast(ByRef $aArray, $bIsCaseSensitive = False)
    Local Const $AUF_DELIM = ChrW(160), $AUF_LENGTH = 2, $AUF_LOCAL = 1
    Local $sOutput = '', $sString = ''
    For $i = 0 To UBound($aArray) - 1
        $sString = StringTrimLeft(StringToBinary($bIsCaseSensitive ? $aArray[$i] : StringLower($aArray[$i])), $AUF_LENGTH)
        If Not IsDeclared($sString) Then
            Assign($sString, 0, $AUF_LOCAL)
            $sOutput &= $aArray[$i] & $AUF_DELIM
        EndIf
    Next
    $sOutput = StringTrimRight($sOutput, StringLen($AUF_DELIM))
    $aArray = StringSplit($sOutput, $AUF_DELIM, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
    If @error Then
        Local $aTemp[0]
        $aArray = $aTemp
    EndIf
    Return UBound($aArray) > 0
EndFunc   ;==>_ArrayUniqueFast
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 5 months later...
Posted

Fixed bug in _ArrayUniqueEx when passing a 2d array. Updated the initial post.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 3 months later...
Posted

Improved source code by replacing the _ArrayUniqueFast function wit native AutoIt code.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 6 months later...
Posted

_ArrayUniqueFast() is now case-sensitive. This is thanks to an idea czardas gave here in which they mentioned about converting to hex.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 4 months later...
Posted

I have updated _ArrayUniqueFast() that previously was misuing a bug in AutoIt where variables could be assigned with non-word characters.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 4 months later...
Posted

Another update, though nothing new I am afraid.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 6 months later...
Posted

Removed the count in the first index, as I prefer to use UBound to retrieve the length.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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