server.trie_server module¶
- class server.trie_server.AutoSaver(interval: int = 60)¶
Bases:
threading.ThreadA class to automatically save the state of the trie and words stored in it
- Attributes:
interval: The amount of time between triggers ev: An event object to wait on
- run()¶
Starts the saving loop once the thread is initialized
- class server.trie_server.ClientHandler(conn: socket.socket, add, packet: tuple)¶
Bases:
objectA class to encapsulate individual clients and their requests into the queue
- Attributes:
conn: A socket that represents the connection to the client that made the request add: The address of the client that made the request packet: The tuple that represents the client’s request
- execute() None¶
Executes the packet this handler was instantiated with
- server.trie_server.add_to_trie(word: str)¶
Adds the given word to the trie
- Args:
word (str): The word that should be added to the trie
- server.trie_server.autocomplete(prefix: str)¶
Autocompletes from the given prefix given the words in the trie
- Args:
prefix (str): The prefix to search the trie with
- Returns:
Any: Either a boolean that states there were no matches for the prefix or a list of matches
- server.trie_server.delete_all_trie()¶
Deletes all values from the trie
- server.trie_server.delete_from_trie(word: str) bool¶
Sends a TCP request to the server with a packet containing the desired operation and value to be added
- Args:
word (str): The word that should be attempted to be deleted
- Returns:
bool: Whether or not the deletion was successful (failing the delete means it wasn’t a word that existed in the trie)
- server.trie_server.find_words(starting_lv: dict, prefix: str, letters: str = '') list¶
Finds all the words that branch off from a starting level
- Args:
starting_lv (dict): The level to perform the search on prefix (str): The string of characters that you start the search with letters (str): The string of characters that are assembled from the starting point to the current point in the trie (current point meaning the level that this recursive method is at)
- Returns:
list: A list that contains all words formed from the given level
- server.trie_server.full_send(conn: socket.socket, data_: bytes) None¶
- server.trie_server.get_final_level() dict¶
Gets a node that represents the last character of a word
- Returns:
dict: A dictionary representing an empty node that also marks the end of a word
- server.trie_server.get_new_level() dict¶
Gets a new node that contains a flag for its size
- Returns:
dict: A dictionary representing an empty node
- server.trie_server.pop_layer_safe(lv: dict, pop_key: str)¶
Pops a child from a layer ‘safely’ in that it maintains the node’s size
- Args:
lv (dict): The node to pop a child from pop_key (str): The key to the child that should be popped
- server.trie_server.queue_reader(queue: queue.Queue) None¶
Constantly reads from the queue
- Args:
queue (Queue): The queue to be read from
- server.trie_server.recursive_delete(lv: dict, word: str, length: int, i: int) tuple¶
Recursively iterates the trie and deletes the necessary nodes to delete the given word
- Args:
lv (dict): The node that is being recursively called to word (str): The word that is looking to be deleted length (int): The length of the word in order to make operations much more efficient i (int): The index of the word being accessed on this call
- Returns:
tuple: A tuple of booleans with the first being whether or not the node should be popped and the second being whether or not the word was found in the trie
- server.trie_server.search_trie(word: str) bool¶
Searches the trie for a given word and returns whether or not it was something that was put into the trie
- Args:
word (str): The word to look for in the trie
- Returns:
bool: Whether or not the given word was found to be placed into the trie