Skip to content

Commit f5fa7b3

Browse files
FIX: dictionnary merging simplified (#136)
1 parent 6af7b98 commit f5fa7b3

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

src/gh/diffCheck/diffCheck/df_util.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,33 +170,16 @@ def merge_shared_indexes(original_dict):
170170
:param original_dict: the dictionary to merge
171171
:return: the merged dictionary
172172
"""
173-
merged_dict = {}
174-
index_to_key = {}
173+
new_dict = {}
175174

176175
for key, (face, indexes) in original_dict.items():
177-
merged_indexes = set(indexes)
178-
keys_to_merge = set()
179-
180-
for index in indexes:
181-
if index in index_to_key:
182-
keys_to_merge.add(index_to_key[index])
183-
184-
for merge_key in keys_to_merge:
185-
merged_indexes.update(merged_dict[merge_key][1])
186-
# del merged_dict[merge_key]
187-
188-
for index in merged_indexes:
189-
index_to_key[index] = key
190-
191-
merged_dict[key] = (face, list(merged_indexes))
192-
193-
keys_with_duplicates = {}
194-
195-
for key in merged_dict.keys():
196-
for other_key, (face, indexes) in merged_dict.items():
197-
if key in indexes:
198-
if key not in keys_with_duplicates:
199-
keys_with_duplicates[key] = []
200-
keys_with_duplicates[key].append(other_key)
201-
202-
return merged_dict
176+
intersection_found = False
177+
for other_key, (other_face, other_indexes) in original_dict.items():
178+
if key != other_key:
179+
if set(indexes).intersection(set(other_indexes)):
180+
new_dict[key] = (face, list(set(indexes).union(set(other_indexes))))
181+
intersection_found = True
182+
if not intersection_found:
183+
new_dict[key] = (face, indexes)
184+
185+
return new_dict

0 commit comments

Comments
 (0)