Update ordered_multimap.py
Browse files- ordered_multimap.py +7 -2
ordered_multimap.py
CHANGED
@@ -1,6 +1,11 @@
|
|
1 |
from weakref import WeakValueDictionary
|
2 |
from collections import defaultdict
|
3 |
|
|
|
|
|
|
|
|
|
|
|
4 |
class OrderedMultiIndexMapWeakRef:
|
5 |
def __init__(self):
|
6 |
self.data = []
|
@@ -9,9 +14,9 @@ class OrderedMultiIndexMapWeakRef:
|
|
9 |
def insert(self, id, text, title: str = None, sub_title: str = None):
|
10 |
self.data.append(text)
|
11 |
if (title is not None) and (sub_title is not None):
|
12 |
-
self.index_list.append((id, WeakValueDictionary({'title': title, 'sub_title': sub_title})))
|
13 |
elif (title is not None) and (sub_title is None):
|
14 |
-
self.index_list.append((id, WeakValueDictionary({'title': title})))
|
15 |
else:
|
16 |
self.index_list.append(id)
|
17 |
|
|
|
1 |
from weakref import WeakValueDictionary
|
2 |
from collections import defaultdict
|
3 |
|
4 |
+
class StringWrapper:
|
5 |
+
def __init__(self, s):
|
6 |
+
self.s = s
|
7 |
+
|
8 |
+
|
9 |
class OrderedMultiIndexMapWeakRef:
|
10 |
def __init__(self):
|
11 |
self.data = []
|
|
|
14 |
def insert(self, id, text, title: str = None, sub_title: str = None):
|
15 |
self.data.append(text)
|
16 |
if (title is not None) and (sub_title is not None):
|
17 |
+
self.index_list.append((id, WeakValueDictionary({'title': StringWrapper(title), 'sub_title': StringWrapper(sub_title)})))
|
18 |
elif (title is not None) and (sub_title is None):
|
19 |
+
self.index_list.append((id, WeakValueDictionary({'title': StringWrapper(title)})))
|
20 |
else:
|
21 |
self.index_list.append(id)
|
22 |
|