@@ -44,46 +44,46 @@ bintrees提供了丰富的API,涵盖了通常的多种应用。下面逐条说
4444- 引用
4545
4646如果按照一般模块的思路,输入下面的命令引入上述模块
47-
47+
4848 >>> import bintrees
49-
49+
5050错了,这是错的,出现如下警告:(×××不可用,用×××)
5151
5252 Warning: FastBinaryTree not available, using Python version BinaryTree.
5353 Warning: FastAVLTree not available, using Python version AVLTree.
5454 Warning: FastRBTree not available, using Python version RBTree.
5555
5656正确的引入方式是:
57-
57+
5858 >>> from bintrees import BinaryTree #只引入了BinartTree
5959 >>> from bintrees import * #三个模块都引入了
60-
60+
6161- 实例化
62-
62+
6363 >>> btree = BinaryTree()
6464 >>> btree
6565 BinaryTree({})
6666 >>> type(btree)
6767 <class 'bintrees.bintree.BinaryTree'>
68-
68+
6969- 逐个增加键值对:.__ setitem__ (k,v) .复杂度O(log(n))(后续说明中,都会有复杂度标示,为了简单,直接标明:O(log(n)).)
70-
70+
7171 >>> btree.__ setitem__ ("Tom","headmaster")
7272 >>> btree
7373 BinaryTree({'Tom': 'headmaster'})
7474 >>> btree.__ setitem__ ("blog","http://blog.csdn.net/qiwsir ")
7575 >>> btree
7676 BinaryTree({'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'} )
77-
77+
7878- 批量添加:.update(E) E是dict/iterable,将E批量更新入btree. O(E* log(n))
79-
79+
8080 >>> adict = [ (2,"phone"),(5,"tea"),(9,"scree"),(7,"computer")]
8181 >>> btree.update(adict)
8282 >>> btree
8383 BinaryTree({2: 'phone', 5: 'tea', 7: 'computer', 9: 'scree', 'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'} )
84-
84+
8585- 查找某个key是否存在:.__ contains__ (k) 如果含有键k,则返回True,否则返回False. O(log(n))
86-
86+
8787 >>> btree
8888 BinaryTree({2: 'phone', 5: 'tea', 7: 'computer', 9: 'scree', 'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'} )
8989 >>> btree.__ contains__ (5)
@@ -94,9 +94,9 @@ bintrees提供了丰富的API,涵盖了通常的多种应用。下面逐条说
9494 False
9595 >>> btree.__ contains__ (1)
9696 False
97-
97+
9898- 根据key删除某个key-value:.__ delitem__ (key), O(log(n))
99-
99+
100100 >>> btree
101101 BinaryTree({2: 'phone', 5: 'tea', 7: 'computer', 9: 'scree', 'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'} )
102102 >>> btree.__ delitem__ (5) #删除key=5的key-value,即:5:'tea' 被删除.
0 commit comments