Skip to content

Commit

Permalink
LoggableDict to track changes in sim variables
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsekar committed Apr 6, 2022
1 parent 89feaa6 commit 0b1a1cd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions wc_rules/utils/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Tuple, Dict
from backports.cached_property import cached_property
from collections import defaultdict, UserDict
from sortedcontainers import SortedSet

class SimpleMapping(UserDict):

Expand Down Expand Up @@ -382,3 +383,17 @@ def __init__(self,elems):
def __contains__(self,x):
return x not in self._exclude

class LoggableDict(UserDict):

def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.modified = SortedSet()

def set(self,key,value):
self.modified.add(key)
UserDict.__setitem__(self,key,value)
return self

def flush(self):
self.modified = SortedSet()

0 comments on commit 0b1a1cd

Please sign in to comment.