Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
release v2.0.7
Browse files Browse the repository at this point in the history
BUGFIX: foreach with empty tree raised exception
close issue #3
  • Loading branch information
mozman committed Apr 29, 2017
1 parent 0d13d6d commit 667002a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 2 additions & 3 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
NEWS
====

bintrees development stopped, use `sortedcontainers` instead: https://pypi.python.org/pypi/sortedcontainers

Version 2.0.7 - ...
Version 2.0.7 - 2017-04-28

* BUGFIX: foreach (pure Python implementation) works with empty trees
* acquire GIL for PyMem_Malloc() and PyMem_Free() calls

Version 2.0.6 - 2017-02-04
Expand Down
3 changes: 3 additions & 0 deletions bintrees/abctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ def foreach(self, func, order=0):
parm func: function(key, value)
param int order: inorder = 0, preorder = -1, postorder = +1
"""
if self.count == 0:
return

def _traverse(node):
if order == -1:
func(node.key, node.value)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read(fname):

setup(
name='bintrees',
version='2.0.6',
version='2.0.7',
description='Package provides Binary-, RedBlack- and AVL-Trees in Python and Cython.',
author='mozman',
url='https://github.com/mozman/bintrees.git',
Expand Down
11 changes: 11 additions & 0 deletions tests/test_all_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,17 @@ def test_101_deepcopy_tree_in_tree(self):
self.assertEqual(id(copytree21[5]), id(copytree22[5])) # sublist copied only once?
self.assertEqual(id(copytree21[5]), id(copytree23[5])) # sublist copied only once?

def test_102_deepcopy_empty_tree(self):
tree1 = self.TREE_CLASS()
tree2 = deepcopy(tree1)
self.assertEqual(len(tree2), 0)

def test_103_foreach_with_empty_tree(self):
tree1 = self.TREE_CLASS()
# does not raise any exception
tree1.foreach(lambda k, v: None)
self.assertTrue(True)


class TestBinaryTree(CheckTree, unittest.TestCase):
TREE_CLASS = BinaryTree
Expand Down

0 comments on commit 667002a

Please sign in to comment.