Jump to content

Stack UDF - Based on the concept in .NET.


guinness
 Share

Recommended Posts

On Monday night I had an idea about creating a Stack UDF as I hadn't seen one on the Forums, but then I did a little searching and came across this. Not to be dismayed, I still created my version as I had already planned how I was going to implement it and decrease the number of redims.

 

Enjoy.

Global Const $STACK_GUID = '736DBB18-0DF3-11E4-807A-B46DECBA0006'
Global Enum $STACK_COUNT, $STACK_ID, $STACK_INDEX, $STACK_UBOUND, $STACK_MAX

#Region Example
#include <Array.au3>

Example()

Func Example()
    Local $hStack = Stack() ; Create a stack object.

    For $i = 1 To 20
        If Stack_Push($hStack, 'Example_' & $i) Then ConsoleWrite('Push: ' & 'Example_' & $i & @CRLF) ; Push random data to the stack.
    Next

    For $i = 1 To 15
        ConsoleWrite('Pop: ' & Stack_Pop($hStack) & @CRLF) ; Pop from the stack.
        If Stack_Push($hStack, 'Example_' & $i * 10) Then ConsoleWrite('Push: ' & 'Example_' & $i * 10 & @CRLF) ; Push random data to the stack.
    Next
    ConsoleWrite('Peek: ' & Stack_Peek($hStack) & @CRLF)
    ConsoleWrite('Peek: ' & Stack_Peek($hStack) & @CRLF)

    ConsoleWrite('Count: ' & Stack_Count($hStack) & @CRLF)
    ConsoleWrite('Capacity: ' & Stack_Capacity($hStack) & @CRLF)

    Stack_ForEach($hStack, AppendUnderscore) ; Loop through the stack and pass each item to the custom function.

    ConsoleWrite('Contains Example_150: ' & (Stack_ForEach($hStack, Contains_150) = False) & @CRLF) ; It will return False if found so as to exit the ForEach() loop, hence why False is compared
    ConsoleWrite('Contains Example_1000: ' & (Stack_ForEach($hStack, Contains_1000) = False) & @CRLF) ; It will return False if found so as to exit the ForEach() loop, hence why False is compared

    Local $aStack = Stack_ToArray($hStack) ; Create an array from the stack.
    _ArrayDisplay($aStack)

    Stack_Clear($hStack) ; Clear the stack.
    Stack_TrimExcess($hStack) ; Decrease the memory footprint.
EndFunc   ;==>Example

Func AppendUnderscore(ByRef $vItem)
    $vItem &= '_'
    Return (Random(0, 1, 1) ? True : False) ; Randomise when to return True Or False. The false was break from the ForEach() function.
EndFunc   ;==>AppendUnderscore

Func Contains_150(ByRef $vItem)
    Return ($vItem == 'Example_150' ? False : True) ; If found exit the loop by setting to False.
EndFunc   ;==>Contains_150

Func Contains_1000(ByRef $vItem)
    Return ($vItem == 'Example_1000' ? False : True) ; If found exit the loop by setting to False.
EndFunc   ;==>Contains_1000
#EndRegion Example

; Functions:
; Stack - Create a stack handle.
; Stack_ToArray - Create an array from the stack.
; Stack_Capacity - Retrieve the capacity of the internal stack elements.
; Stack_Clear - Remove all items/objects from the stack.
; Stack_Count - Retrieve the number of items/objects on the stack.
; Stack_ForEach - Loop through the stack and pass each item/object to a custom function for processing.
; Stack_Peek - Peek at the item/object in the stack.
; Stack_Pop - Pop the last item/object from the stack.
; Stack_Push - Push an item/object to the stack.
; Stack_TrimExcess - Set the capacity to the number of items/objects in the stack.

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack
; Description ...: Create a stack handle.
; Syntax ........: Stack([$iInitialSize = Default])
; Parameters ....: $iInitialSize        - [optional] Initialise the stack with a certain size. Useful if you know how large the stack will grow. Default is zero
; Parameters ....: None
; Return values .: Handle that should be passed to all relevant stack functions.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack($iInitialSize = Default)
    Local $aStack = 0
    __Stack($aStack, $iInitialSize, False)
    Return $aStack
EndFunc   ;==>Stack

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_ToArray
; Description ...: Create an array from the stack.
; Syntax ........: Stack_ToArray(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: A zero based array.
;                  Failure: Sets @error to non-zero and returns Null.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_ToArray(ByRef $aStack)
    If __Stack_IsAPI($aStack) And $aStack[$STACK_COUNT] > 0 Then
        Local $aArray[$aStack[$STACK_COUNT]]
        Local $j = $aStack[$STACK_COUNT] - 1
        For $i = $STACK_MAX To $aStack[$STACK_INDEX]
            $aArray[$j] = $aStack[$i]
            $j -= 1
        Next
        Return $aArray
    EndIf
    Return SetError(1, 0, Null)
EndFunc   ;==>Stack_ToArray

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Capacity
; Description ...: Retrieve the capacity of the internal stack elements.
; Syntax ........: Stack_Capacity(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: Capacity of the internal stack.
;                  Failure: None.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_Capacity(ByRef $aStack)
    Return (__Stack_IsAPI($aStack) ? $aStack[$STACK_UBOUND] - $STACK_MAX : 0)
EndFunc   ;==>Stack_Capacity

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Clear
; Description ...: Remove all items/objects from the stack.
; Syntax ........: Stack_Clear(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: True.
;                  Failure: None.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_Clear(ByRef $aStack)
    Return __Stack($aStack, Null, False)
EndFunc   ;==>Stack_Clear

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Count
; Description ...: Retrieve the number of items/objects on the stack.
; Syntax ........: Stack_Count(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: Count of the items/objects on the stack.
;                  Failure: None.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_Count(ByRef $aStack)
    Return (__Stack_IsAPI($aStack) And $aStack[$STACK_COUNT] >= 0 ? $aStack[$STACK_COUNT] : 0)
EndFunc   ;==>Stack_Count

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_ForEach
; Description ...: Loop through the stack and pass each item/object to a custom function for processing.
; Syntax ........: Stack_ForEach(ByRef $aStack, $hFunc)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
;                  $hFunc               - A delegate to a function that has a single ByRef input and a return value of either True (continue looping) or False (exit looping).
; Return values .: Success: Return value of either True or False from the delegate function.
;                  Failure: Null
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_ForEach(ByRef $aStack, $hFunc)
    Local $bReturn = Null
    If __Stack_IsAPI($aStack) And IsFunc($hFunc) Then
        For $i = $STACK_MAX To $aStack[$STACK_INDEX]
            $bReturn = $hFunc($aStack[$i])
            If Not $bReturn Then
                ExitLoop
            EndIf
        Next
    EndIf
    Return $bReturn
EndFunc   ;==>Stack_ForEach

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Peek
; Description ...: Peek at the item/object in the stack.
; Syntax ........: Stack_Peek(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: Item/object in the stack.
;                  Failure: Sets @error to non-zero and returns Null.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_Peek(ByRef $aStack)
    Return __Stack_IsAPI($aStack) And $aStack[$STACK_INDEX] >= $STACK_MAX ? $aStack[$aStack[$STACK_INDEX]] : SetError(1, 0, Null)
EndFunc   ;==>Stack_Peek

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Pop
; Description ...: Pop the last item/object from the stack.
; Syntax ........: Stack_Pop(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: Item/object popped from the stack.
;                  Failure: Sets @error to non-zero and returns Null.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_Pop(ByRef $aStack)
    If __Stack_IsAPI($aStack) And $aStack[$STACK_INDEX] >= $STACK_MAX Then
        $aStack[$STACK_COUNT] -= 1 ; Decrease the count.
        Local $vData = $aStack[$aStack[$STACK_INDEX]] ; Save the stack item/object.
        $aStack[$aStack[$STACK_INDEX]] = Null ; Set to null.
        $aStack[$STACK_INDEX] -= 1 ; Decrease the index by 1.
        ; If ($aStack[$STACK_UBOUND] - $aStack[$STACK_INDEX]) > 15 Then ; If there are too many blank rows then re-size the stack.
        ; __Stack($aStack, Null, True)
        ; EndIf
        Return $vData
    EndIf
    Return SetError(1, 0, Null)
EndFunc   ;==>Stack_Pop

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Push
; Description ...: Push an item/object to the stack.
; Syntax ........: Stack_Push(ByRef $aStack, $vData)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
;                  $vData               - Item/object.
; Return values .: Success: True.
;                  Failure: False.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_Push(ByRef $aStack, $vData)
    Local $bReturn = False
    If __Stack_IsAPI($aStack) Then
        $bReturn = True
        $aStack[$STACK_INDEX] += 1 ; Increase the stack by 1.
        $aStack[$STACK_COUNT] += 1 ; Increase the count.
        If $aStack[$STACK_INDEX] >= $aStack[$STACK_UBOUND] Then ; ReDim the internal stack array if required.
            $aStack[$STACK_UBOUND] = Ceiling(($aStack[$STACK_UBOUND] - $STACK_MAX) * 2) + $STACK_MAX
            ReDim $aStack[$aStack[$STACK_UBOUND]]
        EndIf
        $aStack[$aStack[$STACK_INDEX]] = $vData ; Set the stack element.
    EndIf
    Return $bReturn
EndFunc   ;==>Stack_Push

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_TrimExcess
; Description ...: Set the capacity to the number of items/objects in the stack.
; Syntax ........: Stack_TrimExcess(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: True.
;                  Failure: None.
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func Stack_TrimExcess(ByRef $aStack)
    Return __Stack($aStack, Null, True)
EndFunc   ;==>Stack_TrimExcess

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __Stack
; Description ...:Create a new stack object or re-size a current stack object.
; Syntax ........: __Stack(ByRef $aStack, $iInitialSize, $bIsCopyObjects)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
;                  $iInitialSize        - Initial size value.
;                  $bIsCopyObjects      - Copy the previous stack items/objects.
; Return values .: True
; Author ........: guinness
; ===============================================================================================================================
Func __Stack(ByRef $aStack, $iInitialSize, $bIsCopyObjects)
    Local $iCount = (__Stack_IsAPI($aStack) ? $aStack[$STACK_COUNT] : ((IsInt($iInitialSize) And $iInitialSize > 0) ? $iInitialSize : 0))

    Local $iUBound = $STACK_MAX + (($iCount > 0) ? $iCount : 4) ; STACK_INITIAL_SIZE
    Local $aStack_New[$iUBound]
    $aStack_New[$STACK_INDEX] = $STACK_MAX - 1
    $aStack_New[$STACK_COUNT] = 0
    $aStack_New[$STACK_ID] = $STACK_GUID
    $aStack_New[$STACK_UBOUND] = $iUBound

    If $bIsCopyObjects And $iCount > 0 Then ; If copy the previous objects is true and the count is greater than zero then copy.
        $aStack_New[$STACK_INDEX] = $STACK_MAX - 1 + $iCount
        $aStack_New[$STACK_COUNT] = $iCount

        For $i = $STACK_MAX To $aStack[$STACK_INDEX]
            $aStack_New[$i] = $aStack[$i]
        Next
    EndIf
    $aStack = $aStack_New
    $aStack_New = 0
    Return True
EndFunc   ;==>__Stack

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __Stack_IsAPI
; Description ...: Determine if the variable is a valid stack handle.
; Syntax ........: __Stack_IsAPI(ByRef $aStack)
; Parameters ....: $aStack              - [in/out] Handle returned by Stack().
; Return values .: Success: True.
;                  Failure: False.
; Author ........: guinness
; ===============================================================================================================================
Func __Stack_IsAPI(ByRef $aStack)
    Return UBound($aStack) >= $STACK_MAX And $aStack[$STACK_ID] = $STACK_GUID
EndFunc   ;==>__Stack_IsAPI
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Doh! Now I just realised I could create it with a single 1d array. I will do this later on.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Updated to a 1d array.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Much better! Simple is beatiful.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Mine didn't show up in a search?

(There are a few practices in the code that I've since considered to be incorrect or outdated.)

Edited by jaberwacky
Link to comment
Share on other sites

Now try a queue, there's some extra complications there.

Challenged accepted.

jaberwacky,

I never found your version. Sorry. The difference is mine use native AutoIt.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I will do it on Thursday as now I don't have time.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Added Stack_Clear() to the first post.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Nice job, looking forward to the queue UDF ;)

Wait no longer >> >Queue UDF.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Here a Stack implementation using ActiveXObject "Scripting.Dictionary":

 

;stack (LIFO) implementation using ActiveXObject "Scripting.Dictionary" -> http://msdn.microsoft.com/en-us/library/x4k5wbx4(v=vs.84).aspx
;coded by UEZ (proof of concept version)
#include-once

;function list:
;Stack_Clear
;Stack_Count
;Stack_Init
;Stack_IsEmpty
;Stack_Peek
;Stack_Pop
;Stack_PrintToConsole
;Stack_Push
;Stack_ToArray

Global $__iStackElement = 0
Global $oErrorHandler = ObjEvent("AutoIt.Error", "__Catch_COM_Errors")

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Push
; Description ...: adds an element onto the stack
; Syntax ........: Stack_Push($element, $obj)
; Parameters ....: $element             - any kind of an element
;                  $obj                 - must be the an object returned by Stack_Init()
; Return values .: True
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......:
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_Push($element, $obj)
    $obj.Add($__iStackElement, $element)
    $__iStackElement += 1
    Return True
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Pop
; Description ...: returns the topmost element and removes it from the stack
; Syntax ........: Stack_Pop($obj)
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
; Return values .: topmost element from the stack
;                  on error false and sets error to 1
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......: if stack is empty then error will be set to 1 and 0 returned
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_Pop($obj)
    If Not $__iStackElement Then Return SetError(1, 0, false)
    Local $return = $obj.Item($__iStackElement - 1)
    $obj.Remove($__iStackElement - 1)
    $__iStackElement -= 1
    Return $return
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Peek
; Description ...: returns the topmost element without removing it from the stack
; Syntax ........: Stack_Peek($obj)
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
; Return values .: topmost element from the stack
;                  on error false and sets error to 1
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......: if stack is empty then error will be set to 1 and 0 returned
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_Peek($obj)
    If Not $__iStackElement Then Return SetError(1, 0, false)
    Return $obj.Item($__iStackElement - 1)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_PrintToConsole
; Description ...: prints all stack elements to the console
; Syntax ........: Stack_PrintToConsole($obj)
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
; Return values .: True
;                  on error false and sets error to 1
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......: if stack is empty then error will be set to 1 and 0 returned
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_PrintToConsole($obj)
    If Not $__iStackElement Then Return SetError(1, 0, false)
    Local $i
    For $i = $__iStackElement - 1 To 0 Step - 1
        ConsoleWrite($obj.Item($i) & @CRLF)
    Next
    Return True
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_ToArray
; Description ...: returns an array with all stack elements
; Syntax ........: Stack_ToArray($obj[, $bReverse = True])
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
;                  $bReverse            - [optional] a binary value. Default is True. If true topmost stack element is the 1st
;                                         entry in the array, if false then last element
; Return values .: array with all stack elements
;                  on error false and sets error to 1
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......: if stack is empty then error will be set to 1 and 0 returned
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_ToArray($obj, $bReverse = True)
    If Not $__iStackElement Then Return SetError(1, 0, false)
    Local $a = $obj.Items(), $j = UBound($a) - 1
    If Not $j Then Return $a
    If Not $bReverse Then Return $a
    Local $i, $aRevers[$j + 1]
    For $i = 0 To $j
        $aRevers[$i] = $a[$j - $i]
    Next
    Return $aRevers
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Count
; Description ...: return the amount of stack elements
; Syntax ........: Stack_Count($obj)
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
; Return values .: the amount of stack elements (an integer value)
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......:
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_Count($obj)
    Return $obj.Count()
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_IsEmpty
; Description ...: checks whether stack is empty
; Syntax ........: Stack_IsEmpty($obj)
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
; Return values .: True, if stack is empty, otherwise false
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......:
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_IsEmpty($obj)
    Return $obj.Count() = 0
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Clear
; Description ...: clears all stack elements
; Syntax ........: Stack_Clear($obj)
; Parameters ....: $obj                 - must be the an object returned by Stack_Init()
; Return values .: None
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......:
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_Clear($obj)
    $obj.RemoveAll()
    $__iStackElement = 0
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: Stack_Init
; Description ...: initialize a stack object
; Syntax ........: Stack_Init()
; Parameters ....: None
; Return values .: an dictionary object
;                  on error false and sets error to 1
; Author ........: UEZ
; Version .......: 0.90 build 2014-04-14
; Remarks .......:
; Related .......: data types
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func Stack_Init()
    Local $oDictionary = ObjCreate('Scripting.Dictionary')
    If @error Then Return SetError(1, 0, false)
    Return $oDictionary
EndFunc

;internal functions
Func __Catch_COM_Errors()
    ConsoleWrite( _
            "A COM error has occured!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _
            "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _
            "err.number (hex) is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _
            )
EndFunc

Edit: added function headers

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks UEZ for your contribution.

 

I have added the function Stack_ToArray() in the meantime and changed the way I record the count of the items/objects.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Now the array prints out as it would appear on the stack i.e. last item is at the start of the array.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Is it really necessary to have 3 index of the array to hold information about the stack?

Couldn't it be retrieved by UBound?

When I use _ArrayDisplay() on the stack ($hStack in your example), it shoes me this (Looks like messed up):

[0]|22
[1]|20
[2]|27
[3]|Example_1
[4]|Example_2
[5]|Example_3
[6]|Example_4
[7]|Example_5
[8]|Example_6
[9]|Example_7
[10]|Example_8
[11]|Example_9
[12]|Example_10
[13]|Example_11
[14]|Example_12
[15]|Example_13
[16]|Example_14
[17]|Example_15
[18]|Example_16
[19]|Example_17
[20]|Example_18
[21]|Example_19
[22]|Example_150
[23]|
[24]|
[25]|
[26]|

Also an Stack_IsEmpty() would be nice, some kind of wrapper for (Stack_Count() = 0).

And thanks for Queue UDF, going to try that out right now.

Link to comment
Share on other sites

I created a count element for simplicity more than anything and using UBound() won't work as I re-size the array not by 1, but by 1.5. I could re-add the calculation again by taking the next index - $STACK_MAX, but then I would call Stack_Count() each time I need the count as I want to keep operations simple. What do you want me to do? One less element and multiple calls to Stack_Count() OR as it is now?

What is wrong with that array? Blank elements? Order? You shouldn't be using the stack object as is, that's internal to me only. If you want an array then please use Stack_ToArray().

I also don't feel right adding a wrapper for something as simple as If Not Stack_Count($hStack) Then.

Thanks for testing.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Here is my attempt:

#include-once
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

Func Stack()
    Local $avStack[0]
    Return $avStack
EndFunc

Func Clear(ByRef $avStack)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, False)

    Dim $avStack[0]

    Return SetError(0, 0, True)
EndFunc

Func Count(ByRef $avStack)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, Null)

    Return SetError(0, 0, UBound($avStack))
EndFunc

Func IsEmpty(ByRef $avStack)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, Null)

    Return SetError(0, 0, UBound($avStack) = 0)
EndFunc

Func Peek(ByRef $avStack)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, Null)

    Local $iSize = UBound($avStack)
    If ($iSize = 0) Then Return SetError(2, 0, Null)

    Return SetError(0, 0, $avStack[$iSize - 1])
EndFunc

Func Pop(ByRef $avStack)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, Null)

    Local $iSize = UBound($avStack)
    If ($iSize = 0) Then Return SetError(2, 0, Null)

    Local $vData = $avStack[$iSize - 1]
    ReDim $avStack[$iSize - 1]

    Return SetError(0, 0, $vData)
EndFunc

Func Push(ByRef $avStack, $vData)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, False)

    Local $iSize = UBound($avStack)
    ReDim $avStack[$iSize + 1]
    $avStack[$iSize] = $vData

    Return SetError(0, 0, True)
EndFunc

Func ToArray(ByRef $avStack)
    If (Not IsArray($avStack)) Then Return SetError(1, 0, Null)

    Local $iSize = UBound($avStack)
    If ($iSize = 0) Then Return SetError(2, 0, Null)

    Local $avArray[$iSize], $iReverseCounter = $iSize - 1
    For $iCounter = 0 To $iSize - 1
        $avArray[$iReverseCounter] = $avStack[$iCounter]
        $iReverseCounter -= 1
    Next

    Return SetError(0, 0, $avArray)
EndFunc

I made some benchmarking, yours is 3x faster, this one uses 1/3 ram (7500 push, 5000 pop, 1500 peek).

Personally prefer to use yours.

Edited by D4RKON3
Link to comment
Share on other sites

Personally prefer to use yours.

OK great.

Your version works slightly differently and that's the reason I keep reference of the next index, total count and size of the array.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 2 weeks later...

Added: Stack_TrimExcess()

Changed: The example.

Changed: Stack_Clear() which will destroy the contents but not the size of the stack.

Changed: Variable naming.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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
 Share

  • Recently Browsing   0 members

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