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

Function demo_sorteddict_migration

python/examples/migration_guide.py:67–100  ·  view source on GitHub ↗

Show migration from SortedDict to BPlusTree.

()

Source from the content-addressed store, hash-verified

65
66
67def demo_sorteddict_migration():
68 """Show migration from SortedDict to BPlusTree."""
69 print("\n=== Migrating from SortedDict to BPlusTree ===\n")
70
71 try:
72 from sortedcontainers import SortedDict
73
74 print("BEFORE (using SortedDict):")
75 print("```python")
76 print("from sortedcontainers import SortedDict")
77 print("data = SortedDict()")
78 print("# ... same operations ...")
79 print("```")
80
81 # SortedDict example
82 sorted_data = SortedDict()
83 sorted_data.update({5: "five", 1: "one", 3: "three"})
84 print(f"SortedDict: {list(sorted_data.items())}")
85
86 except ImportError:
87 print("SortedDict not available, showing conceptual migration:")
88
89 print("\nAFTER (using BPlusTree):")
90 print("```python")
91 print("from bplustree import BPlusTreeMap")
92 print("data = BPlusTreeMap(capacity=64) # Optional: tune for performance")
93 print("# ... same operations ...")
94 print("```")
95
96 # BPlusTree equivalent
97 bplus_data = BPlusTreeMap(capacity=64)
98 bplus_data.update({5: "five", 1: "one", 3: "three"})
99 print(f"BPlusTree: {list(bplus_data.items())}")
100 print("✓ Same sorted behavior, potentially better performance!")
101
102
103def demo_api_compatibility():

Callers 1

mainFunction · 0.85

Calls 3

updateMethod · 0.95
itemsMethod · 0.95
BPlusTreeMapClass · 0.90

Tested by

no test coverage detected