Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/25/2024 in all areas

  1. Here is a data structures package designed to offer robust and efficient dynamic collections, suitable for a wide range of programming needs. The included structures are List, LinkedList, DoubleLinkedList, DeQueue, and CircularQueue, each providing specific solutions for data management. 1. List Description: List is a sequential data structure that allows for storing and manipulating collections of ordered elements. It enables efficient operations for accessing, adding, and removing elements, providing a solid foundation for many applications. Usage: Direct and fast access to elements by index. Simple management of data collections. Easy iteration over elements for processing or display. 2. LinkedList Description: LinkedList implements a linked list where each element (node) points to the next. This structure is ideal for scenarios where insertion and deletion operations are frequent, as they are performed in constant time. Usage: Constant-time addition and removal of elements. Flexible management of collections with dynamic sizes. Sequential iteration to traverse elements. 3. DoubleLinkedList Description: DoubleLinkedList is a doubly linked list, with each node having pointers to both the previous and next nodes. This structure allows for efficient bidirectional navigation, facilitating traversal operations in both directions. Usage: Easy bidirectional navigation. Efficient insertion and deletion at both ends. Advanced management of dynamic collections. 4. DeQueue (Double Ended Queue) Description: DeQueue is a double-ended queue that allows adding and removing elements at both the beginning and the end of the queue. It combines the functionalities of stacks (LIFO) and queues (FIFO). Usage: Flexible management of elements at both ends. Applications requiring dynamic access to elements. Scenarios where both LIFO and FIFO operations are needed. 5. CircularQueue Description: CircularQueue is a circular queue where the last element is linked to the first, forming a continuous loop. This structure is particularly useful for applications requiring cyclic access to elements, optimizing space utilization. Usage: Optimal memory space management. Continuous loop processing scenarios. Applications needing a circular queue for repetitive operations. Conclusion This Data Structures package offers powerful and flexible tools for managing data collections, suited to various programming needs. Each structure is designed to maximize the efficiency of data manipulation operations, providing a solid foundation for developing performant and scalable solutions. #include-once #include "DeQueue.au3" ; Create a deque Local $dq = Deque() ; Append elements $dq.append(1) $dq.append(2) $dq.append(3) ; Print the deque representation ConsoleWrite("Deque: " & $dq.__repr__() & @CRLF) ; Output: [1 2 3] ; Append left $dq.appendleft(0) ; Print the deque representation ConsoleWrite("Deque after appendleft: " & $dq.__repr__() & @CRLF) ; Output: [0 1 2 3] ; Pop an element from the right ConsoleWrite("Popped from right: " & $dq.pop() & @CRLF) ; Output: 3 ; Print the deque representation ConsoleWrite("Deque after pop: " & $dq.__repr__() & @CRLF) ; Output: [0 1 2] ; Pop an element from the left ConsoleWrite("Popped from left: " & $dq.popleft() & @CRLF) ; Output: 0 ; Print the deque representation ConsoleWrite("Deque after popleft: " & $dq.__repr__() & @CRLF) ; Output: [1 2] ; Check if the deque is empty If $dq.is_empty() Then ConsoleWrite("Deque is empty" & @CRLF) Else ConsoleWrite("Deque is not empty" & @CRLF) EndIf ; Get the length of the deque ConsoleWrite("Length of deque: " & $dq.__repr__() & @CRLF) ; Output: 2 ; Extend the deque Local $array[3] = [4, 5, 6] $dq.extend($array) ; Print the deque representation ConsoleWrite("Deque after extending: " & $dq.__repr__() & @CRLF) ; Output: [1 2 4 5 6] ; Extend left the deque Local $array2[3]=[-1, -2, -3] $dq.extendleft($array2) ; Print the deque representation ConsoleWrite("Deque after extending left: " & $dq.__repr__() & @CRLF) ; Output: [-3 -2 -1 1 2 4 5 6] #include "CircularQueue.au3" ; Creating a circular queue with a maximum size of 5 Local $cq = CircularQueue(5) ; Enqueue elements ConsoleWrite("Enqueuing elements A, B, C..." & @CRLF) $cq.enqueue("A") $cq.enqueue("B") $cq.enqueue("C") ; Display the size of the circular queue ConsoleWrite("Size of the circular queue: " & $cq.size() & @CRLF) ; Display the first element in the circular queue ConsoleWrite("First element in the circular queue: " & $cq.first() & @CRLF) ; Dequeue an element ConsoleWrite("Dequeuing an element..." & @CRLF) Local $dequeued = $cq.dequeue() ConsoleWrite("Dequeued element: " & $dequeued & @CRLF) ; Display the size of the circular queue again ConsoleWrite("Size of the circular queue after dequeue: " & $cq.size() & @CRLF) ; Enqueue a new element ConsoleWrite("Enqueuing element D..." & @CRLF) $cq.enqueue("D") ; Display the size of the circular queue after enqueue ConsoleWrite("Size of the circular queue after enqueue: " & $cq.size() & @CRLF) ; Display whether the circular queue is empty or not If $cq.is_empty() Then ConsoleWrite("Circular queue is empty" & @CRLF) Else ConsoleWrite("Circular queue is not empty" & @CRLF) EndIf ; Display the first element in the circular queue again after operations ConsoleWrite("First element in the circular queue after operations: " & $cq.first() & @CRLF) DataStructures1.0.1.rar
    2 points
  2. I haven't looked at the URL standard to see what would be exactly correct. In your function, however, the spaces are consistently removed, which leads to failure in the use case here, for example, where you want to pass texts with spaces (except in cases where Google manages to interpret the text without spaces). I have also compared the output of the functions with common URL encoders on the net and Progandy's function corresponds to this completely except for the small difference that it translates spaces as "+" instead of "%20". So you only have to use a StringReplace(_URIEncode($sJson), "+", "%20") and the function returns the correct URL-encoded string, while the output of your function is very different from their result. I think that was Musashi's script rather than mine? That would be a bit of a shame to limit yourself more than is necessary - wouldn't it? You could code in the background during input and dynamically deduce whether the size has been exceeded or not. Btw: DeepL is much better 😉
    1 point
  3. You can probably increase the maximum number of characters if you really use POST instead of a disguised GET. The return limit here seems to be 65,535 characters. As an example: #include "Json.au3" #include <String.au3> ; build long string $sText = _StringRepeat("Wie geht`s? ", 2^16 / 12) ConsoleWrite("string length: " & StringLen($sText) & @CRLF) ; translate the string $sTranslated = _GoogleAPITranslate($sText , "de", "en") ConsoleWrite("return length: " & StringLen($sTranslated) & @CRLF & @CRLF) ConsoleWrite($sTranslated & @CRLF) Func _GoogleAPITranslate($sMytext, $sFrom, $sTo) ; format and send request Local $sResponse With ObjCreate("winhttp.winhttprequest.5.1") .Open("POST", "https://translate.googleapis.com/translate_a/single", False) .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") .Send(StringFormat("client=gtx&sl=%s&tl=%s&dt=t&q=%s", $sFrom, $sTo, _URIEncode($sText))) $sResponse = .ResponseText EndWith Local $vResponse = _JSON_Parse($sResponse) ; process return Local $aData, $sOutput = "" If VarGetType($vResponse) = 'Array' Then $aData = $vResponse[0] If VarGetType($aData) = 'Array' Then For $i = 0 To UBound($aData) -1 $sOutput &= ($aData[$i])[0] Next EndIf EndIf Return $sOutput EndFunc Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode
    1 point
×
×
  • Create New...