﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2563	UDF - _ArrayUnique - proposal	mlipok		"'''now is:'''

{{{
Func _ArrayUnique(Const ByRef $aArray, $iColumn = Default, $iBase = Default, $iCase = Default, $iFlags = Default)
	If $iColumn = Default Then $iColumn = 1
	If $iBase = Default Then $iBase = 0
	If $iCase = Default Then $iCase = 0
	If $iFlags = Default Then $iFlags = 1
	; Start bounds checking
	If UBound($aArray) = 0 Then Return SetError(1, 0, 0) ; Check if array is empty, or not an array
	; $iBase can only be 0 or 1, if anything else, return with an error
	If $iBase < 0 Or $iBase > 1 Or (Not IsInt($iBase)) Then Return SetError(2, 0, 0)
	If $iCase < 0 Or $iCase > 1 Or (Not IsInt($iCase)) Then Return SetError(2, 0, 0)
	If $iFlags < 0 Or $iFlags > 1 Or (Not IsInt($iFlags)) Then Return SetError(4, 0, 0)
	Local $iDims = UBound($aArray, 0), $iNumColumns = UBound($aArray, 2)
	If $iDims > 2 Then Return SetError(3, 0, 0)
	; checks the given dimension is valid
	If ($iColumn < 1) Or ($iNumColumns = 0 And ($iColumn - 1 > $iNumColumns)) Or ($iNumColumns > 0 And ($iColumn > $iNumColumns)) Then Return SetError(3, 0, 0)
	; make $iColumn an array index, note this is ignored for 1D arrays
	$iColumn -= 1
	; create dictionary
	Local $oD = ObjCreate(""Scripting.Dictionary"")
	; compare mode for strings
	; 0 = binary, which is case sensitive
	; 1 = text, which is case insensitive
	; this expression forces either 1 or 0
	$oD.CompareMode = Number(Not $iCase)
	Local $vElem
	; walk the input array
	For $i = $iBase To UBound($aArray) - 1
		If $iDims = 1 Then
			; 1D array
			$vElem = $aArray[$i]
		Else
			; 2D array
			$vElem = $aArray[$i][$iColumn]
		EndIf
		; add key to dictionary
		; NOTE: accessing the value (.Item property) of a key that doesn't exist creates the key :)
		; keys are guaranteed to be unique
		$oD.Item($vElem)
	Next
	;
	; return the array of unique keys
	If BitAND($iFlags, 1) = 1 Then
		Local $aTemp = $oD.Keys()
		_ArrayInsert($aTemp, 0, $oD.Count)
		Return $aTemp
	Else
		Return $oD.Keys()
	EndIf
EndFunc   ;==>_ArrayUnique

}}}

'''proposal:'''

{{{
Func _ArrayUnique(Const ByRef $aArray, $iColumn = Default, $iBase = Default, $iCase = Default, $iFlags = Default)
	If $iColumn = Default Then $iColumn = 1
	If $iBase = Default Then $iBase = 0
	If $iCase = Default Then $iCase = 0
	If $iFlags = Default Then $iFlags = 1
	; Start bounds checking
	Local $iUBound = UBound($aArray)
	If $iUBound = 0 Then Return SetError(1, 0, 0) ; Check if array is empty, or not an array
	; $iBase can only be 0 or 1, if anything else, return with an error
	If $iBase < 0 Or $iBase > 1 Or (Not IsInt($iBase)) Then Return SetError(2, 0, 0)
	If $iCase < 0 Or $iCase > 1 Or (Not IsInt($iCase)) Then Return SetError(2, 0, 0)
	If $iFlags < 0 Or $iFlags > 1 Or (Not IsInt($iFlags)) Then Return SetError(4, 0, 0)
	Local $iDims = UBound($aArray, 0), $iNumColumns = UBound($aArray, 2)
	If $iDims > 2 Then Return SetError(3, 0, 0)
	; checks the given dimension is valid
	If ($iColumn < 1) Or ($iNumColumns = 0 And ($iColumn - 1 > $iNumColumns)) Or ($iNumColumns > 0 And ($iColumn > $iNumColumns)) Then Return SetError(3, 0, 0)
	; make $iColumn an array index, note this is ignored for 1D arrays
	$iColumn -= 1
	; create dictionary
	Local $oD = ObjCreate(""Scripting.Dictionary"")
	; compare mode for strings
	; 0 = binary, which is case sensitive
	; 1 = text, which is case insensitive
	; this expression forces either 1 or 0
	$oD.CompareMode = Number(Not $iCase)
	Local $vElem
	; walk the input array
	$iUBound -=1
	For $i = $iBase To $iUBound
		If $iDims = 1 Then
			; 1D array
			$vElem = $aArray[$i]
		Else
			; 2D array
			$vElem = $aArray[$i][$iColumn]
		EndIf
		; add key to dictionary
		; NOTE: accessing the value (.Item property) of a key that doesn't exist creates the key :)
		; keys are guaranteed to be unique
		$oD.Item($vElem)
	Next
	;
	; return the array of unique keys
	If BitAND($iFlags, 1) = 1 Then
		Local $aTemp = $oD.Keys()
		_ArrayInsert($aTemp, 0, $oD.Count)
		Return $aTemp
	Else
		Return $oD.Keys()
	EndIf
EndFunc   ;==>_ArrayUnique

}}}

'''changed:'''

{{{
Local $iUBound = UBound($aArray)
If $iUBound = 0 Then Return SetError(1, 0, 0) ; Check if array is empty, or not an array
}}}

'''and'''

{{{
$iUBound -=1
For $i = $iBase To $iUBound
}}}

'''because: faster'''"	Feature Request	closed		Standard UDFs		None	Rejected		
