From 5e7089f3203a69052842cdd152a69dcff605211c Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 9 Jun 2019 14:43:49 +0000 Subject: [PATCH] Find oldest message in supply --- cheuph/element_supply.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cheuph/element_supply.py b/cheuph/element_supply.py index 2818720..85d3da7 100644 --- a/cheuph/element_supply.py +++ b/cheuph/element_supply.py @@ -74,6 +74,14 @@ class ElementSupply(ABC, Generic[E]): pass + @abstractmethod + def oldest_id(self) -> Optional[Id]: + """ + Return the smallest id. + """ + + pass + def root_id(self, elem_id: Id) -> Id: """ Find the root of the tree that an element is contained in. @@ -288,3 +296,10 @@ class InMemorySupply(ElementSupply[E]): return roots[-1] else: return None + + def oldest_id(self) -> Optional[Id]: + ids = self._elements.keys() + if ids: + return min(ids) + else: + return None