MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / demo_dict_migration

Function demo_dict_migration

python/examples/migration_guide.py:19–64  ·  view source on GitHub ↗

Show how to migrate from regular dict to BPlusTree.

()

Source from the content-addressed store, hash-verified

17
18
19def demo_dict_migration():
20 """Show how to migrate from regular dict to BPlusTree."""
21 print("=== Migrating from dict to BPlusTree ===\n")
22
23 print("BEFORE (using dict):")
24 print("```python")
25 print("# Original dict-based code")
26 print("data = {}")
27 print("data[1] = 'apple'")
28 print("data[3] = 'cherry'")
29 print("data[2] = 'banana'")
30 print("print(f'Length: {len(data)}')")
31 print("print(f'Value: {data[2]}')")
32 print("print(f'Keys: {list(data.keys())}')")
33 print("```")
34
35 # Original dict code
36 data = {}
37 data[1] = "apple"
38 data[3] = "cherry"
39 data[2] = "banana"
40 print(
41 f"Dict output - Length: {len(data)}, Value: {data[2]}, Keys: {list(data.keys())}"
42 )
43
44 print("\nAFTER (using BPlusTree):")
45 print("```python")
46 print("# Migrated to BPlusTree - MINIMAL CHANGES!")
47 print("data = BPlusTreeMap() # Only change: constructor")
48 print("data[1] = 'apple' # Same syntax")
49 print("data[3] = 'cherry' # Same syntax")
50 print("data[2] = 'banana' # Same syntax")
51 print("print(f'Length: {len(data)}')")
52 print("print(f'Value: {data[2]}')")
53 print("print(f'Keys: {list(data.keys())}')")
54 print("```")
55
56 # BPlusTree equivalent
57 data = BPlusTreeMap()
58 data[1] = "apple"
59 data[3] = "cherry"
60 data[2] = "banana"
61 print(
62 f"BPlusTree output - Length: {len(data)}, Value: {data[2]}, Keys: {list(data.keys())}"
63 )
64 print("✓ Keys are now automatically sorted!")
65
66
67def demo_sorteddict_migration():

Callers 1

mainFunction · 0.85

Calls 2

keysMethod · 0.95
BPlusTreeMapClass · 0.90

Tested by

no test coverage detected