Multipurpose-AI-Agent-Development / ordered_multimap.py
devve1's picture
Update ordered_multimap.py
ae6660f verified
raw
history blame
No virus
737 Bytes
import uuid
from weakref import WeakValueDictionary
from collections import defaultdict
class StringWrapper:
def __init__(self, s):
self.s = s
class OrderedMultiIndexMapWeakRef:
def __init__(self):
self.data = []
self.ids = []
self.index_list = []
def insert(self, id, text, title: str, sub_title: str):
self.data.append(text)
self.ids.append(int(uuid.UUID(id)))
self.index_list.append(WeakValueDictionary({'title': StringWrapper(title), 'sub_title': StringWrapper(sub_title)}))
def all_ids(self):
return self.ids
def all_metadatas(self):
return [dict(d.items()) for d in self.index_list]
def all_texts(self):
return self.data