Skip to content

Commit ce5ca83

Browse files
Raises ValueError if the requested timestamp is not in the list
1 parent e8334df commit ce5ca83

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pydatastructs/graphs/graph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def add_snapshot(self):
9393
"""Automatically assigns timestamps using system time."""
9494
timestamp = int(time.time()) # Secure real-time timestamp
9595
self.snapshots[timestamp] = copy.deepcopy(self)
96+
def get_snapshot(self, timestamp: int):
97+
"""Retrieves a past version of the graph if the timestamp exists."""
98+
if timestamp not in self.snapshots:
99+
raise ValueError(f"Snapshot for timestamp {timestamp} does not exist. "
100+
f"Available timestamps: {sorted(self.snapshots.keys())}")
101+
102+
return self.snapshots[timestamp]
96103

97104
def is_adjacent(self, node1, node2):
98105
"""

0 commit comments

Comments
 (0)