STAR-322: Fixing printer matching by network key

This commit is contained in:
Daniel Schiavini 2018-12-05 16:02:38 +01:00
parent cd67100097
commit 7e76913736
5 changed files with 97 additions and 64 deletions

View file

@ -0,0 +1,19 @@
from typing import TypeVar, Dict, Tuple, List
T = TypeVar("T")
U = TypeVar("U")
def findChanges(previous: Dict[str, T], received: Dict[str, U]) -> Tuple[List[T], List[U], List[Tuple[T, U]]]:
previous_ids = set(previous)
received_ids = set(received)
removed_ids = previous_ids.difference(received_ids)
new_ids = received_ids.difference(previous_ids)
updated_ids = received_ids.intersection(previous_ids)
removed = [previous[removed_id] for removed_id in removed_ids]
added = [received[new_id] for new_id in new_ids]
updated = [(previous[updated_id], received[updated_id]) for updated_id in updated_ids]
return removed, added, updated