Skip to content

Commit

Permalink
Ensure new tree creation passes sizes uniformly.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Mar 17, 2014
1 parent 3875e38 commit c5596c8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions BTrees/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,12 @@ def _grow(self, child, index):
if len(self._data) > max_size * 2:
self._split_root()

def _new_tree(self):
return self.__class__(max_btree_size=self._max_btree_size,
max_bucket_size=self._max_bucket_size)

def _split_root(self):
child = self.__class__()
child = self._new_tree()
child._data = self._data
child._firstbucket = self._firstbucket
self._data = [_TreeItem(None, child)]
Expand All @@ -910,8 +914,7 @@ def _split(self, index=None):
if index is None:
index = len(data) // 2

next = self.__class__(max_btree_size=self._max_btree_size,
max_bucket_size=self._max_bucket_size)
next = self._new_tree()
next._data[:] = data[index:]
first = data[index]
del data[index:]
Expand Down

0 comments on commit c5596c8

Please sign in to comment.