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

Function demo_api_compatibility

python/examples/migration_guide.py:103–151  ·  view source on GitHub ↗

Demonstrate full API compatibility.

()

Source from the content-addressed store, hash-verified

101
102
103def demo_api_compatibility():
104 """Demonstrate full API compatibility."""
105 print("\n=== Complete API Compatibility ===\n")
106
107 print("All standard dict methods work with BPlusTree:")
108
109 tree = BPlusTreeMap(capacity=8)
110
111 print("\n1. Basic operations:")
112 print(" tree[key] = value, tree[key], del tree[key], key in tree")
113 tree[1] = "one"
114 tree[2] = "two"
115 print(f" tree[1] = {tree[1]}")
116 print(f" 1 in tree: {1 in tree}")
117 del tree[1]
118 print(f" After del tree[1]: {1 in tree}")
119
120 print("\n2. Dictionary methods:")
121 print(" get(), pop(), popitem(), setdefault(), update(), copy(), clear()")
122
123 tree.update({3: "three", 4: "four", 5: "five"})
124 print(f" After update: {len(tree)} items")
125
126 value = tree.get(3, "default")
127 print(f" get(3): {value}")
128
129 popped = tree.pop(4)
130 print(f" pop(4): {popped}")
131
132 key, value = tree.popitem()
133 print(f" popitem(): ({key}, {value})")
134
135 result = tree.setdefault(10, "ten")
136 print(f" setdefault(10, 'ten'): {result}")
137
138 copied = tree.copy()
139 print(f" copy(): {len(copied)} items")
140
141 tree.clear()
142 print(f" After clear(): {len(tree)} items")
143 print(f" Copy still has: {len(copied)} items")
144
145 print("\n3. Iteration methods:")
146 print(" keys(), values(), items()")
147
148 tree.update({1: "one", 2: "two", 3: "three"})
149 print(f" keys(): {list(tree.keys())}")
150 print(f" values(): {list(tree.values())}")
151 print(f" items(): {list(tree.items())}")
152
153
154def demo_performance_benefits():

Callers 1

mainFunction · 0.85

Calls 11

updateMethod · 0.95
getMethod · 0.95
popMethod · 0.95
popitemMethod · 0.95
setdefaultMethod · 0.95
copyMethod · 0.95
clearMethod · 0.95
keysMethod · 0.95
valuesMethod · 0.95
itemsMethod · 0.95
BPlusTreeMapClass · 0.90

Tested by

no test coverage detected