I am learning python and I came across a code (*) that uses Hash and UUID for storing data in python.
Below is a simpler excerpt for the topic in question.
Basically, when data is passed to DataBase, it hashes data, creates uuid,
then holds them as ._data: {uuid, data} and ._index: {hash value, uuid}.
What are the benefits of using Hash and UUID from the perspective of DBMS? (as opposed to just simply storing them in python built-in classes, like List and Dictionary)
from typing import Dict
import uuid
class DataBase:
def __init__(self) -> None:
self._data: Dict[uuid.UUID, Dict] = {}
self._index: Dict[int, uuid.UUID] = {}
def insert(self,
data: Dict[str, int]) -> None:
keyhash = hash(tuple(data))
_id = uuid.uuid4()
self._data[_id] = data
self._index[keyhash] = _id
db = DataBase()
db.insert(data={'priceA': 5000})
db.insert(data={'priceB': 4000})
...
(*) The original code is an API client that constantly receives data asynchronously via multiple Websocket streaming, and read, update, insert, delete them in their defined Database.