This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Accepted = namedtuple('Accepted', ['n', 'state']) | |
class Acceptor: | |
def __init__(self, node_id): | |
self.node_id = node_id | |
self.promise = 0 | |
self.accepted = Accepted(0,None) | |
emit_accepted(0, node_id=self.node_id, ts=now(), accepted_n=0, state=self.accepted.state) | |
@synchronized | |
def prepare(self, ballot_n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cas_update(old, new): | |
def change(x): | |
if x!=old: raise Conflict(x) | |
return new | |
return change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Accepted = namedtuple('Accepted', ['n', 'state']) | |
class Acceptor: | |
def __init__(self, node_id, hdd): | |
self.node_id = node_id | |
if hdd.is_empty(): | |
hdd.write(promise=0, accepted=Accepted(0,None)) | |
# emit_* functions are used to record a event and capture a bit of context | |
# The proof is based on reasoning on the structure of the sequence of the event | |
# that the program can generate | |
emit_accepted(0, node_id=self.node_id, ts=now(), accepted_n=0, state=self.hdd.accepted.state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Variable: | |
def __init__(self, nodes, q, node_id): | |
self.proposer = Proposer(nodes, q, node_id) | |
@endpoint | |
def write(self, ver, value, due): | |
def change(previous): | |
if previous == None or previous.ver==ver: | |
return Val(ver = ver+1, value = value) | |
return previous | |
def query(current): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Switch: | |
def __init__(self, nodes, q, node_id): | |
self.proposer = Proposer(nodes, q, node_id) | |
@endpoint | |
def write(self, value, due): | |
def change(previous): | |
return value if previous == None else previous | |
def query(current): | |
if current == value: | |
return current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
def ltot(l): | |
def _ltot(l, i): | |
if len(l)==i: return () | |
return (l[i], _ltot(l, i+1)) | |
return _ltot(l, 0) | |
def symbol(x): | |
def parser(txt): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Queue import Queue | |
from threading import Thread | |
from time import sleep | |
# main queues | |
tasks = Queue() | |
results = Queue() | |
# auxiliary queues & workers #################################################### | |
preresults = Queue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="canvas"></div> | |
<script type="text/javascript"> | |
var canvas = document.getElementById("canvas"); | |
var input = document.createElement("input"); | |
input.type = "textbox"; | |
input.value = "click here and then on address"; | |
input.style.cssText += ";width:200px;" | |
input.addEventListener("blur", function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proposer: | |
def __init__(self, nodes, q, node_id): | |
self.q = q | |
self.nodes = nodes | |
self.node_id = node_id | |
# generates a new ballot number which is greater than v | |
def get_n(self, v): | |
# ... | |
@endpoint | |
def change_query(self, change, query, due): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(xs, b, e, x): | |
if b==e: | |
return b if xs[b] == x else -1 | |
m = (b+e)/2 | |
# [x_b .. x_m x_{m+1} .. x_e] | |
# x_b <= x_m and x_{m+1} <= x_e # normal, normal | |
if xs[b] <= xs[m] and xs[m+1] <= xs[e]: | |
if xs[b] <= x <= xs[m]: | |
return search(xs, b, m, x) | |
if xs[m+1] <= x <= xs[e]: |