Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/02/2023 in all areas

  1. I'll give you examples of use. NB: the names of the functions you call do not include an underscord(_). For example for sorting you must call : $myLinkedList.sort() and not $myLinkedList._sort() 1. Creating a Linked List and Inserting Elements: $myList = LinkedList() ; Create a new linked list $myList.insertAtEnd("A") ; Insert "A" at the end of the list $myList.insertAtEnd("B") ; Insert "B" at the end of the list $myList.insertAtEnd("C") ; Insert "C" at the end of the list ; Print the elements of the linked list $myList.printLL() ; Output: A, B, C 2.Inserting at the Beginning: $myList.insertAtBegin("X") ; Insert "X" at the beginning of the list ; Print the elements of the linked list $myList.printLL() ; Output: X, A, B, C 3.Inserting at a Specific Index: $myList.insertAtIndex("Y", 2) ; Insert "Y" at index 2 (0-based) ; Print the elements of the linked list $myList.printLL() ; Output: X, A, Y, B, C 4. Updating a Node at a Specific Index: $myList.updateNode("Z", 1) ; Update the element at index 1 to "Z" ; Print the elements of the linked list $myList.printLL() ; Output: X, Z, Y, B, C 5. Removing Elements: $myList.remove_first_node() ; Remove the first element $myList.remove_last_node() ; Remove the last element $myList.remove_at_index(1) ; Remove the element at index 1 ; Print the elements of the linked list $myList.printLL() ; Output: Z, B 6. Searching for an Element: $position = $myList.search("B") ; Search for "B" If $position <> -1 Then ConsoleWrite("Found at index " & $position & @CRLF) Else ConsoleWrite("Not found" & @CRLF) EndIf 7. Reversing the Linked List: $myList.reverse() ; Reverse the linked list ; Print the reversed linked list $myList.printLL() ; Output: B, Z 8. Iterating Over the Linked List: $iterator = $myList.iterator() While Not $iterator.isDone() $data = $iterator.next() ConsoleWrite("Element: " & $data & @CRLF) WEnd A singly linked list data structure has specific performance characteristics in terms of execution time for various operations. Here is an explanation of the performance for each common operation on a singly linked list: 1. Insertion at the Head (adding an element at the beginning): - Performance: O(1) - Explanation: Inserting at the head of a singly linked list is highly efficient because it only requires modifying a pointer (the head) to point to the new node. There is no need to traverse the entire list. 2. Insertion at the End (appending an element to the end): - Performance: O(n), where n is the number of elements in the list - Explanation: To insert an element at the end, you need to traverse the entire list to reach the last node for the insertion. 3. Insertion at a Specific Index: - Performance: O(n), where n is the insertion index - Explanation: To insert an element at a specific index, you need to traverse the list up to that index to perform the insertion. In the worst case, this may require traversing the entire list. 4. Deletion at the Head (removing the first element): - Performance: O(1) - Explanation: Deletion at the head is an efficient operation because it involves simply modifying the head pointer to exclude the first node. 5. Deletion at the End (removing the last element): - Performance: O(n), where n is the number of elements in the list - Explanation: To delete the last element, you need to traverse the entire list to reach the second-to-last node and then modify its "Next" pointer to exclude the last element. 6. Deletion at a Specific Index: - Performance: O(n), where n is the deletion index - Explanation: To delete an element at a specific index, you need to traverse the list up to that index to perform the deletion. In the worst case, this may require traversing the entire list. 7. Search for an Element by Value: - Performance: O(n), where n is the number of elements in the list - Explanation: To search for an element by value, you need to traverse the list from the beginning until you find the desired element. In the worst case, this may require traversing the entire list. 8. Reversing the List: - Performance: O(n), where n is the number of elements in the list - Explanation: Reversing the list requires traversing all the elements in the list to reverse the "Next" pointers of the nodes. Singly linked lists generally have good performance for head insertion, head deletion, and element access operations. However, operations such as search, tail insertion, tail deletion, and insertion/deletion at a specific index can be less efficient due to the need to traverse the list. For frequent operations involving searching or accessing elements by index, other data structures like arrays may be more efficient.
    2 points
  2. MattyD

    Midi UDF

    Hi all, Attached below are two segments of this project. The first "Midi API" is a wrap of the windows functions below. https://docs.microsoft.com/en-us/windows/win32/multimedia/midi-functions The second "Midi UDF" library is built on the first, and aims to provide a user friendly code base for people working with midi. This UDF so far covers: Channel Voice and Mode Messaging Registered Parameters (Channel Tuning, Mod Wheel/Pitch Bend ranges) Some prolific Non-Registered Parameters. Drum editing Envelope control Vibrato control Filter control General SysEx messaging Roland Data Transfer (DT1/RQ1) Yamaha XG Data Transfer & SysEx Parameter Control Global parameter control (GM2 Reverb & Chorus control) Device Control (Master Volume/Balance/Tuning) Octive/Scale Tuning Controller Destination settings (aftertouch/cc modulation editing) Active Sensing for Output Devices 3D Sound Controllers Midi Show Control - General Commands Importing and exporting midi files (experimental) Recording midi event sequences. (experimental) Midi Machine Control is currently not supported. Thank yous A quick shoutout shoutout to Water and Mr_Creator for the Simple Library Docs Generator - which was the originaly the basis of the helpfiles. Also a double to Water for the advanced help example (f1 key integration with scite). A couple of notes on synths. I've based the UDF on a couple of different RPs published many years apart, so implementation can be quite instrument specific. Don't expect too much of the builtin MS Wavetable Synth! I've had some more joy with the coolsoft midisynth with the choriumRevA soundfont if anyone is looking for a free alternative to test with. The two software synths mentioned above are also very slow responding to midi messages. If you forward messages to a physical instrument you should be able to play in real time. Previous versions: If anyone is after a previous release, they are all available on the sourceforge page. midi.zip
    1 point
  3. Leveraging LinkedList for Efficient Data Management In the development of robust software solutions, the choice of data structure plays a pivotal role in achieving optimal performance and scalability. LinkedList, a dynamic data structure, offers unparalleled flexibility and efficiency in managing collections of data elements. Let's explore how LinkedList enhances the performance and flexibility of our codebase. Efficient Memory Management: LinkedList excels in memory management by dynamically allocating memory for each element at runtime. Unlike static arrays, LinkedList adapts dynamically to accommodate varying numbers of elements, minimizing memory wastage and optimizing resource utilization. Dynamic Insertion and Deletion: One of the key advantages of LinkedList is its ability to efficiently insert and delete elements from anywhere within the list. This dynamic nature enables seamless updates to the snake's body segments and food objects in our application, enhancing its responsiveness and fluidity. Constant-Time Insertions and Deletions: LinkedList offers constant-time insertion and deletion operations, irrespective of the list size. This attribute is particularly advantageous in scenarios where frequent modifications to the data structure are required, such as adding new segments to the snake or removing consumed food items. Iterative Traversal: LinkedList supports efficient traversal through its elements using iterators. This iterative access facilitates smooth navigation through the snake's body segments and food objects, enabling rapid processing of game logic and rendering updates. Flexibility in Data Representation: LinkedList accommodates heterogeneous data types within the same list, allowing for versatile data representation. In our application, this flexibility enables us to store and manage diverse objects, such as snake segments and food items, within a single data structure seamlessly. Conclusion: In summary, LinkedList emerges as a cornerstone of efficient data management in our application, providing dynamic memory allocation, constant-time insertions and deletions, and versatile data representation capabilities. By leveraging LinkedList, we optimize performance, enhance scalability, and lay a solid foundation for the seamless execution of our codebase. The UDF has just been updated: Its performance has been optimized. LinkedList.au3
    1 point
  4. Will have a look, but am currently busy with another project.... thanks for your input!
    1 point
  5. You can send me what you have but I will be able to look over the code just tonight when I get home.
    1 point
  6. to: For $i = 1 To 5 Assign("program" & $i, "Null") Next
    1 point
  7. Thanks - very informative and more or less in line with my opinion of the community given the abundance of UDFs and support freely offered to others on these forums. Whilst I cant guarantee anything at this point, if we do decide to pursue qualification of AutoIt to DO-178 or DO-330 standards I will try to make sure that as much as possible of the library of V&V tests developed for that purpose gets fed back into the AutoIt community for other people to add to over time - hopefully making it easier in future to prove the 'fitness of purpose' for the tool to decision makers and regulatory authorities alike.
    1 point
  8. Your filter returns all types of objects (including OUs) - some of them do not have the specified attributes and hence return an empty line in the array. I suggest to specify the filter in more detail so you only get the objects you are looking for. Example: "(&(objectcategory=person)(objectclass=user)(name=*))" to only get users.
    1 point
  9. Get Subscription Key/Region step: https://portal.azure.com/#home => Translator => Your Instance Name => Endpoints: Click here to view endpoints Standalone script: ;#include <String.au3> ;#include <File.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Global $oErrorHandler = ObjEvent("AutoIt.Error", "__COMErrFunc") ; ============================================================================================================================ ; Require Microsoft Azure Account and Bing Translator Text API Subscription Key ; GET KEY: https://portal.azure.com/#home => Translator => Your Instance Name => Endpoints: Click here to view endpoints Global $sSubscription_Key = '' ;| ENTER YOUR Key 1 HERE ;~ Global $sSubscription_Key_2 = '' ;| ENTER YOUR Key 2 HERE Global $sSubscription_Region = 'eastasia' ; 'global'| ENTER YOUR Subscription Region HERE Global $sSubscription_Region_URL = "https://api.cognitive.microsofttranslator.com/" ; Define the source and target languages Global $slang_From = '' ; "vi" Global $slang_TO = "en" ;Eg 1 Global $vi_Text = "Tôi Yêu Bạn" Global $Text_Translated = _Bing_TranslateText($vi_Text, $slang_From, $slang_TO) ;~ MsgBox(0, 'Bing Translate', "Translate from " & $slang_From & "= " & $vi_Text & @CRLF & "Translated to " & $slang_TO & "= " & $Text_Translated) ; End eg 1 ! ConsoleWrite('! ' & $Text_Translated & @CRLF) ;Eg 2 ; Specify the folder containing the text files ;~ Global $sWorkingDir = @ScriptDir & "\TEST" ;~ Global $sFileTranslated_Prefix = '_translated' ;~ Global $Retun = _Translate_All_TxtFileInDir($sWorkingDir, '*', $slang_From, $slang_TO) ;~ If $Retun Then ;~ If FileExists($sWorkingDir & "\*" & $sFileTranslated_Prefix & ".txt") Then ;~ ; Notify the user that the translation is complete ;~ MsgBox(0, "Translation Complete", "All files in the folder " & $sWorkingDir & @CRLF & "have been translated and saved with the prefix " & $sFileTranslated_Prefix) ;~ Else ;~ MsgBox(48, "Error /!\", "No files translated in the folder: " & $sWorkingDir) ;~ EndIf ;~ Else ;~ MsgBox(16, "Error /!\", "No files in the folder: " & $sWorkingDir) ;~ EndIf ; End eg 2 ! ; ============================================================================================================================ ; Function: Func _Translate_All_TxtFileInDir($sFilePath, $sFilter = "*", $slang_From = 'Auto', $slang_TO = "en", $sFileTranslated_Prefix = '_translated') If Not FileExists($sFilePath) Then Return SetError(1, 0, 0) ; Get an array of all the files in the folder If ($sFilter == "*.*") Or ($sFilter == Default) Or ($sFilter == '') Then $sFilter = "*" $sFilter = $sFilter & ".txt" Local $aListFile, $aFileList = _FileListToArray($sFilePath, $sFilter, 1, 1) If Not IsArray($aFileList) Then Return SetError(1, 0, 0) For $i = 1 To UBound($aFileList) - 1 If Not StringInStr($aFileList[$i], $sFileTranslated_Prefix) Then $aListFile &= '|' & $aFileList[$i] Next $aFileList = StringSplit($aListFile, '|', 2) Local $sFileContent, $translated_text, $hOpen, $sFilePath_translated ; Loop through the array of files For $i = 1 To UBound($aFileList) - 1 ; Read the text file ConsoleWrite("- Reading the file " & $i & ":" & $aFileList[$i] & @CRLF) $sFileContent = FileRead($aFileList[$i]) If (@error) Then ConsoleWrite("An error occurred while reading the text file:" & $aFileList[$i] & @CRLF) ;MsgBox(16, "Error", "An error occurred while reading the text file:" & $aFileList[$i]) ContinueLoop EndIf ; Translate the text ConsoleWrite("- Start translating..." & @CRLF) $translated_text = _Bing_TranslateText($sFileContent, $slang_From, $slang_TO) If (@error) Then ConsoleWrite("! Error: An error occurred while translate text !" & @CRLF) ;MsgBox(16, "Error", "An error occurred while translate text !") ContinueLoop EndIf ; Write the translated text to a new file $sFilePath_translated = StringReplace($aFileList[$i], ".txt", $sFileTranslated_Prefix & ".txt") ConsoleWrite("- Writing the translated text to the file:" & $sFilePath_translated & @CRLF) $hOpen = FileOpen($sFilePath_translated, 2 + 8 + 128) FileWrite($hOpen, $translated_text) If (@error) Then FileClose($hOpen) ConsoleWrite("! Error: An error occurred while writing the translated text to the file:" & $sFilePath_translated & @CRLF) ;MsgBox(16, "Error", "An error occurred while writing the translated text to the file:" & $sFilePath_translated) ContinueLoop EndIf FileClose($hOpen) ConsoleWrite("+ " & $i & " OK !" & @CRLF) $sFileContent = '' $translated_text = '' $sFilePath_translated = '' $hOpen = 0 Next Return 1 EndFunc ;==>_Translate_All_TxtFileInDir ; Function to translate text using Bing Translator API Func _Bing_TranslateText($sContent, $slang_From = 'Auto', $slang_TO = "en") Local $iSubscriptionKey = StringLower(StringStripWS($sSubscription_Key, 8)) If ($iSubscriptionKey == '') Then Exit MsgBox(16, 'Error /!\', "Ocp-Apim-Subscription-Key is Not Enter !") ;Return SetError(1, 0, '') EndIf Local $iSubscriptionRegion = StringLower(StringStripWS($sSubscription_Region, 8)) If ($iSubscriptionRegion == '') Then $iSubscriptionRegion = 'global' If ($iSubscriptionRegion == '') Then Exit MsgBox(16, 'Error /!\', "Ocp-Apim-Subscription-Region is Not Enter !") ;Return SetError(1, 0, '') EndIf Local $iSubscription_RegionURL = StringStripWS($sSubscription_Region_URL, 8) If StringRight($iSubscription_RegionURL, 1) == '/' Then $iSubscription_RegionURL = StringTrimRight($iSubscription_RegionURL, 1) If ($iSubscription_RegionURL == '') Then Exit MsgBox(16, 'Error /!\', "Region URL is Not Enter !") ;Return SetError(1, 0, '') EndIf $slang_From = StringStripWS($slang_From, 8) $slang_TO = StringStripWS($slang_TO, 8) If ($slang_From == '') Then $slang_From = 'Auto' ConsoleWrite("> Translate from language: " & $slang_From & ' [TO> ' & $slang_TO & @CRLF) ConsoleWrite("> //-------------------------- Text:" & @CRLF & $sContent & @CRLF) ConsoleWrite("---------------------------------- \\" & @CRLF) $slang_From = StringLower($slang_From) $slang_TO = StringLower($slang_TO) If ($slang_From == 'auto') Then $slang_From = '' Local $apiURL = $sSubscription_Region_URL & "/translate?api-version=3.0&from=" & $slang_From & "&to=" & $slang_TO Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", $apiURL) $oHTTP.SetRequestHeader("Content-Type", "application/json; charset=UTF-8") $oHTTP.SetRequestHeader("Ocp-Apim-Subscription-Key", $iSubscriptionKey) If ($iSubscriptionRegion <> 'global') Then $oHTTP.SetRequestHeader("Ocp-Apim-Subscription-Region", $iSubscriptionRegion) $oHTTP.Send('[{"Text": "' & $sContent & '"}]') If $oHTTP.Status <> 200 Then ConsoleWrite("! Error: An error occurred while connecting to the Bing Translator API. HTTP status code: " & $oHTTP.Status & " " & $oHTTP.StatusText & @CRLF) ;MsgBox(16, "Error", "An error occurred while connecting to the Bing Translator API. HTTP status code: " & $oHTTP.Status & " " & $oHTTP.StatusText) Return SetError(2, 0, "") EndIf Local $Json_Response = $oHTTP.ResponseText ConsoleWrite("> Microsoft Translator Response: " & $Json_Response & @CRLF) Local $aTranslated = _StringBetween($Json_Response, '"translations":[{"text":"', '","to":"' & $slang_TO & '"}]}') If @error Or (Not IsArray($aTranslated)) Then ConsoleWrite("! Error: An error occurred while decoding the JSON response from the Bing Translator API." & @CRLF) ;MsgBox(16, "Error", "An error occurred while decoding the JSON response from the Bing Translator API.") Return SetError(2, 0, "") EndIf Local $sContent_Translated = $aTranslated[0] $sContent_Translated = StringReplace($sContent_Translated, '\r\n', @CRLF) ConsoleWrite(">//---------------- Translated text :" & @CRLF & $sContent_Translated & @CRLF) ConsoleWrite("---------------------------------- //" & @CRLF) Return SetError(0, 0, $sContent_Translated) EndFunc ;==>_Bing_TranslateText Func __COMErrFunc() ;Keep Script Runing on Obj Error! EndFunc ;==>__COMErrFunc ; ============================================================================================================================ ; Functions on Include: Func _StringBetween($sString, $sStart, $sEnd, $iMode = 0, $bCase = False) $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A" If $iMode <> 1 Then $iMode = 0 If $iMode = 0 Then $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z" Else $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z" EndIf If $bCase = Default Then $bCase = False EndIf Local $aRet = StringRegExp($sString, "(?s" & (Not $bCase ? "i" : "") & ")" & $sStart & "(.*?)" & $sEnd, 3) If @error Then Return SetError(1, 0, 0) Return $aRet EndFunc ;==>_StringBetween Func _FileListToArray($sFilePath, $sFilter = "*", $iFlag = 0, $bReturnPath = False) Local $sDelimiter = "|", $sFileList = "", $sFileName = "", $sFullPath = "" $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+$", "") & "\" If $iFlag = Default Then $iFlag = 0 If $bReturnPath Then $sFullPath = $sFilePath If $sFilter = Default Then $sFilter = "*" If Not FileExists($sFilePath) Then Return SetError(1, 0, 0) If StringRegExp($sFilter, "[\\/:><\|]|(?s)^\s*$") Then Return SetError(2, 0, 0) If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 0, 0) Local $hSearch = FileFindFirstFile($sFilePath & $sFilter) If @error Then Return SetError(4, 0, 0) While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If ($iFlag + @extended = 2) Then ContinueLoop $sFileList &= $sDelimiter & $sFullPath & $sFileName WEnd FileClose($hSearch) If $sFileList = "" Then Return SetError(4, 0, 0) Return StringSplit(StringTrimLeft($sFileList, 1), $sDelimiter) EndFunc ;==>_FileListToArray
    1 point
  10. Inververs, I usually create an invisible label which has the required resizing parameters and then resize the UDF control to fit it in a WM_SIZE message handler: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> $hGUI = GUICreate("test", 400, 400, Default, Default, $WS_SIZEBOX) $cLabel = GUICtrlCreateLabel("", 20, 20, 200, 20) ; Label which will adjust with the GUI GUICtrlSetBkColor($cLabel, 0xFFCCCC) GUICtrlSetResizing($cLabel, $GUI_DOCKRIGHT + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT + $GUI_DOCKTOP) $hCombo = _GUICtrlComboBox_Create($hGUI, "", 20, 20, 200) GUISetState() GUIRegisterMsg($WM_SIZE, "_WM_SIZE") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam) ; Get label posiition and size and adjust child GUI to fit $aPos = ControlGetPos($hGUI, "", $cLabel) WinMove($hCombo, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndFuncIncidentally, you should use normal addition for the resizing parameters, not BitOr as with Windows styles. M23
    1 point
×
×
  • Create New...