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

Method _insert_sorted_optimized

python/bplustree/bplus_tree.py:114–132  ·  view source on GitHub ↗

Optimized insertion for sorted data - avoids repeated tree traversals. Args: key: The key to insert. value: The value to associate with the key.

(self, key: Any, value: Any)

Source from the content-addressed store, hash-verified

112 self._insert_sorted_optimized(key, value)
113
114 def _insert_sorted_optimized(self, key: Any, value: Any) -> None:
115 """Optimized insertion for sorted data - avoids repeated tree traversals.
116
117 Args:
118 key: The key to insert.
119 value: The value to associate with the key.
120 """
121 if (
122 self._rightmost_leaf_cache
123 and self._rightmost_leaf_cache.keys
124 and key > self._rightmost_leaf_cache.keys[-1]
125 and not self._rightmost_leaf_cache.is_full()
126 ):
127 self._rightmost_leaf_cache.keys.append(key)
128 self._rightmost_leaf_cache.values.append(value)
129 return
130
131 self[key] = value
132 self._update_rightmost_leaf_cache()
133
134 def _update_rightmost_leaf_cache(self) -> None:
135 """Update the rightmost leaf cache."""

Callers 1

_bulk_load_sortedMethod · 0.95

Calls 2

is_fullMethod · 0.45

Tested by

no test coverage detected