wolf9228

Number CArray

5 posts in this topic

#1 ·  Posted (edited)

CArray.zip

This project includes the construction of two-dimensional array and a one-dimensional array depending on the data structures ... arrays private enterprise figures without strings and are quick in completing operations .

CArray.au3

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>

Global $kernel32 = DllOpen("kernel32.dll"),$DoubleSize=DllStructGetSize(DllStructCreate("DOUBLE"))

Func CArray1D($RowsCount)
If $RowsCount < 1 Then Return SetError(1,0,0)
$CArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $RowsCount & "]")
DllStructSetData($CArray1D,1,$RowsCount)
Return $CArray1D
EndFunc

Func UBound1D(ByRef $CArray1D)
$RE = DllStructGetData($CArray1D,"RE")
if ($RE = 0) Then Return SetError(1,0,0)
Return $RE
EndFunc

Func ReDim1D(ByRef $CArray1D,$RowsCount)

Local $iRowsCount  =  DllStructGetData($CArray1D, 1)
Local $TestBool = $iRowsCount > 0 And $RowsCount > 0

Select
Case $TestBool And $RowsCount > $iRowsCount
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $RowsCount & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = ($DoubleSize * $iRowsCount)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray1D,1,$RowsCount)
$CArray1D = $NewCArray1D
Return True
Case $TestBool And $RowsCount < $iRowsCount
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $RowsCount & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = $DoubleSize * $RowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray1D,1,$RowsCount)
$CArray1D = $NewCArray1D
Return True
Case ($TestBool) And ($RowsCount = $iRowsCount)
Return True
EndSelect

Return SetError(1,0,False)

EndFunc

Func GetAt1D(ByRef $CArray1D,$RowIndex)

Local $vValue = DllStructGetData($CArray1D,2,($RowIndex + 1))
Return SetError(@error <> 0,0,$vValue)

EndFunc

Func SetAt1D(ByRef $CArray1D,$RowIndex,$vValue)

DllStructSetData($CArray1D,2,$vValue,($RowIndex + 1))
$Error = @error
Return SetError($Error <> 0,0,$Error == 0)

EndFunc

Func SetWithReDim1D(ByRef $CArray1D,$RowIndex,$vValue)

$RowIndex += 1
Local $RowsCount = DllStructGetData($CArray1D,"RE")

Select
Case $RowsCount = 0 Or $RowIndex < 1
Return SetError(1,0,False)
Case $RowIndex <= $RowsCount
DllStructSetData($CArray1D,2,$vValue,$RowIndex)
Return True
Case $RowIndex > $RowsCount
;----------------ReDim---------------------------------
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $RowIndex & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = $DoubleSize * $RowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray1D,1,$RowIndex)
;----------------ReDim---------------------------------
$CArray1D = $NewCArray1D
DllStructSetData($CArray1D,2,$vValue,$RowIndex)
Return True
EndSelect

EndFunc

Func Add1D(ByRef $CArray1D,$vValue,$End = True)

Local $iRowsCount = DllStructGetData($CArray1D , 1 )
Local $NRowsCount =  $iRowsCount + 1

Select
Case $End = True And $iRowsCount > 0
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $NRowsCount & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = $DoubleSize * $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray1D,1,$NRowsCount)
DllStructSetData($NewCArray1D,2,$vValue,$NRowsCount)
$CArray1D = $NewCArray1D
Return True
Case $End = False And $iRowsCount > 0
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $NRowsCount & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = $DoubleSize * $iRowsCount
Local $SizeC = $DoubleSize ;($DoubleSize * 1)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeC,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray1D,1,$NRowsCount)
DllStructSetData($NewCArray1D,2,$vValue,1)
$CArray1D = $NewCArray1D
Return True
EndSelect

Return SetError(1,0,False)

EndFunc

Func InsertAt1D(ByRef $CArray1D,$RowIndex,$vValue)

Local $iRowsCount = DllStructGetData($CArray1D,1),$NRowIndex = ($RowIndex + 1)
Local $NRowsCount =  $iRowsCount + 1

Select
Case $iRowsCount > 0 And $NRowIndex > 0 And $NRowIndex <= $iRowsCount
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $NRowsCount & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = $DoubleSize * $RowIndex
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
Local $SizeB = $DoubleSize * $NRowIndex
Local $SizeC =  $DoubleSize * $RowIndex
Local $SizeD = $DoubleSize * ($iRowsCount - $RowIndex)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeB,"PTR",$ElementsPtr + $SizeC,"ULONG_PTR",$SizeD)
DllStructSetData($NewCArray1D,1,$NRowsCount)
DllStructSetData($NewCArray1D,2,$vValue,$NRowIndex)
$CArray1D = $NewCArray1D
Return True
EndSelect

Return SetError(1,0,False)

EndFunc

Func DeleteAt1D(ByRef $CArray1D,$RowIndex)
Local $iRowsCount = DllStructGetData($CArray1D,1)
if $RowIndex < 0 Or $RowIndex > $iRowsCount - 1 _
Or $iRowsCount = 0 Then Return SetError(1,0,False)
Local $nRowsCount = $iRowsCount - 1
Local $NewCArray1D = DllStructCreate("INT RE;DOUBLE ELEMENTS[" & $nRowsCount & "]")
Local $ElementsPtr = DllStructGetPtr(  $CArray1D  , 2 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray1D,2)
Local $SizeA = $DoubleSize * $RowIndex
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
Local $SizeB = $DoubleSize * ($iRowsCount - ($RowIndex + 1))
Local $SizeC = $DoubleSize * $RowIndex
Local $SizeD = $DoubleSize * ($RowIndex + 1)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeC,"PTR",$ElementsPtr + $SizeD,"ULONG_PTR",$SizeB)
DllStructSetData($NewCArray1D,1,$nRowsCount)
$RowIndex += 1
$CArray1D = $NewCArray1D
Return True
EndFunc



Func CArray2D($RowsCount,$ColusCount)
Select
Case $RowsCount < 1 Or $ColusCount < 1
Return SetError(1,0,0)
Case Else
Local $ElementsCount = $RowsCount * $ColusCount
Local $CArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
DllStructSetData($CArray2D,1,$RowsCount)
DllStructSetData($CArray2D,2,$ColusCount)
Return $CArray2D
EndSelect
EndFunc

Func UBound2D(ByRef $CArray2D , $Dimension = 1)
Switch $Dimension
Case 1
$RE = DllStructGetData($CArray2D,"RE")
if ($RE = 0) Then Return SetError(1,0,0)
Return $RE
Case 2
$CE = DllStructGetData($CArray2D,"CE")
if ($CE = 0) Then Return SetError(1,0,0)
Return $CE
Case Else
Return SetError(2,0,0)
EndSwitch
EndFunc

Func ReDim2D(ByRef $CArray2D,$RowsCount,$ColusCount)
Local $iRowsCount = DllStructGetData($CArray2D,"RE")
Local $iColusCount= DllStructGetData($CArray2D,"CE")
Select
Case $iRowsCount < 1 Or $RowsCount < 1 _
Or $iColusCount < 1 Or $iColusCount < 1
Return SetError(1,0,False)
Case $ColusCount = $iColusCount And $RowsCount > $iRowsCount
Local $ElementsCount = $RowsCount * $ColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;BYTE DATATYPE["&$ElementsCount&"];DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $ColusCount * $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray2D,1,$RowsCount)
DllStructSetData($NewCArray2D,2,$ColusCount)
$CArray2D = $NewCArray2D
Return True
Case $ColusCount = $iColusCount And $RowsCount < $iRowsCount
Local $ElementsCount = $RowsCount * $ColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $ColusCount * $RowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray2D,1,$RowsCount)
DllStructSetData($NewCArray2D,2,$ColusCount)
$CArray2D = $NewCArray2D
Return True
Case ($ColusCount > $iColusCount And $RowsCount >= $iRowsCount)
Local $ElementsCount = $RowsCount * $ColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $RowSizeA =  $ColusCount * $DoubleSize
Local $RowSizeB = $iColusCount * $DoubleSize
For $i = 1 To $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$RowSizeB)
$NewElementsPtr += $RowSizeA
$ElementsPtr += $RowSizeB
Next
DllStructSetData($NewCArray2D,1,$RowsCount)
DllStructSetData($NewCArray2D,2,$ColusCount)
$CArray2D = $NewCArray2D
Return True
Case $ColusCount = $iColusCount And $RowsCount = $iRowsCount
Return True
Case Else
Local $pRowsCount = $iRowsCount , $pColusCount = $iColusCount
If $RowsCount < $iRowsCount Then $pRowsCount = $RowsCount
If $ColusCount < $iColusCount Then $pColusCount = $ColusCount
Local $ElementsCount = $RowsCount * $ColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $RowSizeA =  $ColusCount * $DoubleSize
Local $RowSizeB = $iColusCount * $DoubleSize
Local $RowSizeC = $pColusCount * $DoubleSize
For $i = 1 To $iRowsCount
Select
Case $i <= $pRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$RowSizeC)
$NewElementsPtr += $RowSizeA
$ElementsPtr += $RowSizeB
EndSelect
Next
DllStructSetData($NewCArray2D,1,$RowsCount)
DllStructSetData($NewCArray2D,2,$ColusCount)
$CArray2D = $NewCArray2D
Return True
EndSelect
EndFunc


Func GetAt2D(ByRef $CArray2D,$RowIndex,$ColuIndex)

Local $RowsCount  = DllStructGetData($CArray2D,"RE")
Local $ColusCount = DllStructGetData($CArray2D,"CE")

$RowIndex  += 1
$ColuIndex += 1

Select
Case $RowIndex < 1 Or $RowIndex > $RowsCount Or  $ColuIndex < 1 _
Or $ColuIndex > $ColusCount  Or $RowsCount < 1 Or $ColusCount < 1
Return SetError(1,0,0)
Case Else
Local $ElementNu = ($RowIndex * $ColusCount) - ($ColusCount - $ColuIndex)
Local $vValue = DllStructGetData($CArray2D,3,$ElementNu)
Return SetError(@error <> 0,0,$vValue)
EndSelect

EndFunc

Func SetAt2D(ByRef $CArray2D,$RowIndex,$ColuIndex,$vValue)

Local $RowsCount  = DllStructGetData($CArray2D,1)
Local $ColusCount = DllStructGetData($CArray2D,2)

$RowIndex  += 1
$ColuIndex += 1

Select
Case $RowIndex < 1 Or  $RowIndex > $RowsCount Or $ColuIndex < 1 _
Or $ColuIndex > $ColusCount Or $RowsCount < 1 Or $ColusCount < 1
Return SetError(1,0,False)
Case Else
Local $ElementNu = ($RowIndex * $ColusCount) - ($ColusCount - $ColuIndex)
DllStructSetData($CArray2D,3,$vValue,$ElementNu)
$Error = @error
Return SetError($Error <> 0,0,$Error == 0)
EndSelect

EndFunc

Func SetWithReDim2D(ByRef $CArray2D,$RowIndex,$ColuIndex,$vValue)

Local $DataType = 0
Local $RowsCount  = DllStructGetData($CArray2D,"RE")
Local $ColusCount = DllStructGetData($CArray2D,"CE")

$RowIndex  += 1
$ColuIndex += 1

Select
Case $RowIndex < 1 Or $ColuIndex < 1 Or $RowsCount < 1 Or $ColusCount < 1
Return SetError(1,0,False)
Case Else
Select
Case $RowIndex <= $RowsCount And $ColuIndex <= $ColusCount
Local $ElementNu = ($RowIndex * $ColusCount) - ($ColusCount - $ColuIndex)
DllStructSetData($CArray2D,3,$vValue,$ElementNu)
Return True
Case $ColuIndex = $ColusCount And $RowIndex > $RowsCount
;-------------------------------------------ReDim---------------------------------------------------------
Local $ElementsCount = $RowIndex * $ColuIndex
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $ColuIndex * $RowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllStructSetData($NewCArray2D,1,$RowIndex)
DllStructSetData($NewCArray2D,2,$ColuIndex)
;-------------------------------------------ReDim---------------------------------------------------------
Local $ElementNu = ($RowIndex * $ColuIndex)
DllStructSetData($NewCArray2D,3,$DataType,$ElementNu)
DllStructSetData($NewCArray2D,4,$vValue,$ElementNu)
$CArray2D = $NewCArray2D
Return True
Case Else ; $ColuIndex > $ColusCount And $RowIndex > $RowsCount or $ColuIndex > $ColusCount And $RowIndex = $RowsCount
;-------------------------------------------ReDim---------------------------------------------------------
Local $pRowsCount = $RowsCount ,$pColusCount = $ColusCount
If $RowIndex  >  $RowsCount Then  $pRowsCount  = $RowIndex
If $ColuIndex > $ColusCount Then $pColusCount = $ColuIndex
Local $ElementsCount = $pRowsCount * $pColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $RowSizeA =  $ColusCount * $DoubleSize
Local $RowSizeC =  $ColusCount * $DoubleSize
Local $RowSizeE =  $pColusCount * $DoubleSize
For $i = 1 To $RowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$RowSizeA)
$ElementsPtr += $RowSizeC
$NewElementsPtr += $RowSizeE
Next
DllStructSetData($NewCArray2D,1,$pRowsCount)
DllStructSetData($NewCArray2D,2,$pColusCount)
;-------------------------------------------ReDim---------------------------------------------------------
$ElementNu = ($RowIndex * $pColusCount) - ($pColusCount - $ColuIndex)
DllStructSetData($NewCArray2D,3,$vValue,$ElementNu)
$CArray2D = $NewCArray2D
Return True
EndSelect
EndSelect

EndFunc

Func Add2D(ByRef $CArray2D,$RowsCount = 1,$RowsEnd = True,$ColsCount = 0,$ColsEnd = True)
Local $iRowsCount = DllStructGetData($CArray2D,"RE")
Local $iColusCount= DllStructGetData($CArray2D,"CE")
Local $vIndex = 0
Select
Case $RowsCount < 0 Or $ColsCount < 0 Or $iRowsCount < 1 Or $iColusCount < 1
Return SetError(1,0,False)
Case $ColsCount = 0 And $RowsCount = 0
Return True
Case $ColsCount = 0
Local $NewRowsCount = $iRowsCount + $RowsCount
Local $ElementsCount = $NewRowsCount * $iColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $iColusCount * $iRowsCount
Local $SizeC = $DoubleSize * $iColusCount * $RowsCount
Select
Case $RowsEnd = True
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
Case $RowsEnd = False
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeC,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
EndSelect
DllStructSetData($NewCArray2D,1,$NewRowsCount)
DllStructSetData($NewCArray2D,2,$iColusCount)
$CArray2D = $NewCArray2D
Return True
Case Else
Local $NewRowsCount = $iRowsCount + $RowsCount
Local $NewColsCount = $iColusCount + $ColsCount
Local $ElementsCount = $NewRowsCount * ($NewColsCount)
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $iColusCount
Local $SizeB = $DoubleSize * $NewColsCount
Local $SizeC = $DoubleSize * $ColsCount
Local $SizeG = $DoubleSize * $NewColsCount * $RowsCount
Select
Case $RowsEnd = True And $ColsEnd = True
For $i = 1 To $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
$ElementsPtr += $SizeA
$NewElementsPtr += $SizeB
Next
Case $RowsEnd = True And $ColsEnd = False
For $i = 1 To $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeC,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
$ElementsPtr += $SizeA
$NewElementsPtr += $SizeB
Next
Case $RowsEnd = False And $ColsEnd = True
$NewElementsPtr += $SizeG
For $i = 1 To $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
$ElementsPtr += $SizeA
$NewElementsPtr += $SizeB
Next
Case $RowsEnd = False And $ColsEnd = False
$NewElementsPtr += $SizeG
For $i = 1 To $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeC,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
$ElementsPtr += $SizeA
$NewElementsPtr += $SizeB
Next
EndSelect
DllStructSetData($NewCArray2D,1,$NewRowsCount)
DllStructSetData($NewCArray2D,2,$NewColsCount)
$CArray2D = $NewCArray2D
Return True
EndSelect
EndFunc

Func Insert2D(ByRef $CArray2D,$RowIndex = 0,$RowsCount = 1,$ColuIndex = 0,$ColsCount = 0)
Local $iRowsCount = DllStructGetData($CArray2D,"RE")
Local $iColusCount= DllStructGetData($CArray2D,"CE")
Select
Case $RowsCount < 0 Or $ColsCount < 0 Or $iRowsCount < 1 Or $iColusCount < 1 Or $RowIndex < 0 _
Or $ColuIndex < 0 Or $RowIndex > ($iRowsCount -1) Or $ColuIndex > ($iColusCount -1)
Return SetError(1,0,False)
Case $ColsCount = 0 And $RowsCount = 0
Return True
Case $ColsCount = 0
Local $NewRowsCount = $iRowsCount + $RowsCount
Local $ElementsCount = $NewRowsCount * $iColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $RowIndex * $iColusCount
Local $SizeB = $DoubleSize * ($iRowsCount - $RowIndex) * $iColusCount
Local $SizeC = $DoubleSize * $RowsCount * $iColusCount + $SizeA
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeC,"PTR",$ElementsPtr + $SizeA,"ULONG_PTR",$SizeB)
DllStructSetData($NewCArray2D,1,$NewRowsCount)
DllStructSetData($NewCArray2D,2,$iColusCount)
$CArray2D = $NewCArray2D
Return True
Case Else
Local $NewRowsCount = $iRowsCount + $RowsCount
Local $NewColsCount = $iColusCount + $ColsCount
Local $ElementsCount = $NewRowsCount * $NewColsCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $ColuIndex
Local $SizeB = $DoubleSize * ($iColusCount - $ColuIndex)
Local $SizeC = $DoubleSize * $ColsCount
Local $SizeD = $DoubleSize * $NewColsCount
Local $SizeE = $DoubleSize * $iColusCount
Local $SizeF = $DoubleSize * $RowsCount * $NewColsCount
Local $SizeM = $SizeA + $SizeC
For $i = 1 To $RowIndex
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeM,"PTR",$ElementsPtr + $SizeA,"ULONG_PTR",$SizeB)
$NewElementsPtr += $SizeD
$ElementsPtr += $SizeE
Next
$NewElementsPtr += $SizeF
For $j = $RowIndex + 1 To $iRowsCount
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeM,"PTR",$ElementsPtr + $SizeA,"ULONG_PTR",$SizeB)
$NewElementsPtr += $SizeD
$ElementsPtr += $SizeE
Next
DllStructSetData($NewCArray2D,1,$NewRowsCount)
DllStructSetData($NewCArray2D,2,$NewColsCount)
$CArray2D = $NewCArray2D
Return True
EndSelect
EndFunc

Func Delete2D(ByRef $CArray2D,$RowIndex = 0,$RowsCount = 1,$ColuIndex = 0,$ColsCount = 0)
Local $iRowsCount = DllStructGetData($CArray2D,"RE")
Local $iColusCount= DllStructGetData($CArray2D,"CE")
Select
Case $RowIndex < 0 Or $ColuIndex < 0 Or $RowsCount >= $iRowsCount - $RowIndex _
Or $ColsCount >= $iColusCount - $ColuIndex Or $RowsCount < 0 Or $ColsCount < 0
Return SetError(1,0,False)
Case $ColsCount = 0 And $RowsCount = 0
Return True
Case $ColsCount = 0
Local $NewRowsCount = $iRowsCount - $RowsCount
Local $ElementsCount = $NewRowsCount * $iColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $RowIndex * $iColusCount
Local $SizeB = $DoubleSize * ($iRowsCount - ($RowsCount + $RowIndex)) * $iColusCount
Local $SizeC = $DoubleSize * $RowsCount * $iColusCount
Local $SizeD = $SizeA + $SizeC
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeA,"PTR",$ElementsPtr + $SizeD,"ULONG_PTR",$SizeB)
DllStructSetData($NewCArray2D,1,$NewRowsCount)
DllStructSetData($NewCArray2D,2,$iColusCount)
$CArray2D = $NewCArray2D
Case Else
$RowIndex += 1
Local $NewColusCount = $iColusCount - $ColsCount
Local $NewRowsCount = $iRowsCount - $RowsCount
Local $ElementsCount = $NewRowsCount * $NewColusCount
Local $NewCArray2D = DllStructCreate("INT RE;INT CE;DOUBLE ELEMENTS["&$ElementsCount&"]")
Local $ElementsPtr = DllStructGetPtr(  $CArray2D  , 3 )
Local $NewElementsPtr = DllStructGetPtr($NewCArray2D,3)
Local $SizeA = $DoubleSize * $ColuIndex
Local $SizeB = $DoubleSize * $ColsCount
Local $SizeC = $DoubleSize * $iColusCount - ($SizeA + $SizeB)
Local $SizeD = $SizeA + $SizeB
Local $SizeI = $DoubleSize * $iColusCount
Local $Sizej = $DoubleSize * $NewColusCount
Local $nLoop = $ColuIndex + 1
Local $vLoop = $ColuIndex + $ColsCount
Local $vCase = $RowIndex + $RowsCount - 1
For $i = 1 To $iRowsCount
Select
Case $i < $RowIndex Or $i > $vCase
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr,"PTR",$ElementsPtr,"ULONG_PTR",$SizeA)
DllCall($kernel32,"NONE","RtlMoveMemory","PTR",$NewElementsPtr + $SizeA,"PTR",$ElementsPtr + $SizeD,"ULONG_PTR",$SizeC)
$NewElementsPtr += $Sizej
$ElementsPtr += $SizeI
Case Else
$ElementsPtr += $SizeI
EndSelect
Next
DllStructSetData($NewCArray2D,1,$NewRowsCount)
DllStructSetData($NewCArray2D,2,$NewColusCount)
$CArray2D = $NewCArray2D
Return True
EndSelect
EndFunc



Func Display(ByRef $CArrayStruct,$Title = "DisplayCArray")
$TrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]") ;Taskbar Window
$WPos = WinGetPos($TrayWnd)
If Not IsArray($WPos) Then
$iH = @DesktopHeight - 68
Else
$iH = $WPos[1] - 30
EndIf
$RE = DllStructGetData($CArrayStruct,"RE")
$CE = DllStructGetData($CArrayStruct,"CE")
Local $Error = @error , $Value = ""
if $Error Then $CE = 1
$W = (($CE + 1) * 70) + 15 ; $CE + 1 ==> 1 Rows Number
$H = (($RE + 1) * 20) + 50 ; $RE + 1 ==> 1 Clos Number
If $W > (@DesktopWidth - 5) Then $W = @DesktopWidth - 5
If $H > $iH Then $H = $iH
GUICreate($Title,$W,$H,0,0)
$W -= 10
$H -= 40
$hListView = GUICtrlCreateListView("",5,5,$W,$H)
_GUICtrlListView_SetExtendedListViewStyle($hListView, _
BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_FLATSB))
$CopyButton = GUICtrlCreateButton("Copy Selected", 5,$H + 10, $W - 5, 25)
For $i = 0 To $RE - 1
For $j = 0 To $CE - 1
if ($Error) Then
$Value = GetAt1D($CArrayStruct,$i)
Else
$Value = GetAt2D($CArrayStruct,$i,$j)
EndIf
If $i = 0 Then
If $J = 0 Then _
_GUICtrlListView_AddColumn($hListView, "Row",70)
_GUICtrlListView_AddColumn($hListView, "Col " & $J,70)
EndIf
If $j = 0 Then
_GUICtrlListView_AddItem($hListView,"",$i)
_GUICtrlListView_AddSubItem($hListView,$i, "[" & $i & "]",$j)
_GUICtrlListView_AddSubItem($hListView,$i,$Value,$j + 1)
Else
_GUICtrlListView_AddSubItem($hListView,$i,$Value,$j + 1)
EndIf
Next
Next
GUISetState()
Do
$msg = GUIGetMsg()
If $msg = $CopyButton Then
$selectionmark = _GUICtrlListView_GetSelectionMark($hListView)
ClipPut(_GUICtrlListView_GetItemTextString($hListView,$selectionmark))
EndIf
Until $msg = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc

 

SpeedTest_1D.au3

#include <Array.au3>
#include "CArray.au3"

$hTimer1 = TimerInit()
Dim $nArray[1]
For $i = 1 To 10000
ReDim $nArray[$i]
Next
$fDiff1 = TimerDiff($hTimer1)

$hTimer2 = TimerInit()
$vArray1D = CArray1D(1)
For $i = 1 To 10000
ReDim1D($vArray1D,$i)
Next
$fDiff2 = TimerDiff($hTimer2)

MsgBox(0,"ReDim Time","Autoit Array ==> " & $fDiff1 & @CRLF & "CArray ==> " & $fDiff2)

$hTimer1 = TimerInit()
Dim $nArray[1]
For $i = 1 To 1000
_ArrayAdd ($nArray,$i)
Next
$fDiff1 = TimerDiff($hTimer1)

$hTimer2 = TimerInit()
$vArray1D = CArray1D(1)
For $i = 1 To 1000
Add1D($vArray1D,$i)
Next
$fDiff2 = TimerDiff($hTimer2)

MsgBox(0,"Add Time","Autoit Array ==> " & $fDiff1 & @CRLF & "CArray ==> " & $fDiff2)

$hTimer1 = TimerInit()
Dim $nArray[1000]
For $i = 1 To 500
_ArrayDelete($nArray,$i - 1)
Next
$fDiff1 = TimerDiff($hTimer1)

$hTimer2 = TimerInit()
$vArray1D = CArray1D(1000)
For $i = 1 To 500
DeleteAt1D($vArray1D,$i - 1)
Next
$fDiff2 = TimerDiff($hTimer2)

MsgBox(0,"Delete Time","Autoit Array ==> " & $fDiff1 & @CRLF & "CArray ==> " & $fDiff2)

SpeedTest_2D.au3

#include <Array.au3>
#include "CArray.au3"

$hTimer1 = TimerInit()
Dim $nArray[1][1] , $Max = 0
For $i = 1 To 100
For $j = 1 To 100
if $Max < $j Then
ReDim $nArray[$i][$j]
$Max += 1
Else
ReDim $nArray[$i][$Max]
EndIf
Next
Next
$fDiff1 = TimerDiff($hTimer1)

$hTimer2 = TimerInit()
$Max = 0
$vArray2D = CArray2D(1,1)
For $i = 1 To 100
For $j = 1 To 100
if $Max < $j Then
ReDim2D($vArray2D,$i,$j)
$Max += 1
Else
ReDim2D($vArray2D,$i,$Max)
EndIf
Next
Next
$fDiff2 = TimerDiff($hTimer2)

MsgBox(0,"ReDim Time","Autoit Array ==> " & $fDiff1 & @CRLF & "CArray ==> " & $fDiff2)

$hTimer1 = TimerInit()
Dim $nArray[1][1] , $Max = 0
For $i = 1 To 50
For $j = 1 To 50
if $Max < $j Then
ReDim $nArray[$i][$j]
$Max += 1
Else
ReDim $nArray[$i][$Max]
EndIf
$nArray[$i - 1][$j - 1] = $i * $j
Next
Next
$fDiff1 = TimerDiff($hTimer1)

$hTimer2 = TimerInit()
$vArray2D = CArray2D(1,1)
For $i = 1 To 50
For $j = 1 To 50
SetWithReDim2D($vArray2D,$i - 1,$j - 1,$i * $j)
Next
Next
$fDiff2 = TimerDiff($hTimer2)

MsgBox(0,"SetWithReDim2D Time","Autoit Array ==> " & $fDiff1 & @CRLF & "CArray ==> " & $fDiff2)

 

Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



Could you please add a few lines of description so people know what this is all about?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

:huh2:

Share this post


Link to post
Share on other sites
12 hours ago, water said:

Could you please add a few lines of description so people know what this is all about?

Thank you .


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
11 hours ago, dmob said:

:huh2:

Thank you  :)


صرح السماء كان هنا

 

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