Jump to content
Sign in to follow this  
laffo16

Func Delete Duplicates from 3D Array Col, need help!

Recommended Posts

laffo16

been working on this function for longer then i'd care to mention, almost to the point of pulling my hair out lol

ok heres the code so far:

Func _arraydeldupes3d($adel_arr, $adel_col)
    $inc = 0
    While 1
        $inc += 1
        Dim $adel_i
        If $inc > UBound($adel_arr) -1 Then
            Return $adel_arr
        EndIf
        For $adel_i = $inc to UBound($adel_arr) -2
            If $adel_i = UBound($adel_arr) -1 Then
                Return $adel_arr
            EndIf
            If $adel_arr[$inc][$adel_col] = $adel_arr[$adel_i +1][$adel_col] Then
                _ArrayDelete4D($adel_arr, Int($inc))
                $inc = $inc - 1
                ExitLoop
            EndIf
        Next
    WEnd
EndFunc

you'll need _ArrayDelete4D() which can find from search.

execute as follows: _arraydeldupes3d(array, column_number)

does this code seem ok to you? if you have any suggestions pls help :)

Share this post


Link to post
Share on other sites
PsaltyDS

been working on this function for longer then i'd care to mention, almost to the point of pulling my hair out lol

ok heres the code so far:

Func _arraydeldupes3d($adel_arr, $adel_col)
    $inc = 0
    While 1
        $inc += 1
        Dim $adel_i
        If $inc > UBound($adel_arr) -1 Then
            Return $adel_arr
        EndIf
        For $adel_i = $inc to UBound($adel_arr) -2
            If $adel_i = UBound($adel_arr) -1 Then
                Return $adel_arr
            EndIf
            If $adel_arr[$inc][$adel_col] = $adel_arr[$adel_i +1][$adel_col] Then
                _ArrayDelete4D($adel_arr, Int($inc))
                $inc = $inc - 1
                ExitLoop
            EndIf
        Next
    WEnd
EndFuncoÝ÷ Û*.ßÙeçºÚÈ7¥z׸brø§uúèÇ­È^Åç.µæ¬~e£®¶²ué]º¬ÝÖ«­¬¢[¦{¦mêÝ¡ë-+¡×¬yé¨Ú2¢èÊ¡j÷+.¬¶*'²léiþ«¨µäáÉbë!£2¢æ«y×)àÂ+aØ6«­¬¬w
«­¢+Ù]¡Ðµå½ÔÑ¡¥¹¬¥ÐÝÌÍ

So when your function finds a duplicate in the 2D array, what is it supposed to do? Delete the row? Delete the column? Delete the value? Does it work for you? Do you have an actual test script that can be run?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
laffo16

sorry, the function _arraydeldupes3d() looks for duplicate entries in a selected column from a 2-dimensional array, if it detects a dupilcate it will delete the entire row. yes it seems to be working for me, i was wondering if someone could double check the code for me, i think my ubound calls might be a little hairy. here is an example, including another small function which converts the result into combo box format. about the 3D, i was just unsure what to call it.

#include <array.au3>

global $test_arr[9][3]
$test_arr[1][1] = "just"
$test_arr[2][1] = "another"
$test_arr[3][1] = "day"
$test_arr[4][1] = "in"
$test_arr[5][1] = "another"
$test_arr[6][1] = "just"
$test_arr[7][1] = "day"
$test_arr[8][1] = "another"

_ArrayDisplay($test_arr, "original array")
$test_arr = _arraydeldupes3d($test_arr, 1)
_ArrayDisplay($test_arr, "after _arraydeldupes3d()")
$test_combo_string = _array2combo3D($test_arr, 1)
MsgBox(0, "array to combo box format", $test_combo_string)

Func _arraydeldupes3d($adel_arr, $adel_col)
    $inc = 0
    While 1
        $inc += 1
        Dim $adel_i
        If $inc > UBound($adel_arr) -1 Then
            Return $adel_arr
        EndIf
        For $adel_i = $inc to UBound($adel_arr) -2
            If $adel_i = UBound($adel_arr) -1 Then
                Return $adel_arr
            EndIf
            If $adel_arr[$inc][$adel_col] = $adel_arr[$adel_i +1][$adel_col] Then
                _ArrayDelete4D($adel_arr, Int($inc))
                $inc = $inc - 1
                ExitLoop
            EndIf
        Next
    WEnd
EndFunc

Func _array2combo3D($a2c_arr, $a2c_col)
    Dim $a2c_str
    $a2c_i = 1
    For $a2c_i = 1 to UBound($a2c_arr) - 1
        $a2c_str = $a2c_str & "|" & $a2c_arr[$a2c_i][$a2c_col]
    Next
    Return $a2c_str
EndFunc

Func _ArrayDelete4D(ByRef $avInput, $iElement)
    If (Not IsArray($avInput)) Or (Not IsInt($iElement)) Then Return SetError(1, 0, 0) ; Wrong type of input(s)
    Local $e, $f, $g, $h
    Local $avUbounds[UBound($avInput, 0) + 1] = [UBound($avInput, 0)]
    For $e = 1 to $avUbounds[0]
        $avUbounds[$e] = UBound($avInput, $e)
    Next
    If $avUbounds[0] > 4 Then Return SetError(2, 0, 0) ; Array has more than four subscripts
    If $avUbounds[1] = 1 Then Return SetError(3, 0, 0) ; Array only has one element
    If $iElement > $avUbounds[1] - 1 Or $iElement < 0 Then Return SetError(4, 0, 0) ; $iElement out of range
    If $iElement <> $avUbounds[1] - 1 Then
        For $e = $iElement To $avUbounds[1] - 2
            Switch $avUbounds[0]
                Case 1
                    $avInput[$e] = $avInput[$e + 1]
                Case 2
                    For $f = 0 To $avUbounds[2] - 1
                        $avInput[$e][$f] = $avInput[$e + 1][$f]
                    Next
                Case 3
                    For $f = 0 To $avUbounds[2] - 1
                        For $g = 0 To $avUbounds[3] - 1
                            $avInput[$e][$f][$g] = $avInput[$e + 1][$f][$g]
                        Next
                    Next
                Case 4
                    For $f = 0 To $avUbounds[2] - 1
                        For $g = 0 To $avUbounds[3] - 1
                            For $h = 0 To $avUbounds[4] - 1
                                $avInput[$e][$f][$g][$h] = $avInput[$e + 1][$f][$g][$h]
                            Next
                        Next
                    Next
            EndSwitch
        Next
    EndIf
    Switch $avUbounds[0]
        Case 1
            ReDim $avInput[$avUbounds[1] - 1]
        Case 2
            ReDim $avInput[$avUbounds[1] - 1][$avUbounds[2]]
        Case 3
            ReDim $avInput[$avUbounds[1] - 1][$avUbounds[2]][$avUbounds[3]]
        Case 4
            ReDim $avInput[$avUbounds[1] - 1][$avUbounds[2]][$avUbounds[3]][$avUbounds[4]]
    EndSwitch
    Return 1
EndFunc   ;==>_ArrayDelete3D
Edited by laffo16

Share this post


Link to post
Share on other sites
PsaltyDS

Well, if it works, that's the main thing. It might be slow because of all the iterative looping through the array, but functionality comes first.

And if the name is going to be unrelated to the actual function's properties, you should have named it _Abigail(). I like the name Abigail.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

]#include <array.au3>
Dim $ar[5], $ar2[5][2]
$ar[0] = "otto"
$ar[1] = "aha"
$ar[2] = "otto"
$ar[3] = "b"
$ar[4] = "aha"

$ar2[0][0] = "otto"
$ar2[1][0] = "aha"
$ar2[2][0] = "otto"
$ar2[3][0] = "b"
$ar2[4][0] = "ah"
$ar2[0][1] = "c"
$ar2[1][1] = "ha"
$ar2[2][1] = "c"
$ar2[3][1] = "bor"
$ar2[4][1] = "aha"

_ArrayDisplay($ar, "1D mit Doppel")
_Array2DDblDel($ar)
_ArrayDisplay($ar, "1D Doppel gelöscht")

_ArrayDisplay($ar2, "2D mit Doppel")
_Array2DDblDel($ar2)
_ArrayDisplay($ar2, "2D Doppel gelöscht")

;----------------------------------------------------------------------------------------------------------------------
; Function        _Array2DDblDel(ByRef $ARRAY [, $CASESENS=0])
;
; Description    - From an 1D/2D Array will delete double entries (2D -> combination by '[n][0]' to '[n][x]').
;                - Autodetection 1D/2D Array
;                - By using string, you can choose case sensitivity.
;
; Parameter        $ARRAY:            Array to sort
;    optional    $CASESENS:        Case sensitivity off[0] or on[1] (default 0)
;
; Return        Succes            ByRef Array without doubles
;                                Count of doubles
;                Failure            0 and set @error = 1; no array
;
; Author        BugFix (bugfix@autoit.de)
;----------------------------------------------------------------------------------------------------------------------
Func _Array2DDblDel(ByRef $ARRAY, $CASESENS=0)
    Local $iDIM, $arTmp[1] = [''], $dbl = 0, $count = 0
    If ( Not IsArray($ARRAY) ) Then
        SetError(1)
        Return 0
    EndIf
    $Ubound2nd = UBound($ARRAY,2)
    If @error = 2 Then
        For $i = 0 To UBound($ARRAY)-1
            $dbl = 0
            For $k = 0 To UBound($arTmp)-1
                Switch $CASESENS
                    Case 0
                        If $arTmp[$k] = $ARRAY[$i] Then 
                            $dbl = 1
                            $count += 1
                        EndIf
                    Case 1
                        If $arTmp[$k] == $ARRAY[$i] Then
                            $dbl = 1
                            $count += 1
                        EndIf
                EndSwitch    
            Next
            If $dbl = 0 Then
                If $arTmp[0] = "" Then
                    $arTmp[0] = $ARRAY[$i]
                Else
                    ReDim $arTmp[UBound($arTmp)+1]
                    $arTmp[UBound($arTmp)-1] = $ARRAY[$i]
                EndIf
            Else
                $dbl = 0
            EndIf
        Next
    Else
        ReDim $arTmp[1][$Ubound2nd]
        $arTmp[0][0] = ''
        $x = 0
        For $i = 0 To UBound($ARRAY)-1
            $dbl = 0
            $val = ''
            $valTmp = ''
            For $l = 0 To $Ubound2nd-1
                $val &= $ARRAY[$i][$l]
            Next
            For $k = 0 To UBound($arTmp)-1
                For $l = 0 To $Ubound2nd-1
                    $valTmp &= $arTmp[$k][$l]
                Next
                Switch $CASESENS
                    Case 0
                        If  $valTmp = $val Then
                            $dbl = 1
                            $count += 1
                        EndIf
                    Case 1        
                        If  $valTmp == $val Then
                            $dbl = 1
                            $count += 1
                        EndIf
                EndSwitch                
            Next
            If $dbl = 0 Then
                If $x = 1 Then ReDim $arTmp[UBound($arTmp)+1][$Ubound2nd]
                For $l = 0 To $Ubound2nd-1
                    If $arTmp[0][0] = '' Or $x = 0 Then    
                        $arTmp[0][$l] = $ARRAY[0][$l]
                        If $l = $Ubound2nd-1 Then $x = 1
                    Else
                        $arTmp[UBound($arTmp)-1][$l] = $ARRAY[$i][$l]
                        $x = 2
                        If $l = $Ubound2nd-1 Then $x = 1
                    EndIf
                Next
            Else
                $dbl = 0
            EndIf
        Next
    EndIf
    $ARRAY = $arTmp
    Return $count
EndFunc ; ==>_ArrayDblDel

So long,

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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  

×