Skip to content

Instantly share code, notes, and snippets.

@rystsov
Last active September 7, 2015 18:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rystsov/a45793daa1662a921479 to your computer and use it in GitHub Desktop.
Accepted = namedtuple('Accepted', ['n', 'val'])
class Variable:
def __init__(self, nodes, q):
self.q = q
self.nodes = nodes
self.promise = 0
self.accepted = Accepted(0,0,None)
@synchronized
def prepare(self, n):
if self.promise.n < n:
self.promise = n
return self.accepted
return Conflict(promise=self.promise)
@synchronized
def accept(self, n, val):
if self.promise == n:
self.accepted = Accepted(n, val)
return OK()
return Conflict(promise=self.promise)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment