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)
| 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.""" |
no test coverage detected