Skip to content

Commit

Permalink
Fix packing rules and rulebooks in slow deltas
Browse files Browse the repository at this point in the history
And test it
  • Loading branch information
clayote committed Aug 31, 2024
1 parent 18087db commit fbeee3b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
40 changes: 38 additions & 2 deletions LiSE/LiSE/handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ def _concat_char_delta(delta: SlightlyPackedDeltaType) -> bytes:
universal = delta.pop(UNIVERSAL, None)
if universal:
mostly_packed_delta[UNIVERSAL] = universal
if RULEBOOK in delta:
mostly_packed_delta[RULEBOOK] = delta.pop(RULEBOOK)
rules = delta.pop(RULES, {})
for char, chardelta in delta.items():
if chardelta.get(b"\xa4name") == b"\xc0":
mostly_packed_delta[char] = b"\xc0"
Expand Down Expand Up @@ -289,9 +292,10 @@ def _concat_char_delta(delta: SlightlyPackedDeltaType) -> bytes:
charn: (concat_d(stuff) if stuff != b"\xc0" else b"\xc0")
for charn, stuff in mostly_packed_delta.items()
}
rules = delta.pop(RULES, None)
if rules:
almost_entirely_packed_delta[RULES] = concat_d(rules)
almost_entirely_packed_delta[RULES] = concat_d(
{rule: concat_d(funcls) for (rule, funcls) in rules.items()}
)
return concat_d(almost_entirely_packed_delta)

@prepacked
Expand Down Expand Up @@ -412,6 +416,38 @@ def _get_slow_delta(
ids_to.append(id(vb))
values_from.append(va)
values_to.append(vb)
for rulebook in kf_from["rulebook"].keys() | kf_to["rulebook"].keys():
va = kf_from["rulebook"].get(rulebook, ())
vb = kf_to["rulebook"].get(rulebook, ())
keys.append(("rulebook", rulebook))
ids_from.append(id(va))
ids_to.append(id(vb))
values_from.append(va)
values_to.append(vb)
for rule in kf_from["triggers"].keys() | kf_to["triggers"].keys():
va = kf_from["triggers"].get(rule, ())
vb = kf_to["triggers"].get(rule, ())
keys.append(("triggers", rule))
ids_from.append(id(va))
ids_to.append(id(vb))
values_from.append(va)
values_to.append(vb)
for rule in kf_from["prereqs"].keys() | kf_to["prereqs"].keys():
va = kf_from["prereqs"].get(rule, ())
vb = kf_to["prereqs"].get(rule, ())
keys.append(("prereqs", rule))
ids_from.append(id(va))
ids_to.append(id(vb))
values_from.append(va)
values_to.append(vb)
for rule in kf_from["actions"].keys() | kf_to["actions"].keys():
va = kf_from["actions"].get(rule, ())
vb = kf_to["actions"].get(rule, ())
keys.append(("actions", rule))
ids_from.append(id(va))
ids_to.append(id(vb))
values_from.append(va)
values_to.append(vb)
values_changed = np.array(ids_from) != np.array(ids_to)

def pack_one(k, va, vb, deleted_nodes, deleted_edges):
Expand Down
44 changes: 31 additions & 13 deletions LiSE/LiSE/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
}

KF_FROM = {
"rulebooks": {"somerules": ["onerule", "anotherrule"]},
"rulebook": {"somerules": ["onerule", "anotherrule"]},
"triggers": {"onerule": ["foo", "bar"], "anotherrule": ["bar", "bas"]},
"prereqs": {"onerule": ["qux", "quux"], "anotherrule": ["quux", "quuux"]},
"actions": {
Expand Down Expand Up @@ -10122,16 +10122,12 @@
("physical", (24, 23), (24, 22), 0): {},
("physical", (24, 24), (24, 23), 0): {},
},
"triggers": {},
"prereqs": {},
"actions": {},
"rulebook": {},
}

BTT_FROM = ("trunk1", 7, 421)

KF_TO = {
"rulebooks": {"somerules": ["anotherrule", "thirdrule"]},
"rulebook": {"somerules": ["anotherrule", "thirdrule"]},
"triggers": {"onerule": ["foo"], "anotherrule": ["bar", "bas", "foo"]},
"prereqs": {"onerule": ["qux", "quux", "quuux"], "anotherrule": ["quux"]},
"actions": {
Expand Down Expand Up @@ -21325,14 +21321,7 @@
("physical", (24, 24), (23, 24), 0): {},
("physical", (24, 24), (24, 23), 0): {},
},
"triggers": {},
"prereqs": {},
"actions": {},
"rulebook": {},
}

BTT_TO = ("trunk", 15, 186)

SLOW_DELTA = {
"physical": {
"nodes": {(0, 0): False, "sheep8": True},
Expand Down Expand Up @@ -22596,4 +22585,33 @@
}
}
},
"rulebook": {"somerules": ("anotherrule", "thirdrule")},
"rules": {
"anotherrule": {
"actions": (
"ham",
"baked beans",
"spam",
"spam",
"spam",
),
"prereqs": ("quux",),
"triggers": (
"bar",
"bas",
"foo",
),
},
"onerule": {
"actions": ("eggs",),
"prereqs": (
"qux",
"quux",
"quuux",
),
"triggers": ("foo",),
},
},
}

BTT_TO = ("trunk", 15, 186)

0 comments on commit fbeee3b

Please sign in to comment.