Demonstrate full API compatibility.
()
| 101 | |
| 102 | |
| 103 | def 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 | |
| 154 | def demo_performance_benefits(): |