Search the Community
Showing results for tags 'array unique associative'.
-
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