Skip to content

Commit

Permalink
fix operation based or-set
Browse files Browse the repository at this point in the history
  • Loading branch information
ytsao committed Nov 7, 2024
1 parent 67b80f3 commit bbe30cd
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions operation_based_CRDT/observed_remove_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def __init__(self):

# initial value, after connection, it is going to be either 0 or 1.
self.node_id: int = -1
self.A: Set[Tuple[Tuple[str,int],str]] = set()
self.T: Set[Tuple[Tuple[str,int],str]] = set()
self.AT: Set[Tuple[Tuple[str,int],str]] = set()
self.operation_idx: int = 0

self.start_CRDT: bool = False
Expand All @@ -73,7 +72,7 @@ def __init__(self):

def request_value(self):
# user interface function
self.state_label.setText(f"Current State: {self._eval()}\n A: {self.A}\n T: {self.T}")
self.state_label.setText(f"Current State: {self._eval()}\n AT: {self.AT}")

def operation(self, isAdd: bool):
x: str = ""
Expand Down Expand Up @@ -124,18 +123,17 @@ def _effect(self, message: str):
uid = (int(node_id), int(operation_idx))
x = (uid, x)
if "add" in message:
self.A.add(x)
self.AT.add(x)
elif "remove" in message:
R = set(a for a in self.A if a[1] == x[1])
self.A = self.A - R
self.T = self.T.union(R)
R = set(a for a in self.AT if a[1] == x[1])
self.AT = self.AT - R

def _lookup(self, lookup_value: str):
value = self._eval()
return lookup_value in value

def _eval(self):
return set(a[1] for a in self.A)
return set(a[1] for a in self.AT)

def receive(self):
# receive "state_vector" from another client
Expand Down

0 comments on commit bbe30cd

Please sign in to comment.