Implemented lfsr_btree_update and added more tests

This was a rather simple exercise. lfsr_btree_commit does most of the
work already, so all this needed was setting up the pending attributes
correctly.

Also:
- Tweaked dbgrbyd.py's tree rendering to match dbgbtree.py's.
- Added a print to each B-tree test to help find the resulting B-tree
  when debugging.
This commit is contained in:
Christopher Haster
2023-03-11 16:39:41 -06:00
parent eb6b5332a0
commit a897b875d3
4 changed files with 543 additions and 640 deletions
+5 -5
View File
@@ -345,12 +345,12 @@ def main(disk, block_size=None, trunk=0, limit=None, *,
branches_.append('+')
elif i+1 < len(t_branches):
if (id-(w-1) == t_branches[i+1][0]
and t_branches[i+1][0] == t_branches[i][0]
and t_branches[i][0] == t_branches[i+1][0]
and (not args.get('inner')
or (i == 0 and d == 0))):
branches_.append('+-')
elif (id-(w-1) == t_branches[i+1][0]
and t_branches[i+1][1]-1 == t_branches[i][1]-1
and t_branches[i][1] == t_branches[i+1][1]
and (not args.get('inner') or d == i)):
branches_.append('\'-')
elif (id-(w-1) == t_branches[i+1][0]
@@ -358,7 +358,7 @@ def main(disk, block_size=None, trunk=0, limit=None, *,
branches_.append('|-')
elif (id-(w-1) >= t_branches[i][0]
and id-(w-1) < t_branches[i][1]
and t_branches[i+1][1]-1 != t_branches[i][1]-1):
and t_branches[i][1] != t_branches[i+1][1]):
branches_.append('| ')
else:
branches_.append(' ')
@@ -366,9 +366,9 @@ def main(disk, block_size=None, trunk=0, limit=None, *,
if (id-(w-1) == t_branches[i][0]
and (not args.get('inner') or i == 0)):
branches_.append('+-%s> ' % ('-'*2*(t_depth-i-1)))
elif id-(w-1) == t_branches[i][1]-1:
elif id == t_branches[i][1]-1:
branches_.append('\'-%s> ' % ('-'*2*(t_depth-i-1)))
elif (id-(w-1) >= t_branches[i][0]
elif (id >= t_branches[i][0]
and id-(w-1) < t_branches[i][1]):
branches_.append('|-%s> ' % ('-'*2*(t_depth-i-1)))
+6 -3
View File
@@ -486,6 +486,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
return done, tag_, id_, w_, j, delta, jump, path
# precompute tree
tree_width = 0
if args.get('tree'):
tags = []
paths = {}
@@ -510,6 +511,8 @@ def show_tree(block_size, data, rev, trunk, weight, *,
# also find the maximum depth
depth = max((x+1 for _, _, x in paths.keys()), default=0)
if depth > 0:
tree_width = 2*depth + 2
def treerepr(j):
if depth == 0:
@@ -571,7 +574,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
seen = c
if seen and x == depth-1:
path.append('%s>%s' % (c_start(seen), c_stop(seen)))
path.append('%s->%s' % (c_start(seen), c_stop(seen)))
elif seen:
path.append('%s-%s' % (c_start(seen), c_stop(seen)))
else:
@@ -583,7 +586,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
w_width = 2*m.ceil(m.log10(max(1, weight)+1))+1
print('%-8s %*s%-*s %-22s %s' % (
'off',
2*depth+1 if args.get('tree') and depth > 0 else 0, '',
tree_width, '',
w_width, 'ids',
'tag',
'data (truncated)'
@@ -614,7 +617,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
if args.get('device'):
print('%8s %*s%*s %s' % (
'',
2*depth+1 if args.get('tree') and depth > 0 else 0, '',
tree_width, '',
w_width, '',
'%-22s%s' % (
'%04x %08x %07x' % (tag, 0xffffffff & id, size),