Exemple #1
0
    def map_set(self, body, key, value, last_value=None, comments="") -> State:
        """Generates the `map_set` state when a particular key is set for a new
        value.

        Args:
            body : The contents of the map that are to be sent along with the state
            key : The key that has been accessed
            value : The current value being associated with key
            last_value (optional): the last value that the key was associated to.
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``map_set`` state for the respective map mentioned
        """
        state_type = "map_set"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": body.copy(),
            "key": key,
            "value": value,
            "last_value": last_value
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #2
0
    def dllnode_iter(self,
                     value,
                     next_node,
                     prev_node,
                     last_value=None,
                     comments=""):
        """Generates the `dllnode_iter` state when a node is accessed or its
        value is changed.

        Args:
            value : The value stored in the linked list node
            next_node (DoublyLinkedListNode): The next pointer
            prev_node (DoublyLinkedListNode): The prev pointer
            last_value (optional): stores the value in the linked list node before it was changed.
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `dllnode_iter` state
        """
        state_type = "dllnode_iter"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "value": value,
            "next": next_node.name if next_node else "none",
            "prev": prev_node.name if prev_node else "none",
        }
        if last_value is not None:
            state_def["last_value"] = last_value
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #3
0
    def dllnode_next(self,
                     value,
                     next_node,
                     prev_node,
                     last_next,
                     comments=""):
        """Generates the `dllnode_next` state when the next pointer changes.

        Args:
            value : The value stored in the linked list node
            next_node (DoublyLinkedListNode): The next pointer
            prev_node (DoublyLinkedListNode): The prev pointer
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `dllnode_next` state
        """
        state_type = "dllnode_next"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "value": value,
            "next": next_node.name if next_node else "none",
            "prev": prev_node.name if prev_node else "none",
            "last_next": last_next.name if last_next else "none",
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #4
0
    def llnode_iter(self,value,_next,last_value=None,comments=""):
        """Generates the `llnode_iter` state when a node is accessed or its
        value is changed.

        Args:
            value : The value stored in the linkedlist node
            next (LinkedListNode): The next pointer
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `llnode_iter` state
        """
        state_type = "llnode_iter"
        state_def = {
            "id" : self._id,
            "variable_name" : self.name,
            "value" : value,
            "next" : _next.name if _next else "none"
        }
        if not(last_value is None):
            state_def["last_value"] = last_value
        return State(
            state_type=state_type,
            state_def=state_def,
            comments=comments
        )
Exemple #5
0
    def vector_iter(self,
                    body,
                    index,
                    value=None,
                    last_value=None,
                    comments=""):
        """Generates the `vector_iter` state when a particular index of vector
        has been accessed.

        Args:
            body (list): The contents of the vector that are to be sent along with the state
            index (int): The index of vector that has been accessed
            value (optional): The current value at array[index] if __setitem__(self, key, value) was called.
            last_value (optional): The current value at array[index] if __setitem__(self, key, value) was called.
            comments (str,optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``vector_iter`` state for the respective vector mentioned
        """
        state_type = "vector_iter"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "index": index
        }
        if not (last_value is None):
            state_def["value"] = value
            state_def["last_value"] = last_value
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #6
0
    def stack_declare(self, comments=""):
        """Generates the `stack_declare` state when an instance of stack is
        created.

        Args:
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `stack_declare` state for respective stack
        """
        state_type = "stack_declare"
        state_def = {"id": self._id, "variable_name": self.name, "body": []}
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #7
0
    def priorityqueue_declare(self, comments=""):
        """Generates the `priorityqueue_declare` state when an instance of
        PriorityQueue is created.

        Args:
            body: The contents of the PriorityQueue that are to be sent along with the state
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``priorityqueue_declare`` state for the respective PriorityQueue mentioned
        """
        state_type = "priorityqueue_declare"
        state_def = {"id": self._id, "variable_name": self.name, "body": []}
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #8
0
    def dllnode_delete(self, comments=""):
        """Generates the `dllnode_delete` state when a node is deleted.

        Args:
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `dllnode_delete` state
        """
        state_type = "dllnode_delete"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #9
0
    def stack_top(self, body, comments=""):
        """Generates the `stack_push` state when top of stack is accessed.

        Args:
            body (list): contents of stack
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `stack_top` state for respective stack
        """
        state_type = "stack_top"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #10
0
    def queue_front(self, body, comments=""):
        """Generates the `queue_front` state when front of queue is accessed.

        Args:
            body (list): Body of queue
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `queue_front` state for respective queue
        """
        state_type = "queue_front"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #11
0
    def priorityqueue_peek(self, body, comments=""):
        """Generates the `priorityqueue_peek` when first element of priority
        queue is accessed.

        Args:
            body: The contents of the PriorityQueue that are to be sent along with the state
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``priorityqueue_peek`` state for the respective PriorityQueue mentioned
        """
        state_type = "priorityqueue_peek"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #12
0
    def map_declare(self, body, comments="") -> State:
        """Generates the `map_declare` state when an instance of Map class is
        created.

        Args:
            body: The contents of the map that are to be sent along with the state
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``map_declare`` state for the respective map mentioned
        """
        state_type = "map_declare"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": body.copy()
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #13
0
    def vector_declare(self, body, comments=""):
        """Generates the `vector_declare` state when an instance of Vector
        class is created.

        Args:
            body (list): The contents of the vector that are to be sent along with the state
            comments (str,optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``vector_declare`` state for the respective vector mentioned
        """
        state_type = "vector_declare"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body)
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #14
0
    def ll_declare(self,head,comments=""):
        """Generates the `ll_declare` state when a new linkedlist is created.

        Args:
            head (LinkedListNode): The head pointer
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `ll_declare` state
        """
        state_type = "ll_declare"
        state_def = {
            "id" : self._id,
            "variable_name" : self.name,
            "head" : head.name if head else "none"
        }
        return State(
            state_type=state_type,
            state_def=state_def,
            comments=comments
        )
Exemple #15
0
    def stack_push(self, body, element, comments=""):
        """Generates the `stack_push` state when an element is added to stack.

        Args:
            body (list): contents of stack
            element : Element pushed to stack top
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `stack_push` state for respective stack
        """
        state_type = "stack_push"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "element": element
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #16
0
    def queue_push(self, body, element, comments=""):
        """Generates the `queue_push` state when an element is added to queue.

        Args:
            body (list): Body of queue
            element: Element to be added to back of queue
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `queue_push` state for respective queue
        """
        state_type = "queue_push"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "element": element
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #17
0
    def set_remove(self, body, key, comments="") -> State:
        """Generates the `set_remove` state when a particular key is deleted.

        Args:
            body : The contents of the set that are to be sent along with the state
            key : The key that has been deleted
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``set_remove`` state for the respective set mentioned
        """
        state_type = "set_remove"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": body.copy(),
            "key": key,
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #18
0
    def string_append(self, body, element, comments=""):
        """Generates the `string_append` state when another string has been
        appended to this string.

        Args:
            body (str): The original string appended with new string
            element (str): The new string that has been appended
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `string_append` state for respective string
        """
        state_type = "string_append"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": body,
            "element": element,
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #19
0
    def vector_remove(self, body, index, comments=""):
        """Generates the `vector_remove` state when a element at particular
        index of vector is removed.

        Args:
            body (list): The contents of the vector that are to be sent along with the state
            index (int): The index of vector at which the element has to be removed
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``vector_remove`` state for the respective vector mentioned
        """
        state_type = "vector_remove"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "index": index
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #20
0
    def string_iter(self, body, index, comments=""):
        """Generates the `string_iter` state when an character of string has
        been accessed.

        Args:
            body (str): The string
            index (int): The index which has been accessed
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `string_iter` state for respective string
        """
        state_type = "string_iter"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": body,
            "index": index
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #21
0
    def stack_pop(self, body, element, comments=""):
        """Generates the `stack_pop` state when an element is popped from
        stack.

        Args:
            body (list): contents of stack
            comments (str, optional): Comments for descriptive purpose. Defaults to "".
            element : element that was popped from the stack.

        Returns:
            State: Returns the `stack_pop` state for respective stack
        """
        state_type = "stack_pop"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "element": element,
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #22
0
    def queue_pop(self, body, element, comments=""):
        """Generates the `queue_pop` state when an element is removed from
        queue.

        Args:
            body (list): Body of queue
            comments (str, optional): Comments for descriptive purpose. Defaults to "".
            element : element that was popped from the queue.

        Returns:
            State: Returns the `queue_pop` state for respective queue
        """
        state_type = "queue_pop"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "element": element,
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #23
0
    def priorityqueue_poll(self, body, element, comments=""):
        """Generates the `priorityqueue_offer` when an element is popped from
        priority queue.

        Args:
            body: The contents of the PriorityQueue that are to be sent along with the state
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".
            element : the element that was polled from the priorityqueue.

        Returns:
            ARgorithmToolkit.utils.State: returns the ``priorityqueue_poll`` state for the respective PriorityQueue mentioned
        """
        state_type = "priorityqueue_poll"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "element": element,
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #24
0
    def array_swap(self, body, indexes, comments=""):
        """Generates the ``array_swap`` state when values at two indexes of
        array are being swapped.

        Args:
            body: The contents of the array that are to be sent along with the state
            indexes : The indexes that are supposed to be swapped
            comments (optional):The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``array_swap`` state for the respective array mentioned
        """
        state_type = "array_swap"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": body.tolist(),
            "index1": indexes[0],
            "index2": indexes[1]
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #25
0
    def dll_tail(self, head, tail, last_tail=None, comments=""):
        """Generates the `dll_tail` state when linked list tail is changed.

        Args:
            head (DoublyLinkedListNode): The head pointer
            tail (DoublyLinkedListNode): The tail pointer
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `dll_tail` state
        """
        state_type = "dll_tail"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "head": head.name if head else "none",
            "tail": tail.name if tail else "none"
        }
        if not (last_tail is None):
            state_def['last_tail'] = last_tail
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #26
0
    def llnode_declare(self,value,_next,comments=""):
        """Generates the `llnode_declare` state when a new node is created.

        Args:
            value : The value stored in the linkedlist node
            next (LinkedListNode): The next pointer
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `llnode_declare` state
        """
        state_type = "llnode_declare"
        state_def = {
            "id" : self._id,
            "variable_name" : self.name,
            "value" : value,
            "next" : _next.name if _next else "none"
        }
        return State(
            state_type=state_type,
            state_def=state_def,
            comments=comments
        )
Exemple #27
0
    def ll_head(self,head,last_head=None,comments=""):
        """Generates the `ll_head` state when linkedlist head is changed.

        Args:
            head (LinkedListNode): The head pointer
            comments (str, optional): Comments for descriptive purpose. Defaults to "".

        Returns:
            State: Returns the `ll_head` state
        """
        state_type = "ll_head"
        state_def = {
            "id" : self._id,
            "variable_name" : self.name,
            "head" : head.name if head else "none"
        }
        if not (last_head is None):
            state_def["last_head"] = last_head
        return State(
            state_type=state_type,
            state_def=state_def,
            comments=comments
        )
Exemple #28
0
    def vector_compare(self, body, indexes, comments=""):
        """Generates the ``vector_compare`` state when values at two indexes of
        vector are being compared.

        Args:
            body (list): The contents of the vector that are to be sent along with the state
            indexes (tuple): The indexes that are supposed to be compared
            comments (str,optional):The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``vector_compare`` state for the respective vector mentioned
        """
        state_type = "vector_compare"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "body": list(body),
            "index1": indexes[0],
            "index2": indexes[1]
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)
Exemple #29
0
    def set_find(self, body, key, found, comments="") -> State:
        """Generates the `set_find` state when a particular key is searched
        for.

        Args:
            body : The contents of the set that are to be sent along with the state
            key : The key that has been searched
            found : true if found false if not found
            comments (optional): The comments that are supposed to rendered with the state for descriptive purpose. Defaults to "".

        Returns:
            ARgorithmToolkit.utils.State: returns the ``set_find`` state for the respective set mentioned
        """
        state_type = "set_find"
        state_def = {
            "id": self._id,
            "variable_name": self.name,
            "key": key,
            "found": found,
            "body": body.copy()
        }
        return State(state_type=state_type,
                     state_def=state_def,
                     comments=comments)