summaryrefslogtreecommitdiff
path: root/chromium/third_party/bintrees
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
commit679147eead574d186ebf3069647b4c23e8ccace6 (patch)
treefc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/third_party/bintrees
downloadqtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz
Initial import.
Diffstat (limited to 'chromium/third_party/bintrees')
-rw-r--r--chromium/third_party/bintrees/LICENSE.txt45
-rw-r--r--chromium/third_party/bintrees/NEWS.txt70
-rw-r--r--chromium/third_party/bintrees/OWNERS2
-rw-r--r--chromium/third_party/bintrees/README.chromium15
-rw-r--r--chromium/third_party/bintrees/README.txt229
-rw-r--r--chromium/third_party/bintrees/bintrees/__init__.py181
-rw-r--r--chromium/third_party/bintrees/bintrees/avltree.py302
-rw-r--r--chromium/third_party/bintrees/bintrees/bintree.py153
-rw-r--r--chromium/third_party/bintrees/bintrees/ctrees.c862
-rw-r--r--chromium/third_party/bintrees/bintrees/ctrees.h51
-rw-r--r--chromium/third_party/bintrees/bintrees/ctrees.pxd38
-rw-r--r--chromium/third_party/bintrees/bintrees/cwalker.c3799
-rw-r--r--chromium/third_party/bintrees/bintrees/cwalker.pxd19
-rw-r--r--chromium/third_party/bintrees/bintrees/cwalker.pyx133
-rw-r--r--chromium/third_party/bintrees/bintrees/qavltree.c3402
-rw-r--r--chromium/third_party/bintrees/bintrees/qavltree.pyx87
-rw-r--r--chromium/third_party/bintrees/bintrees/qbintree.c3397
-rw-r--r--chromium/third_party/bintrees/bintrees/qbintree.pyx85
-rw-r--r--chromium/third_party/bintrees/bintrees/qrbtree.c3399
-rw-r--r--chromium/third_party/bintrees/bintrees/qrbtree.pyx86
-rw-r--r--chromium/third_party/bintrees/bintrees/rbtree.py268
-rw-r--r--chromium/third_party/bintrees/bintrees/stack.c58
-rw-r--r--chromium/third_party/bintrees/bintrees/stack.h28
-rw-r--r--chromium/third_party/bintrees/bintrees/stack.pxd18
-rw-r--r--chromium/third_party/bintrees/bintrees/treemixin.py642
-rw-r--r--chromium/third_party/bintrees/bintrees/treeslice.py70
-rw-r--r--chromium/third_party/bintrees/bintrees/walker.py220
27 files changed, 17659 insertions, 0 deletions
diff --git a/chromium/third_party/bintrees/LICENSE.txt b/chromium/third_party/bintrees/LICENSE.txt
new file mode 100644
index 00000000000..3b2c783eea6
--- /dev/null
+++ b/chromium/third_party/bintrees/LICENSE.txt
@@ -0,0 +1,45 @@
+Copyright (c) 2012, Manfred Moitzi
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Deutsche Übersetzung:
+
+Copyright (c) 2012, Manfred Moitzi
+
+Hiermit wird unentgeltlich, jeder Person, die eine Kopie der Software
+und der zugehörigen Dokumentationen (die "Software") erhält, die
+Erlaubnis erteilt, uneingeschränkt zu benutzen, inklusive und ohne
+Ausnahme, dem Recht, sie zu verwenden, kopieren, ändern, fusionieren,
+verlegen, verbreiten, unterlizenzieren und/oder zu verkaufen, und
+Personen, die diese Software erhalten, diese Rechte zu geben, unter den
+folgenden Bedingungen:
+
+Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in allen
+Kopien oder Teilkopien der Software beizulegen.
+
+DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIE
+BEREITGESTELLT, EINSCHLIESSLICH DER GARANTIE ZUR BENUTZUNG FÜR DEN
+VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER
+RECHTSVERLETZUNG, JEDOCH NICHT DARAUF BESCHRÄNKT. IN KEINEM FALL SIND
+DIE AUTOREN ODER COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER SONSTIGE
+ANSPRÜCHE HAFTBAR ZU MACHEN, OB INFOLGE DER ERFÜLLUNG EINES VERTRAGES,
+EINES DELIKTES ODER ANDERS IM ZUSAMMENHANG MIT DER SOFTWARE ODER
+SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN.
+
diff --git a/chromium/third_party/bintrees/NEWS.txt b/chromium/third_party/bintrees/NEWS.txt
new file mode 100644
index 00000000000..c87ea156a61
--- /dev/null
+++ b/chromium/third_party/bintrees/NEWS.txt
@@ -0,0 +1,70 @@
+Version 1.0.1 February 2013
+
+ * bug fixes
+ * refactorings by graingert
+ * skip useless tests for pypy
+ * new license: MIT License
+ * tested with CPython2.7, CPython3.2, CPython3.3, pypy-1.9, pypy-2.0-beta1
+ * unified line endings to LF
+ * PEP8 refactorings
+ * added floor_item/key, ceiling_item/key methods, thanks to Dai Mikurube
+
+Version 1.0.0 29.12.2011
+
+ * bug fixes
+ * status: 5 - Production/Stable
+ * removed useless TreeIterator() class and T.treeiter() method.
+ * patch from Max Motovilov to use Visual Studio 2008 for building C-extensions
+
+Version 0.4.0 14.04.2011
+
+ * API change!!!
+ * full Python 3 support, also for Cython implementations
+ * removed user defined compare() function - keys have to be comparable!
+ * removed T.has_key(), use 'key in T'
+ * keys(), items(), values() generating 'views'
+ * removed iterkeys(), itervalues(), iteritems() methods
+ * replaced index slicing by key slicing
+ * removed index() and item_at()
+ * repr() produces a correct representation
+ * installs on systems without cython (tested with pypy)
+ * new license: GNU Library or Lesser General Public License (LGPL)
+
+Version 0.3.2 09.04.2011
+
+ * added itemslice(startkey, endkey), keyslice(startkey, endkey),
+ valueslice(startkey, endkey) - slicing by keys
+ * tested with pypy 1.4.1, damn fast
+ * Pure Python trees are working with Python 3
+ * No Cython implementation for Python 3
+
+Version 0.3.1 10.09.2010
+
+ * runs with Python 2.7
+
+Version 0.3.0 11.05.2010
+
+ * low level functions written as c-module only interface to python is a cython
+ module
+ * support for the pickle protocol
+
+Version 0.2.1 06.05.2010
+
+ * added delslice del T[0:3] -> remove treenodes 0, 1, 2
+ * added discard -> remove key without KeyError if not found
+ * added heap methods: min, max, nlarges, nsmallest ...
+ * added Set methods -> intersection, differnce, union, ...
+ * added slicing: T[5:10] get items with position (not key!) 5, 6, 7, 8, 9
+ T[5] get item with key! 5
+ * added index: T.index(key) -> get position of item <key>
+ * added item_at: T.item_at(0) -> get item at position (not key!) 0
+ T.item_at(0) O(n)! <==> T.min_item() O(log(n))
+
+Version 0.2.0 - 03.05.2010
+
+ * TreeMixin Class as base for Python-Trees and as Mixin for Cython-Trees
+
+Version 0.1.0 - 27.04.2010
+
+ * Alpha status
+ * Initial release
diff --git a/chromium/third_party/bintrees/OWNERS b/chromium/third_party/bintrees/OWNERS
new file mode 100644
index 00000000000..cf261a7f5a0
--- /dev/null
+++ b/chromium/third_party/bintrees/OWNERS
@@ -0,0 +1,2 @@
+dmikurube@chromium.org
+peria@chromium.org
diff --git a/chromium/third_party/bintrees/README.chromium b/chromium/third_party/bintrees/README.chromium
new file mode 100644
index 00000000000..98f62d114d1
--- /dev/null
+++ b/chromium/third_party/bintrees/README.chromium
@@ -0,0 +1,15 @@
+Name: Binary-, RedBlack- and AVL-Trees in Python and Cython
+Short Name: bintrees
+URL: https://pypi.python.org/pypi/bintrees/
+Version: 1.0.1
+Date: February 24, 2013
+License: MIT License
+License File: LICENSE.txt
+Security Critical: no
+
+Description:
+A Python library which provides Binary-, RedBlack- and AVL-Trees in Python and
+Cython.
+
+Local Modifications:
+Removed PKG-INFO, setup.py and tests.
diff --git a/chromium/third_party/bintrees/README.txt b/chromium/third_party/bintrees/README.txt
new file mode 100644
index 00000000000..ba8136055d4
--- /dev/null
+++ b/chromium/third_party/bintrees/README.txt
@@ -0,0 +1,229 @@
+Binary Tree Package
+===================
+
+Abstract
+========
+
+This package provides Binary- RedBlack- and AVL-Trees written in Python and Cython.
+
+This Classes are much slower than the built-in dict class, but all
+iterators/generators yielding data in sorted key order.
+
+Source of Algorithms
+--------------------
+
+AVL- and RBTree algorithms taken from Julienne Walker: http://eternallyconfuzzled.com/jsw_home.aspx
+
+Trees written in Python (only standard library)
+-----------------------------------------------
+
+ - *BinaryTree* -- unbalanced binary tree
+ - *AVLTree* -- balanced AVL-Tree
+ - *RBTree* -- balanced Red-Black-Tree
+
+Trees written with C-Functions and Cython as wrapper
+----------------------------------------------------
+
+ - *FastBinaryTree* -- unbalanced binary tree
+ - *FastAVLTree* -- balanced AVL-Tree
+ - *FastRBTree* -- balanced Red-Black-Tree
+
+All trees provides the same API, the pickle protocol is supported.
+
+FastXTrees has C-structs as tree-node structure and C-implementation for low level
+operations: insert, remove, get_value, max_item, min_item.
+
+Constructor
+~~~~~~~~~~~
+
+ * Tree() -> new empty tree;
+ * Tree(mapping) -> new tree initialized from a mapping (requires only an items() method)
+ * Tree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)]
+
+Methods
+~~~~~~~
+
+ * __contains__(k) -> True if T has a key k, else False, O(log(n))
+ * __delitem__(y) <==> del T[y], del[s:e], O(log(n))
+ * __getitem__(y) <==> T[y], T[s:e], O(log(n))
+ * __iter__() <==> iter(T)
+ * __len__() <==> len(T), O(1)
+ * __max__() <==> max(T), get max item (k,v) of T, O(log(n))
+ * __min__() <==> min(T), get min item (k,v) of T, O(log(n))
+ * __and__(other) <==> T & other, intersection
+ * __or__(other) <==> T | other, union
+ * __sub__(other) <==> T - other, difference
+ * __xor__(other) <==> T ^ other, symmetric_difference
+ * __repr__() <==> repr(T)
+ * __setitem__(k, v) <==> T[k] = v, O(log(n))
+ * clear() -> None, remove all items from T, O(n)
+ * copy() -> a shallow copy of T, O(n*log(n))
+ * discard(k) -> None, remove k from T, if k is present, O(log(n))
+ * get(k[,d]) -> T[k] if k in T, else d, O(log(n))
+ * is_empty() -> True if len(T) == 0, O(1)
+ * items([reverse]) -> generator for (k, v) items of T, O(n)
+ * keys([reverse]) -> generator for keys of T, O(n)
+ * values([reverse]) -> generator for values of T, O(n)
+ * pop(k[,d]) -> v, remove specified key and return the corresponding value, O(log(n))
+ * popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple, O(log(n))
+ * setdefault(k[,d]) -> T.get(k, d), also set T[k]=d if k not in T, O(log(n))
+ * update(E) -> None. Update T from dict/iterable E, O(E*log(n))
+ * foreach(f, [order]) -> visit all nodes of tree (0 = 'inorder', -1 = 'preorder' or +1 = 'postorder') and call f(k, v) for each node, O(n)
+
+slicing by keys
+~~~~~~~~~~~~~~~
+
+ * itemslice(s, e) -> generator for (k, v) items of T for s <= key < e, O(n)
+ * keyslice(s, e) -> generator for keys of T for s <= key < e, O(n)
+ * valueslice(s, e) -> generator for values of T for s <= key < e, O(n)
+ * T[s:e] -> TreeSlice object, with keys in range s <= key < e, O(n)
+ * del T[s:e] -> remove items by key slicing, for s <= key < e, O(n)
+
+ start/end parameter:
+
+ * if 's' is None or T[:e] TreeSlice/iterator starts with value of min_key();
+ * if 'e' is None or T[s:] TreeSlice/iterator ends with value of max_key();
+ * T[:] is a TreeSlice which represents the whole tree;
+
+ TreeSlice is a tree wrapper with range check, and contains no references
+ to objects, deleting objects in the associated tree also deletes the object
+ in the TreeSlice.
+
+ * TreeSlice[k] -> get value for key k, raises KeyError if k not exists in range s:e
+ * TreeSlice[s1:e1] -> TreeSlice object, with keys in range s1 <= key < e1
+ - new lower bound is max(s, s1)
+ - new upper bound is min(e, e1)
+
+ TreeSlice methods:
+
+ * items() -> generator for (k, v) items of T, O(n)
+ * keys() -> generator for keys of T, O(n)
+ * values() -> generator for values of T, O(n)
+ * __iter__ <==> keys()
+ * __repr__ <==> repr(T)
+ * __contains__(key)-> True if TreeSlice has a key k, else False, O(log(n))
+
+prev/succ operations
+~~~~~~~~~~~~~~~~~~~~
+
+ * prev_item(key) -> get (k, v) pair, where k is predecessor to key, O(log(n))
+ * prev_key(key) -> k, get the predecessor of key, O(log(n))
+ * succ_item(key) -> get (k,v) pair as a 2-tuple, where k is successor to key, O(log(n))
+ * succ_key(key) -> k, get the successor of key, O(log(n))
+ * floor_item(key) -> get (k, v) pair, where k is the greatest key less than or equal to key, O(log(n))
+ * floor_key(key) -> k, get the greatest key less than or equal to key, O(log(n))
+ * ceiling_item(key) -> get (k, v) pair, where k is the smallest key greater than or equal to key, O(log(n))
+ * ceiling_key(key) -> k, get the smallest key greater than or equal to key, O(log(n))
+
+Heap methods
+~~~~~~~~~~~~
+
+ * max_item() -> get largest (key, value) pair of T, O(log(n))
+ * max_key() -> get largest key of T, O(log(n))
+ * min_item() -> get smallest (key, value) pair of T, O(log(n))
+ * min_key() -> get smallest key of T, O(log(n))
+ * pop_min() -> (k, v), remove item with minimum key, O(log(n))
+ * pop_max() -> (k, v), remove item with maximum key, O(log(n))
+ * nlargest(i[,pop]) -> get list of i largest items (k, v), O(i*log(n))
+ * nsmallest(i[,pop]) -> get list of i smallest items (k, v), O(i*log(n))
+
+Set methods (using frozenset)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ * intersection(t1, t2, ...) -> Tree with keys *common* to all trees
+ * union(t1, t2, ...) -> Tree with keys from *either* trees
+ * difference(t1, t2, ...) -> Tree with keys in T but not any of t1, t2, ...
+ * symmetric_difference(t1) -> Tree with keys in either T and t1 but not both
+ * issubset(S) -> True if every element in T is in S
+ * issuperset(S) -> True if every element in S is in T
+ * isdisjoint(S) -> True if T has a null intersection with S
+
+Classmethods
+~~~~~~~~~~~~
+
+ * fromkeys(S[,v]) -> New tree with keys from S and values equal to v.
+
+Performance
+===========
+
+Profiling with timeit(): 5000 unique random int keys, time in seconds
+
+======================== ============= ============== ============== ==============
+unbalanced Trees CPython 2.7.2 FastBinaryTree ipy 2.7.0 pypy 1.7.0
+======================== ============= ============== ============== ==============
+build time 100x 7,55 0,60 2,51 0,29
+build & delete time 100x 13,34 1,48 4,45 0,47
+search 100x all keys 2,86 0,96 0,27 0,06
+======================== ============= ============== ============== ==============
+
+======================== ============= ============== ============== ==============
+AVLTrees CPython 2.7.2 FastAVLTree ipy 2.7.0 pypy 1.7.0
+======================== ============= ============== ============== ==============
+build time 100x 22,66 0,65 10,45 1,29
+build & delete time 100x 36,71 1,47 20,89 3,02
+search 100x all keys 2,34 0,85 0,89 0,14
+======================== ============= ============== ============== ==============
+
+======================== ============= ============== ============== ==============
+RBTrees CPython 2.7.2 FastRBTree ipy 2.7.0 pypy 1.7.0
+======================== ============= ============== ============== ==============
+build time 100x 14,78 0,65 4,43 0,49
+build & delete time 100x 39,34 1,63 12,43 1,32
+search 100x all keys 2,32 0,86 0,86 0,13
+======================== ============= ============== ============== ==============
+
+News
+====
+
+Version 1.0.1 February 2013
+
+ * bug fixes
+ * refactorings by graingert
+ * skip useless tests for pypy
+ * new license: MIT License
+ * tested with CPython2.7, CPython3.2, CPython3.3, pypy-1.9, pypy-2.0-beta1
+ * unified line endings to LF
+ * PEP8 refactorings
+ * added floor_item/key, ceiling_item/key methods, thanks to Dai Mikurube
+
+Version 1.0.0
+
+ * bug fixes
+ * status: 5 - Production/Stable
+ * removed useless TreeIterator() class and T.treeiter() method.
+ * patch from Max Motovilov to use Visual Studio 2008 for building C-extensions
+
+Version 0.4.0
+
+ * API change!!!
+ * full Python 3 support, also for Cython implementations
+ * removed user defined compare() function - keys have to be comparable!
+ * removed T.has_key(), use 'key in T'
+ * keys(), items(), values() generating 'views'
+ * removed iterkeys(), itervalues(), iteritems() methods
+ * replaced index slicing by key slicing
+ * removed index() and item_at()
+ * repr() produces a correct representation
+ * installs on systems without cython (tested with pypy)
+ * new license: GNU Library or Lesser General Public License (LGPL)
+
+Installation
+============
+
+from source::
+
+ python setup.py install
+
+Download
+========
+
+http://bitbucket.org/mozman/bintrees/downloads
+
+Documentation
+=============
+
+this README.txt
+
+bintrees can be found on bitbucket.org at:
+
+http://bitbucket.org/mozman/bintrees
diff --git a/chromium/third_party/bintrees/bintrees/__init__.py b/chromium/third_party/bintrees/bintrees/__init__.py
new file mode 100644
index 00000000000..8cb5de129a8
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/__init__.py
@@ -0,0 +1,181 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: binary trees package
+# Created: 03.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+from __future__ import absolute_import
+
+__doc__ = """
+Binary Tree Package
+===================
+
+Python Trees
+------------
+
+Balanced and unbalance binary trees written in pure Python with a dict-like API.
+
+Classes
+~~~~~~~
+* BinaryTree -- unbalanced binary tree
+* AVLTree -- balanced AVL-Tree
+* RBTree -- balanced Red-Black-Tree
+
+Cython Trees
+------------
+
+Basic tree functions written in Cython, merged with TreeMixin to provide the
+full API of the Python Trees.
+
+Classes
+~~~~~~~
+
+* FastBinaryTree -- unbalanced binary tree
+* FastAVLTree -- balanced AVLTree
+* FastRBTree -- balanced Red-Black-Tree
+
+Overview of API for all Classes
+===============================
+
+* TreeClass ([compare]) -> new empty tree.
+* TreeClass(mapping, [compare]) -> new tree initialized from a mapping
+* TreeClass(seq, [compare]) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)]
+
+Methods
+-------
+
+* __contains__(k) -> True if T has a key k, else False, O(log(n))
+* __delitem__(y) <==> del T[y], O(log(n))
+* __getitem__(y) <==> T[y], O(log(n))
+* __iter__() <==> iter(T)
+* __len__() <==> len(T), O(1)
+* __max__() <==> max(T), get max item (k,v) of T, O(log(n))
+* __min__() <==> min(T), get min item (k,v) of T, O(log(n))
+* __and__(other) <==> T & other, intersection
+* __or__(other) <==> T | other, union
+* __sub__(other) <==> T - other, difference
+* __xor__(other) <==> T ^ other, symmetric_difference
+* __repr__() <==> repr(T)
+* __setitem__(k, v) <==> T[k] = v, O(log(n))
+* clear() -> None, Remove all items from T, , O(n)
+* copy() -> a shallow copy of T, O(n*log(n))
+* discard(k) -> None, remove k from T, if k is present, O(log(n))
+* get(k[,d]) -> T[k] if k in T, else d, O(log(n))
+* is_empty() -> True if len(T) == 0, O(1)
+* items([reverse]) -> list of T's (k, v) pairs, as 2-tuples, O(n)
+* keys([reverse]) -> list of T's keys, O(n)
+* pop(k[,d]) -> v, remove specified key and return the corresponding value, O(log(n))
+* popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple, O(log(n))
+* setdefault(k[,d]) -> T.get(k, d), also set T[k]=d if k not in T, O(log(n))
+* update(E) -> None. Update T from dict/iterable E, O(E*log(n))
+* values([reverse]) -> list of T's values, O(n)
+
+walk forward/backward, O(log(n))
+
+* prev_item(key) -> get (k, v) pair, where k is predecessor to key, O(log(n))
+* prev_key(key) -> k, get the predecessor of key, O(log(n))
+* succ_item(key) -> get (k,v) pair as a 2-tuple, where k is successor to key, O(log(n))
+* succ_key(key) -> k, get the successor of key, O(log(n))
+
+slicing by keys
+
+* itemslice(s, e) -> generator for (k, v) items of T for s <= key < e, O(n)
+* keyslice(s, e) -> generator for keys of T for s <= key < e, O(n)
+* valueslice(s, e) -> generator for values of T for s <= key < e, O(n)
+* T[s:e] -> TreeSlice object, with keys in range s <= key < e, O(n)
+* del T[s:e] -> remove items by key slicing, for s <= key < e, O(n)
+
+if 's' is None or T[:e] TreeSlice/iterator starts with value of min_key()
+if 'e' is None or T[s:] TreeSlice/iterator ends with value of max_key()
+T[:] is a TreeSlice which represents the whole tree.
+
+TreeSlice is a tree wrapper with range check, and contains no references
+to objects, deleting objects in the associated tree also deletes the object
+in the TreeSlice.
+
+* TreeSlice[k] -> get value for key k, raises KeyError if k not exists in range s:e
+* TreeSlice[s1:e1] -> TreeSlice object, with keys in range s1 <= key < e1
+
+ * new lower bound is max(s, s1)
+ * new upper bound is min(e, e1)
+
+TreeSlice methods:
+
+* items() -> generator for (k, v) items of T, O(n)
+* keys() -> generator for keys of T, O(n)
+* values() -> generator for values of T, O(n)
+* __iter__ <==> keys()
+* __repr__ <==> repr(T)
+* __contains__(key)-> True if TreeSlice has a key k, else False, O(log(n))
+
+Heap methods
+
+* max_item() -> get biggest (key, value) pair of T, O(log(n))
+* max_key() -> get biggest key of T, O(log(n))
+* min_item() -> get smallest (key, value) pair of T, O(log(n))
+* min_key() -> get smallest key of T, O(log(n))
+* pop_min() -> (k, v), remove item with minimum key, O(log(n))
+* pop_max() -> (k, v), remove item with maximum key, O(log(n))
+* nlargest(i[,pop]) -> get list of i largest items (k, v), O(i*log(n))
+* nsmallest(i[,pop]) -> get list of i smallest items (k, v), O(i*log(n))
+
+Set methods (using frozenset)
+
+* intersection(t1, t2, ...) -> Tree with keys *common* to all trees
+* union(t1, t2, ...) -> Tree with keys from *either* trees
+* difference(t1, t2, ...) -> Tree with keys in T but not any of t1, t2, ...
+* symmetric_difference(t1) -> Tree with keys in either T and t1 but not both
+* issubset(S) -> True if every element in T is in S
+* issuperset(S) -> True if every element in S is in T
+* isdisjoint(S) -> True if T has a null intersection with S
+
+Classmethods
+
+* fromkeys(S[,v]) -> New tree with keys from S and values equal to v.
+"""
+
+__all__ = [
+ 'FastBinaryTree',
+ 'FastAVLTree',
+ 'FastRBTree',
+ 'BinaryTree',
+ 'AVLTree',
+ 'RBTree'
+]
+
+from .treemixin import TreeMixin
+from .bintree import BinaryTree
+from .avltree import AVLTree
+from .rbtree import RBTree
+
+try:
+ from .qbintree import cBinaryTree
+
+ class FastBinaryTree(cBinaryTree, TreeMixin):
+ """ Faster unbalanced binary tree written in Cython with C-Code. """
+except ImportError: # fall back to pure Python version
+ FastBinaryTree = BinaryTree
+except ValueError: # for pypy
+ FastBinaryTree = BinaryTree
+
+try:
+ from .qavltree import cAVLTree
+
+ class FastAVLTree(cAVLTree, TreeMixin):
+ """ Faster balanced AVL-Tree written in Cython with C-Code. """
+except ImportError: # fall back to pure Python version
+ FastAVLTree = AVLTree
+except ValueError: # for pypy
+ FastAVLTree = AVLTree
+
+try:
+ from .qrbtree import cRBTree
+
+ class FastRBTree(cRBTree, TreeMixin):
+ """ Faster balanced Red-Black-Tree written in Cython with C-Code. """
+except ImportError: # fall back to pure Python version
+ FastRBTree = RBTree
+except ValueError: # for pypy
+ FastRBTree = RBTree
diff --git a/chromium/third_party/bintrees/bintrees/avltree.py b/chromium/third_party/bintrees/bintrees/avltree.py
new file mode 100644
index 00000000000..632ba4ec0a8
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/avltree.py
@@ -0,0 +1,302 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman (python version)
+# Purpose: avl tree module (Julienne Walker's unbounded none recursive algorithm)
+# source: http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_avl.aspx
+# Created: 01.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+# Conclusion of Julienne Walker
+
+# AVL trees are about as close to optimal as balanced binary search trees can
+# get without eating up resources. You can rest assured that the O(log N)
+# performance of binary search trees is guaranteed with AVL trees, but the extra
+# bookkeeping required to maintain an AVL tree can be prohibitive, especially
+# if deletions are common. Insertion into an AVL tree only requires one single
+# or double rotation, but deletion could perform up to O(log N) rotations, as
+# in the example of a worst case AVL (ie. Fibonacci) tree. However, those cases
+# are rare, and still very fast.
+
+# AVL trees are best used when degenerate sequences are common, and there is
+# little or no locality of reference in nodes. That basically means that
+# searches are fairly random. If degenerate sequences are not common, but still
+# possible, and searches are random then a less rigid balanced tree such as red
+# black trees or Andersson trees are a better solution. If there is a significant
+# amount of locality to searches, such as a small cluster of commonly searched
+# items, a splay tree is theoretically better than all of the balanced trees
+# because of its move-to-front design.
+
+from __future__ import absolute_import
+
+from .treemixin import TreeMixin
+from array import array
+
+__all__ = ['AVLTree']
+
+MAXSTACK = 32
+
+
+class Node(object):
+ """ Internal object, represents a treenode """
+ __slots__ = ['left', 'right', 'balance', 'key', 'value']
+
+ def __init__(self, key=None, value=None):
+ self.left = None
+ self.right = None
+ self.key = key
+ self.value = value
+ self.balance = 0
+
+ def __getitem__(self, key):
+ """ x.__getitem__(key) <==> x[key], where key is 0 (left) or 1 (right) """
+ return self.left if key == 0 else self.right
+
+ def __setitem__(self, key, value):
+ """ x.__setitem__(key, value) <==> x[key]=value, where key is 0 (left) or 1 (right) """
+ if key == 0:
+ self.left = value
+ else:
+ self.right = value
+
+ def free(self):
+ """Remove all references."""
+ self.left = None
+ self.right = None
+ self.key = None
+ self.value = None
+
+
+def height(node):
+ return node.balance if node is not None else -1
+
+
+def jsw_single(root, direction):
+ other_side = 1 - direction
+ save = root[other_side]
+ root[other_side] = save[direction]
+ save[direction] = root
+ rlh = height(root.left)
+ rrh = height(root.right)
+ slh = height(save[other_side])
+ root.balance = max(rlh, rrh) + 1
+ save.balance = max(slh, root.balance) + 1
+ return save
+
+
+def jsw_double(root, direction):
+ other_side = 1 - direction
+ root[other_side] = jsw_single(root[other_side], other_side)
+ return jsw_single(root, direction)
+
+
+class AVLTree(TreeMixin):
+ """
+ AVLTree implements a balanced binary tree with a dict-like interface.
+
+ see: http://en.wikipedia.org/wiki/AVL_tree
+
+ In computer science, an AVL tree is a self-balancing binary search tree, and
+ it is the first such data structure to be invented. In an AVL tree, the
+ heights of the two child subtrees of any node differ by at most one;
+ therefore, it is also said to be height-balanced. Lookup, insertion, and
+ deletion all take O(log n) time in both the average and worst cases, where n
+ is the number of nodes in the tree prior to the operation. Insertions and
+ deletions may require the tree to be rebalanced by one or more tree rotations.
+
+ The AVL tree is named after its two inventors, G.M. Adelson-Velskii and E.M.
+ Landis, who published it in their 1962 paper "An algorithm for the
+ organization of information."
+
+ AVLTree() -> new empty tree.
+ AVLTree(mapping) -> new tree initialized from a mapping
+ AVLTree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)]
+
+ see also TreeMixin() class.
+
+ """
+ def __init__(self, items=None):
+ """ x.__init__(...) initializes x; see x.__class__.__doc__ for signature """
+ self._root = None
+ self._count = 0
+ if items is not None:
+ self.update(items)
+
+ def clear(self):
+ """ T.clear() -> None. Remove all items from T. """
+ def _clear(node):
+ if node is not None:
+ _clear(node.left)
+ _clear(node.right)
+ node.free()
+ _clear(self._root)
+ self._count = 0
+ self._root = None
+
+ @property
+ def count(self):
+ """ count of items """
+ return self._count
+
+ @property
+ def root(self):
+ """ root node of T """
+ return self._root
+
+ def _new_node(self, key, value):
+ """ Create a new treenode """
+ self._count += 1
+ return Node(key, value)
+
+ def insert(self, key, value):
+ """ T.insert(key, value) <==> T[key] = value, insert key, value into Tree """
+ if self._root is None:
+ self._root = self._new_node(key, value)
+ else:
+ node_stack = [] # node stack
+ dir_stack = array('I') # direction stack
+ done = False
+ top = 0
+ node = self._root
+ # search for an empty link, save path
+ while True:
+ if key == node.key: # update existing item
+ node.value = value
+ return
+ direction = 1 if key > node.key else 0
+ dir_stack.append(direction)
+ node_stack.append(node)
+ if node[direction] is None:
+ break
+ node = node[direction]
+
+ # Insert a new node at the bottom of the tree
+ node[direction] = self._new_node(key, value)
+
+ # Walk back up the search path
+ top = len(node_stack) - 1
+ while (top >= 0) and not done:
+ direction = dir_stack[top]
+ other_side = 1 - direction
+ topnode = node_stack[top]
+ left_height = height(topnode[direction])
+ right_height = height(topnode[other_side])
+
+ # Terminate or rebalance as necessary */
+ if left_height - right_height == 0:
+ done = True
+ if left_height - right_height >= 2:
+ a = topnode[direction][direction]
+ b = topnode[direction][other_side]
+
+ if height(a) >= height(b):
+ node_stack[top] = jsw_single(topnode, other_side)
+ else:
+ node_stack[top] = jsw_double(topnode, other_side)
+
+ # Fix parent
+ if top != 0:
+ node_stack[top - 1][dir_stack[top - 1]] = node_stack[top]
+ else:
+ self._root = node_stack[0]
+ done = True
+
+ # Update balance factors
+ topnode = node_stack[top]
+ left_height = height(topnode[direction])
+ right_height = height(topnode[other_side])
+
+ topnode.balance = max(left_height, right_height) + 1
+ top -= 1
+
+ def remove(self, key):
+ """ T.remove(key) <==> del T[key], remove item <key> from tree """
+ if self._root is None:
+ raise KeyError(str(key))
+ else:
+ node_stack = [None] * MAXSTACK # node stack
+ dir_stack = array('I', [0] * MAXSTACK) # direction stack
+ top = 0
+ node = self._root
+
+ while True:
+ # Terminate if not found
+ if node is None:
+ raise KeyError(str(key))
+ elif node.key == key:
+ break
+
+ # Push direction and node onto stack
+ direction = 1 if key > node.key else 0
+ dir_stack[top] = direction
+
+ node_stack[top] = node
+ node = node[direction]
+ top += 1
+
+ # Remove the node
+ if (node.left is None) or (node.right is None):
+ # Which child is not null?
+ direction = 1 if node.left is None else 0
+
+ # Fix parent
+ if top != 0:
+ node_stack[top - 1][dir_stack[top - 1]] = node[direction]
+ else:
+ self._root = node[direction]
+ node.free()
+ self._count -= 1
+ else:
+ # Find the inorder successor
+ heir = node.right
+
+ # Save the path
+ dir_stack[top] = 1
+ node_stack[top] = node
+ top += 1
+
+ while heir.left is not None:
+ dir_stack[top] = 0
+ node_stack[top] = heir
+ top += 1
+ heir = heir.left
+
+ # Swap data
+ node.key = heir.key
+ node.value = heir.value
+
+ # Unlink successor and fix parent
+ xdir = 1 if node_stack[top - 1].key == node.key else 0
+ node_stack[top - 1][xdir] = heir.right
+ heir.free()
+ self._count -= 1
+
+ # Walk back up the search path
+ top -= 1
+ while top >= 0:
+ direction = dir_stack[top]
+ other_side = 1 - direction
+ topnode = node_stack[top]
+ left_height = height(topnode[direction])
+ right_height = height(topnode[other_side])
+ b_max = max(left_height, right_height)
+
+ # Update balance factors
+ topnode.balance = b_max + 1
+
+ # Terminate or rebalance as necessary
+ if (left_height - right_height) == -1:
+ break
+ if (left_height - right_height) <= -2:
+ a = topnode[other_side][direction]
+ b = topnode[other_side][other_side]
+ if height(a) <= height(b):
+ node_stack[top] = jsw_single(topnode, direction)
+ else:
+ node_stack[top] = jsw_double(topnode, direction)
+ # Fix parent
+ if top != 0:
+ node_stack[top - 1][dir_stack[top - 1]] = node_stack[top]
+ else:
+ self._root = node_stack[0]
+ top -= 1
diff --git a/chromium/third_party/bintrees/bintrees/bintree.py b/chromium/third_party/bintrees/bintrees/bintree.py
new file mode 100644
index 00000000000..866dc89d208
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/bintree.py
@@ -0,0 +1,153 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: binary tree module
+# Created: 28.04.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+from __future__ import absolute_import
+
+from .treemixin import TreeMixin
+
+__all__ = ['BinaryTree']
+
+
+class Node(object):
+ """ Internal object, represents a treenode """
+ __slots__ = ['key', 'value', 'left', 'right']
+
+ def __init__(self, key, value):
+ self.key = key
+ self.value = value
+ self.left = None
+ self.right = None
+
+ def __getitem__(self, key):
+ """ x.__getitem__(key) <==> x[key], where key is 0 (left) or 1 (right) """
+ return self.left if key == 0 else self.right
+
+ def __setitem__(self, key, value):
+ """ x.__setitem__(key, value) <==> x[key]=value, where key is 0 (left) or 1 (right) """
+ if key == 0:
+ self.left = value
+ else:
+ self.right = value
+
+ def free(self):
+ """ Set references to None """
+ self.left = None
+ self.right = None
+ self.value = None
+ self.key = None
+
+
+class BinaryTree(TreeMixin):
+ """
+ BinaryTree implements an unbalanced binary tree with a dict-like interface.
+
+ see: http://en.wikipedia.org/wiki/Binary_tree
+
+ A binary tree is a tree data structure in which each node has at most two
+ children.
+
+ BinaryTree() -> new empty tree.
+ BinaryTree(mapping,) -> new tree initialized from a mapping
+ BinaryTree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)]
+
+ see also TreeMixin() class.
+
+ """
+ def __init__(self, items=None):
+ """ x.__init__(...) initializes x; see x.__class__.__doc__ for signature """
+ self._root = None
+ self._count = 0
+ if items is not None:
+ self.update(items)
+
+ def clear(self):
+ """ T.clear() -> None. Remove all items from T. """
+ def _clear(node):
+ if node is not None:
+ _clear(node.left)
+ _clear(node.right)
+ node.free()
+ _clear(self._root)
+ self._count = 0
+ self._root = None
+
+ @property
+ def root(self):
+ """ root node of T """
+ return self._root
+
+ @property
+ def count(self):
+ """ count of items """
+ return self._count
+
+ def _new_node(self, key, value):
+ """ Create a new tree node. """
+ self._count += 1
+ return Node(key, value)
+
+ def insert(self, key, value):
+ """ T.insert(key, value) <==> T[key] = value, insert key, value into Tree """
+ if self._root is None:
+ self._root = self._new_node(key, value)
+ else:
+ parent = None
+ direction = 0
+ node = self._root
+ while True:
+ if node is None:
+ parent[direction] = self._new_node(key, value)
+ break
+ if key == node.key:
+ node.value = value # replace value
+ break
+ else:
+ parent = node
+ direction = 0 if key <= node.key else 1
+ node = node[direction]
+
+ def remove(self, key):
+ """ T.remove(key) <==> del T[key], remove item <key> from tree """
+ node = self._root
+ if node is None:
+ raise KeyError(str(key))
+ else:
+ parent = None
+ direction = 0
+ while True:
+ if key == node.key:
+ # remove node
+ if (node.left is not None) and (node.right is not None):
+ # find replacment node: smallest key in right-subtree
+ parent = node
+ direction = 1
+ replacement = node.right
+ while replacement.left is not None:
+ parent = replacement
+ direction = 0
+ replacement = replacement.left
+ parent[direction] = replacement.right
+ #swap places
+ node.key = replacement.key
+ node.value = replacement.value
+ node = replacement # delete replacement!
+ else:
+ down_dir = 1 if node.left is None else 0
+ if parent is None: # root
+ self._root = node[down_dir]
+ else:
+ parent[direction] = node[down_dir]
+ node.free()
+ self._count -= 1
+ break
+ else:
+ direction = 0 if key < node.key else 1
+ parent = node
+ node = node[direction]
+ if node is None:
+ raise KeyError(str(key))
diff --git a/chromium/third_party/bintrees/bintrees/ctrees.c b/chromium/third_party/bintrees/bintrees/ctrees.c
new file mode 100644
index 00000000000..7d2b964f3b3
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/ctrees.c
@@ -0,0 +1,862 @@
+/*
+ * ctrees.c
+ *
+ * Author: mozman
+ * Copyright (c) 2010-2013 by Manfred Moitzi
+ * License: MIT-License
+ */
+
+#include "ctrees.h"
+#include "stack.h"
+#include <Python.h>
+
+#define LEFT 0
+#define RIGHT 1
+#define KEY(node) (node->key)
+#define VALUE(node) (node->value)
+#define LEFT_NODE(node) (node->link[LEFT])
+#define RIGHT_NODE(node) (node->link[RIGHT])
+#define LINK(node, dir) (node->link[dir])
+#define XDATA(node) (node->xdata)
+#define RED(node) (node->xdata)
+#define BALANCE(node) (node->xdata)
+
+static node_t *
+ct_new_node(PyObject *key, PyObject *value, int xdata)
+{
+ node_t *new_node = PyMem_Malloc(sizeof(node_t));
+ if (new_node != NULL) {
+ KEY(new_node) = key;
+ Py_INCREF(key);
+ VALUE(new_node) = value;
+ Py_INCREF(value);
+ LEFT_NODE(new_node) = NULL;
+ RIGHT_NODE(new_node) = NULL;
+ XDATA(new_node) = xdata;
+ }
+ return new_node;
+}
+
+static void
+ct_delete_node(node_t *node)
+{
+ if (node != NULL) {
+ Py_XDECREF(KEY(node));
+ Py_XDECREF(VALUE(node));
+ LEFT_NODE(node) = NULL;
+ RIGHT_NODE(node) = NULL;
+ PyMem_Free(node);
+ }
+}
+
+extern void
+ct_delete_tree(node_t *root)
+{
+ if (root == NULL)
+ return;
+ if (LEFT_NODE(root) != NULL) {
+ ct_delete_tree(LEFT_NODE(root));
+ }
+ if (RIGHT_NODE(root) != NULL) {
+ ct_delete_tree(RIGHT_NODE(root));
+ }
+ ct_delete_node(root);
+}
+
+static void
+ct_swap_data(node_t *node1, node_t *node2)
+{
+ PyObject *tmp;
+ tmp = KEY(node1);
+ KEY(node1) = KEY(node2);
+ KEY(node2) = tmp;
+ tmp = VALUE(node1);
+ VALUE(node1) = VALUE(node2);
+ VALUE(node2) = tmp;
+}
+
+int
+ct_compare(PyObject *key1, PyObject *key2)
+{
+ int res;
+
+ res = PyObject_RichCompareBool(key1, key2, Py_LT);
+ if (res > 0)
+ return -1;
+ else if (res < 0) {
+ PyErr_SetString(PyExc_TypeError, "invalid type for key");
+ return 0;
+ }
+ /* second compare:
+ +1 if key1 > key2
+ 0 if not -> equal
+ -1 means error, if error, it should happend at the first compare
+ */
+ return PyObject_RichCompareBool(key1, key2, Py_GT);
+}
+
+extern node_t *
+ct_find_node(node_t *root, PyObject *key)
+{
+ int res;
+ while (root != NULL) {
+ res = ct_compare(key, KEY(root));
+ if (res == 0) /* key found */
+ return root;
+ else {
+ root = LINK(root, (res > 0));
+ }
+ }
+ return NULL; /* key not found */
+}
+
+extern PyObject *
+ct_get_item(node_t *root, PyObject *key)
+{
+ node_t *node;
+ PyObject *tuple;
+
+ node = ct_find_node(root, key);
+ if (node != NULL) {
+ tuple = PyTuple_New(2);
+ PyTuple_SET_ITEM(tuple, 0, KEY(node));
+ PyTuple_SET_ITEM(tuple, 1, VALUE(node));
+ return tuple;
+ }
+ Py_RETURN_NONE;
+}
+
+extern node_t *
+ct_max_node(node_t *root)
+/* get node with largest key */
+{
+ if (root == NULL)
+ return NULL;
+ while (RIGHT_NODE(root) != NULL)
+ root = RIGHT_NODE(root);
+ return root;
+}
+
+extern node_t *
+ct_min_node(node_t *root)
+// get node with smallest key
+{
+ if (root == NULL)
+ return NULL;
+ while (LEFT_NODE(root) != NULL)
+ root = LEFT_NODE(root);
+ return root;
+}
+
+extern int
+ct_bintree_remove(node_t **rootaddr, PyObject *key)
+/* attention: rootaddr is the address of the root pointer */
+{
+ node_t *node, *parent, *replacement;
+ int direction, cmp_res, down_dir;
+
+ node = *rootaddr;
+
+ if (node == NULL)
+ return 0; /* root is NULL */
+ parent = NULL;
+ direction = 0;
+
+ while (1) {
+ cmp_res = ct_compare(key, KEY(node));
+ if (cmp_res == 0) /* key found, remove node */
+ {
+ if ((LEFT_NODE(node) != NULL) && (RIGHT_NODE(node) != NULL)) {
+ /* find replacement node: smallest key in right-subtree */
+ parent = node;
+ direction = RIGHT;
+ replacement = RIGHT_NODE(node);
+ while (LEFT_NODE(replacement) != NULL) {
+ parent = replacement;
+ direction = LEFT;
+ replacement = LEFT_NODE(replacement);
+ }
+ LINK(parent, direction) = RIGHT_NODE(replacement);
+ /* swap places */
+ ct_swap_data(node, replacement);
+ node = replacement; /* delete replacement node */
+ }
+ else {
+ down_dir = (LEFT_NODE(node) == NULL) ? RIGHT : LEFT;
+ if (parent == NULL) /* root */
+ {
+ *rootaddr = LINK(node, down_dir);
+ }
+ else {
+ LINK(parent, direction) = LINK(node, down_dir);
+ }
+ }
+ ct_delete_node(node);
+ return 1; /* remove was success full */
+ }
+ else {
+ direction = (cmp_res < 0) ? LEFT : RIGHT;
+ parent = node;
+ node = LINK(node, direction);
+ if (node == NULL)
+ return 0; /* error key not found */
+ }
+ }
+}
+
+extern int
+ct_bintree_insert(node_t **rootaddr, PyObject *key, PyObject *value)
+/* attention: rootaddr is the address of the root pointer */
+{
+ node_t *parent, *node;
+ int direction, cval;
+ node = *rootaddr;
+ if (node == NULL) {
+ node = ct_new_node(key, value, 0); /* new node is also the root */
+ if (node == NULL)
+ return -1; /* got no memory */
+ *rootaddr = node;
+ }
+ else {
+ direction = LEFT;
+ parent = NULL;
+ while (1) {
+ if (node == NULL) {
+ node = ct_new_node(key, value, 0);
+ if (node == NULL)
+ return -1; /* get no memory */
+ LINK(parent, direction) = node;
+ return 1;
+ }
+ cval = ct_compare(key, KEY(node));
+ if (cval == 0) {
+ /* key exists, replace value object */
+ Py_XDECREF(VALUE(node)); /* release old value object */
+ VALUE(node) = value; /* set new value object */
+ Py_INCREF(value); /* take new value object */
+ return 0;
+ }
+ else {
+ parent = node;
+ direction = (cval < 0) ? LEFT : RIGHT;
+ node = LINK(node, direction);
+ }
+ }
+ }
+ return 1;
+}
+
+static int
+is_red (node_t *node)
+{
+ return (node != NULL) && (RED(node) == 1);
+}
+
+#define rb_new_node(key, value) ct_new_node(key, value, 1)
+
+static node_t *
+rb_single(node_t *root, int dir)
+{
+ node_t *save = root->link[!dir];
+
+ root->link[!dir] = save->link[dir];
+ save->link[dir] = root;
+
+ RED(root) = 1;
+ RED(save) = 0;
+ return save;
+}
+
+static node_t *
+rb_double(node_t *root, int dir)
+{
+ root->link[!dir] = rb_single(root->link[!dir], !dir);
+ return rb_single(root, dir);
+}
+
+#define rb_new_node(key, value) ct_new_node(key, value, 1)
+
+extern int
+rb_insert(node_t **rootaddr, PyObject *key, PyObject *value)
+{
+ node_t *root = *rootaddr;
+
+ if (root == NULL) {
+ /*
+ We have an empty tree; attach the
+ new node directly to the root
+ */
+ root = rb_new_node(key, value);
+ if (root == NULL)
+ return -1; // got no memory
+ }
+ else {
+ node_t head; /* False tree root */
+ node_t *g, *t; /* Grandparent & parent */
+ node_t *p, *q; /* Iterator & parent */
+ int dir = 0;
+ int last = 0;
+ int new_node = 0;
+
+ /* Set up our helpers */
+ t = &head;
+ g = NULL;
+ p = NULL;
+ RIGHT_NODE(t) = root;
+ LEFT_NODE(t) = NULL;
+ q = RIGHT_NODE(t);
+
+ /* Search down the tree for a place to insert */
+ for (;;) {
+ int cmp_res;
+ if (q == NULL) {
+ /* Insert a new node at the first null link */
+ q = rb_new_node(key, value);
+ p->link[dir] = q;
+ new_node = 1;
+ if (q == NULL)
+ return -1; // get no memory
+ }
+ else if (is_red(q->link[0]) && is_red(q->link[1])) {
+ /* Simple red violation: color flip */
+ RED(q) = 1;
+ RED(q->link[0]) = 0;
+ RED(q->link[1]) = 0;
+ }
+
+ if (is_red(q) && is_red(p)) {
+ /* Hard red violation: rotations necessary */
+ int dir2 = (t->link[1] == g);
+
+ if (q == p->link[last])
+ t->link[dir2] = rb_single(g, !last);
+ else
+ t->link[dir2] = rb_double(g, !last);
+ }
+
+ /* Stop working if we inserted a new node. */
+ if (new_node)
+ break;
+
+ cmp_res = ct_compare(KEY(q), key);
+ if (cmp_res == 0) { /* key exists? */
+ Py_XDECREF(VALUE(q)); /* release old value object */
+ VALUE(q) = value; /* set new value object */
+ Py_INCREF(value); /* take new value object */
+ return 0;
+ }
+ last = dir;
+ dir = (cmp_res < 0);
+
+ /* Move the helpers down */
+ if (g != NULL)
+ t = g;
+
+ g = p;
+ p = q;
+ q = q->link[dir];
+ }
+ /* Update the root (it may be different) */
+ root = head.link[1];
+ }
+
+ /* Make the root black for simplified logic */
+ RED(root) = 0;
+ (*rootaddr) = root;
+ return 1;
+}
+
+extern int
+rb_remove(node_t **rootaddr, PyObject *key)
+{
+ node_t *root = *rootaddr;
+
+ node_t head = { { NULL } }; /* False tree root */
+ node_t *q, *p, *g; /* Helpers */
+ node_t *f = NULL; /* Found item */
+ int dir = 1;
+
+ if (root == NULL)
+ return 0;
+
+ /* Set up our helpers */
+ q = &head;
+ g = p = NULL;
+ RIGHT_NODE(q) = root;
+
+ /*
+ Search and push a red node down
+ to fix red violations as we go
+ */
+ while (q->link[dir] != NULL) {
+ int last = dir;
+ int cmp_res;
+
+ /* Move the helpers down */
+ g = p, p = q;
+ q = q->link[dir];
+
+ cmp_res = ct_compare(KEY(q), key);
+
+ dir = cmp_res < 0;
+
+ /*
+ Save the node with matching data and keep
+ going; we'll do removal tasks at the end
+ */
+ if (cmp_res == 0)
+ f = q;
+
+ /* Push the red node down with rotations and color flips */
+ if (!is_red(q) && !is_red(q->link[dir])) {
+ if (is_red(q->link[!dir]))
+ p = p->link[last] = rb_single(q, dir);
+ else if (!is_red(q->link[!dir])) {
+ node_t *s = p->link[!last];
+
+ if (s != NULL) {
+ if (!is_red(s->link[!last]) &&
+ !is_red(s->link[last])) {
+ /* Color flip */
+ RED(p) = 0;
+ RED(s) = 1;
+ RED(q) = 1;
+ }
+ else {
+ int dir2 = g->link[1] == p;
+
+ if (is_red(s->link[last]))
+ g->link[dir2] = rb_double(p, last);
+ else if (is_red(s->link[!last]))
+ g->link[dir2] = rb_single(p, last);
+
+ /* Ensure correct coloring */
+ RED(q) = RED(g->link[dir2]) = 1;
+ RED(g->link[dir2]->link[0]) = 0;
+ RED(g->link[dir2]->link[1]) = 0;
+ }
+ }
+ }
+ }
+ }
+
+ /* Replace and remove the saved node */
+ if (f != NULL) {
+ ct_swap_data(f, q);
+ p->link[p->link[1] == q] = q->link[q->link[0] == NULL];
+ ct_delete_node(q);
+ }
+
+ /* Update the root (it may be different) */
+ root = head.link[1];
+
+ /* Make the root black for simplified logic */
+ if (root != NULL)
+ RED(root) = 0;
+ *rootaddr = root;
+ return (f != NULL);
+}
+
+#define avl_new_node(key, value) ct_new_node(key, value, 0)
+#define height(p) ((p) == NULL ? -1 : (p)->xdata)
+#define avl_max(a, b) ((a) > (b) ? (a) : (b))
+
+static node_t *
+avl_single(node_t *root, int dir)
+{
+ node_t *save = root->link[!dir];
+ int rlh, rrh, slh;
+
+ /* Rotate */
+ root->link[!dir] = save->link[dir];
+ save->link[dir] = root;
+
+ /* Update balance factors */
+ rlh = height(root->link[0]);
+ rrh = height(root->link[1]);
+ slh = height(save->link[!dir]);
+
+ BALANCE(root) = avl_max(rlh, rrh) + 1;
+ BALANCE(save) = avl_max(slh, BALANCE(root)) + 1;
+
+ return save;
+}
+
+static node_t *
+avl_double(node_t *root, int dir)
+{
+ root->link[!dir] = avl_single(root->link[!dir], !dir);
+ return avl_single(root, dir);
+}
+
+extern int
+avl_insert(node_t **rootaddr, PyObject *key, PyObject *value)
+{
+ node_t *root = *rootaddr;
+
+ if (root == NULL) {
+ root = avl_new_node(key, value);
+ if (root == NULL)
+ return -1; // got no memory
+ }
+ else {
+ node_t *it, *up[32];
+ int upd[32], top = 0;
+ int done = 0;
+ int cmp_res;
+
+ it = root;
+ /* Search for an empty link, save the path */
+ for (;;) {
+ /* Push direction and node onto stack */
+ cmp_res = ct_compare(KEY(it), key);
+ if (cmp_res == 0) {
+ Py_XDECREF(VALUE(it)); // release old value object
+ VALUE(it) = value; // set new value object
+ Py_INCREF(value); // take new value object
+ return 0;
+ }
+ // upd[top] = it->data < data;
+ upd[top] = (cmp_res < 0);
+ up[top++] = it;
+
+ if (it->link[upd[top - 1]] == NULL)
+ break;
+ it = it->link[upd[top - 1]];
+ }
+
+ /* Insert a new node at the bottom of the tree */
+ it->link[upd[top - 1]] = avl_new_node(key, value);
+ if (it->link[upd[top - 1]] == NULL)
+ return -1; // got no memory
+
+ /* Walk back up the search path */
+ while (--top >= 0 && !done) {
+ // int dir = (cmp_res < 0);
+ int lh, rh, max;
+
+ cmp_res = ct_compare(KEY(up[top]), key);
+
+ lh = height(up[top]->link[upd[top]]);
+ rh = height(up[top]->link[!upd[top]]);
+
+ /* Terminate or rebalance as necessary */
+ if (lh - rh == 0)
+ done = 1;
+ if (lh - rh >= 2) {
+ node_t *a = up[top]->link[upd[top]]->link[upd[top]];
+ node_t *b = up[top]->link[upd[top]]->link[!upd[top]];
+
+ if (height( a ) >= height( b ))
+ up[top] = avl_single(up[top], !upd[top]);
+ else
+ up[top] = avl_double(up[top], !upd[top]);
+
+ /* Fix parent */
+ if (top != 0)
+ up[top - 1]->link[upd[top - 1]] = up[top];
+ else
+ root = up[0];
+ done = 1;
+ }
+ /* Update balance factors */
+ lh = height(up[top]->link[upd[top]]);
+ rh = height(up[top]->link[!upd[top]]);
+ max = avl_max(lh, rh);
+ BALANCE(up[top]) = max + 1;
+ }
+ }
+ (*rootaddr) = root;
+ return 1;
+}
+
+extern int
+avl_remove(node_t **rootaddr, PyObject *key)
+{
+ node_t *root = *rootaddr;
+ int cmp_res;
+
+ if (root != NULL) {
+ node_t *it, *up[32];
+ int upd[32], top = 0;
+
+ it = root;
+ for (;;) {
+ /* Terminate if not found */
+ if (it == NULL)
+ return 0;
+ cmp_res = ct_compare(KEY(it), key);
+ if (cmp_res == 0)
+ break;
+
+ /* Push direction and node onto stack */
+ upd[top] = (cmp_res < 0);
+ up[top++] = it;
+ it = it->link[upd[top - 1]];
+ }
+
+ /* Remove the node */
+ if (it->link[0] == NULL ||
+ it->link[1] == NULL) {
+ /* Which child is not null? */
+ int dir = it->link[0] == NULL;
+
+ /* Fix parent */
+ if (top != 0)
+ up[top - 1]->link[upd[top - 1]] = it->link[dir];
+ else
+ root = it->link[dir];
+
+ ct_delete_node(it);
+ }
+ else {
+ /* Find the inorder successor */
+ node_t *heir = it->link[1];
+
+ /* Save the path */
+ upd[top] = 1;
+ up[top++] = it;
+
+ while ( heir->link[0] != NULL ) {
+ upd[top] = 0;
+ up[top++] = heir;
+ heir = heir->link[0];
+ }
+ /* Swap data */
+ ct_swap_data(it, heir);
+ /* Unlink successor and fix parent */
+ up[top - 1]->link[up[top - 1] == it] = heir->link[1];
+ ct_delete_node(heir);
+ }
+
+ /* Walk back up the search path */
+ while (--top >= 0) {
+ int lh = height(up[top]->link[upd[top]]);
+ int rh = height(up[top]->link[!upd[top]]);
+ int max = avl_max(lh, rh);
+
+ /* Update balance factors */
+ BALANCE(up[top]) = max + 1;
+
+ /* Terminate or rebalance as necessary */
+ if (lh - rh == -1)
+ break;
+ if (lh - rh <= -2) {
+ node_t *a = up[top]->link[!upd[top]]->link[upd[top]];
+ node_t *b = up[top]->link[!upd[top]]->link[!upd[top]];
+
+ if (height(a) <= height(b))
+ up[top] = avl_single(up[top], upd[top]);
+ else
+ up[top] = avl_double(up[top], upd[top]);
+
+ /* Fix parent */
+ if (top != 0)
+ up[top - 1]->link[upd[top - 1]] = up[top];
+ else
+ root = up[0];
+ }
+ }
+ }
+ (*rootaddr) = root;
+ return 1;
+}
+
+extern node_t *
+ct_succ_node(node_t *root, PyObject *key)
+{
+ node_t *succ = NULL;
+ node_t *node = root;
+ int cval;
+
+ while (node != NULL) {
+ cval = ct_compare(key, KEY(node));
+ if (cval == 0)
+ break;
+ else if (cval < 0) {
+ if ((succ == NULL) ||
+ (ct_compare(KEY(node), KEY(succ)) < 0))
+ succ = node;
+ node = LEFT_NODE(node);
+ } else
+ node = RIGHT_NODE(node);
+ }
+ if (node == NULL)
+ return NULL;
+ /* found node of key */
+ if (RIGHT_NODE(node) != NULL) {
+ /* find smallest node of right subtree */
+ node = RIGHT_NODE(node);
+ while (LEFT_NODE(node) != NULL)
+ node = LEFT_NODE(node);
+ if (succ == NULL)
+ succ = node;
+ else if (ct_compare(KEY(node), KEY(succ)) < 0)
+ succ = node;
+ }
+ return succ;
+}
+
+extern node_t *
+ct_prev_node(node_t *root, PyObject *key)
+{
+ node_t *prev = NULL;
+ node_t *node = root;
+ int cval;
+
+ while (node != NULL) {
+ cval = ct_compare(key, KEY(node));
+ if (cval == 0)
+ break;
+ else if (cval < 0)
+ node = LEFT_NODE(node);
+ else {
+ if ((prev == NULL) || (ct_compare(KEY(node), KEY(prev)) > 0))
+ prev = node;
+ node = RIGHT_NODE(node);
+ }
+ }
+ if (node == NULL) /* stay at dead end (None) */
+ return NULL;
+ /* found node of key */
+ if (LEFT_NODE(node) != NULL) {
+ /* find biggest node of left subtree */
+ node = LEFT_NODE(node);
+ while (RIGHT_NODE(node) != NULL)
+ node = RIGHT_NODE(node);
+ if (prev == NULL)
+ prev = node;
+ else if (ct_compare(KEY(node), KEY(prev)) > 0)
+ prev = node;
+ }
+ return prev;
+}
+
+extern node_t *
+ct_floor_node(node_t *root, PyObject *key)
+{
+ node_t *prev = NULL;
+ node_t *node = root;
+ int cval;
+
+ while (node != NULL) {
+ cval = ct_compare(key, KEY(node));
+ if (cval == 0)
+ return node;
+ else if (cval < 0)
+ node = LEFT_NODE(node);
+ else {
+ if ((prev == NULL) || (ct_compare(KEY(node), KEY(prev)) > 0))
+ prev = node;
+ node = RIGHT_NODE(node);
+ }
+ }
+ return prev;
+}
+
+extern node_t *
+ct_ceiling_node(node_t *root, PyObject *key)
+{
+ node_t *succ = NULL;
+ node_t *node = root;
+ int cval;
+
+ while (node != NULL) {
+ cval = ct_compare(key, KEY(node));
+ if (cval == 0)
+ return node;
+ else if (cval < 0) {
+ if ((succ == NULL) ||
+ (ct_compare(KEY(node), KEY(succ)) < 0))
+ succ = node;
+ node = LEFT_NODE(node);
+ } else
+ node = RIGHT_NODE(node);
+ }
+ return succ;
+}
+
+extern int
+ct_index_of(node_t *root, PyObject *key)
+/*
+get index of item <key>, returns -1 if key not found.
+*/
+{
+ node_t *node = root;
+ int index = 0;
+ int go_down = 1;
+ node_stack_t *stack;
+ stack = stack_init(32);
+
+ for (;;) {
+ if ((LEFT_NODE(node) != NULL) && go_down) {
+ stack_push(stack, node);
+ node = LEFT_NODE(node);
+ }
+ else {
+ if (ct_compare(KEY(node), key) == 0) {
+ stack_delete(stack);
+ return index;
+ }
+ index++;
+ if (RIGHT_NODE(node) != NULL) {
+ node = RIGHT_NODE(node);
+ go_down = 1;
+ }
+ else {
+ if (stack_is_empty(stack)) {
+ stack_delete(stack);
+ return -1;
+ }
+ node = stack_pop(stack);
+ go_down = 0;
+ }
+ }
+ }
+}
+
+extern node_t *
+ct_node_at(node_t *root, int index)
+{
+/*
+root -- root node of tree
+index -- index of wanted node
+
+return NULL if index out of range
+*/
+ node_t *node = root;
+ int counter = 0;
+ int go_down = 1;
+ node_stack_t *stack;
+
+ if (index < 0) return NULL;
+
+ stack = stack_init(32);
+
+ for(;;) {
+ if ((LEFT_NODE(node) != NULL) && go_down) {
+ stack_push(stack, node);
+ node = LEFT_NODE(node);
+ }
+ else {
+ if (counter == index) {
+ /* reached wanted index */
+ stack_delete(stack);
+ return node;
+ }
+ counter++;
+ if (RIGHT_NODE(node) != NULL) {
+ node = RIGHT_NODE(node);
+ go_down = 1;
+ }
+ else {
+ if (stack_is_empty(stack)) { /* index out of range */
+ stack_delete(stack);
+ return NULL;
+ }
+ node = stack_pop(stack);
+ go_down = 0;
+ }
+ }
+ }
+}
diff --git a/chromium/third_party/bintrees/bintrees/ctrees.h b/chromium/third_party/bintrees/bintrees/ctrees.h
new file mode 100644
index 00000000000..17afe72022c
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/ctrees.h
@@ -0,0 +1,51 @@
+/*
+ * ctrees.h
+ *
+ * Author: mozman
+ * Copyright (c) 2010-2013 by Manfred Moitzi
+ * License: MIT-License
+ */
+
+#ifndef __CTREES_H
+#define __CTREES_H
+
+#include <Python.h>
+
+typedef struct tree_node node_t;
+
+struct tree_node {
+ node_t *link[2];
+ PyObject *key;
+ PyObject *value;
+ int xdata;
+};
+
+typedef node_t* nodeptr;
+
+/* common binary tree functions */
+void ct_delete_tree(node_t *root);
+int ct_compare(PyObject *key1, PyObject *key2);
+PyObject *ct_get_item(node_t *root, PyObject *key);
+node_t *ct_find_node(node_t *root, PyObject *key);
+node_t *ct_succ_node(node_t *root, PyObject *key);
+node_t *ct_prev_node(node_t *root, PyObject *key);
+node_t *ct_max_node(node_t *root);
+node_t *ct_min_node(node_t *root);
+node_t *ct_floor_node(node_t *root, PyObject *key);
+node_t *ct_ceiling_node(node_t *root, PyObject *key);
+int ct_index_of(node_t *root, PyObject *key);
+node_t *ct_node_at(node_t *root, int index);
+
+/* unbalanced binary tree */
+int ct_bintree_insert(node_t **root, PyObject *key, PyObject *value);
+int ct_bintree_remove(node_t **root, PyObject *key);
+
+/* avl-tree functions */
+int avl_insert(node_t **root, PyObject *key, PyObject *value);
+int avl_remove(node_t **root, PyObject *key);
+
+/* rb-tree functions */
+int rb_insert(node_t **root, PyObject *key, PyObject *value);
+int rb_remove(node_t **root, PyObject *key);
+
+#endif
diff --git a/chromium/third_party/bintrees/bintrees/ctrees.pxd b/chromium/third_party/bintrees/bintrees/ctrees.pxd
new file mode 100644
index 00000000000..c96a2ca27a2
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/ctrees.pxd
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Created: 08.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+cdef extern from "ctrees.h":
+ ctypedef struct PyObject:
+ pass
+
+ ctypedef struct node_t:
+ node_t *link[2]
+ PyObject *key
+ PyObject *value
+
+ int ct_compare(object key1, object key2)
+ void ct_delete_tree(node_t *root)
+ node_t *ct_find_node(node_t *root, object key)
+ PyObject *ct_get_item(node_t *root, object key)
+ node_t *ct_max_node(node_t *root)
+ node_t *ct_min_node(node_t *root)
+ node_t *ct_succ_node(node_t *root, object key)
+ node_t *ct_prev_node(node_t *root, object key)
+ node_t *ct_floor_node(node_t *root, object key)
+ node_t *ct_ceiling_node(node_t *root, object key)
+ int ct_index_of(node_t *root, object key)
+ node_t *ct_node_at(node_t *root, int index)
+
+ # binary-tree functions
+ int ct_bintree_insert(node_t **root, object key, object value)
+ int ct_bintree_remove(node_t **root, object key)
+ # avl-tree functions
+ int avl_insert(node_t **root, object key, object value)
+ int avl_remove(node_t **root, object key)
+ # rb-tree functions
+ int rb_insert(node_t **root, object key, object value)
+ int rb_remove(node_t **root, object key) \ No newline at end of file
diff --git a/chromium/third_party/bintrees/bintrees/cwalker.c b/chromium/third_party/bintrees/bintrees/cwalker.c
new file mode 100644
index 00000000000..0779b4d5dfd
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/cwalker.c
@@ -0,0 +1,3799 @@
+/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+ #error Python headers needed to compile C extensions, please install development version of Python.
+#elif PY_VERSION_HEX < 0x02040000
+ #error Cython requires Python 2.4+.
+#else
+#include <stddef.h> /* For offsetof */
+#ifndef offsetof
+#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+ #ifndef __stdcall
+ #define __stdcall
+ #endif
+ #ifndef __cdecl
+ #define __cdecl
+ #endif
+ #ifndef __fastcall
+ #define __fastcall
+ #endif
+#endif
+#ifndef DL_IMPORT
+ #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+ #define DL_EXPORT(t) t
+#endif
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef Py_HUGE_VAL
+ #define Py_HUGE_VAL HUGE_VAL
+#endif
+#ifdef PYPY_VERSION
+#define CYTHON_COMPILING_IN_PYPY 1
+#define CYTHON_COMPILING_IN_CPYTHON 0
+#else
+#define CYTHON_COMPILING_IN_PYPY 0
+#define CYTHON_COMPILING_IN_CPYTHON 1
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+ #define PY_SSIZE_T_MAX INT_MAX
+ #define PY_SSIZE_T_MIN INT_MIN
+ #define PY_FORMAT_SIZE_T ""
+ #define CYTHON_FORMAT_SSIZE_T ""
+ #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+ #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
+ #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
+ (PyErr_Format(PyExc_TypeError, \
+ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
+ (PyObject*)0))
+ #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
+ !PyComplex_Check(o))
+ #define PyIndex_Check __Pyx_PyIndex_Check
+ #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
+ #define __PYX_BUILD_PY_SSIZE_T "i"
+#else
+ #define __PYX_BUILD_PY_SSIZE_T "n"
+ #define CYTHON_FORMAT_SSIZE_T "z"
+ #define __Pyx_PyIndex_Check PyIndex_Check
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+ #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+ #define PyVarObject_HEAD_INIT(type, size) \
+ PyObject_HEAD_INIT(type) size,
+ #define PyType_Modified(t)
+ typedef struct {
+ void *buf;
+ PyObject *obj;
+ Py_ssize_t len;
+ Py_ssize_t itemsize;
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets;
+ void *internal;
+ } Py_buffer;
+ #define PyBUF_SIMPLE 0
+ #define PyBUF_WRITABLE 0x0001
+ #define PyBUF_FORMAT 0x0004
+ #define PyBUF_ND 0x0008
+ #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+ #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+ #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+ #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+ #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
+ #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
+ #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
+ typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
+ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
+#endif
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#else
+ #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#endif
+#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
+ #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define Py_TPFLAGS_CHECKTYPES 0
+ #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+ #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
+ #define CYTHON_PEP393_ENABLED 1
+ #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \
+ 0 : _PyUnicode_Ready((PyObject *)(op)))
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
+ #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
+#else
+ #define CYTHON_PEP393_ENABLED 0
+ #define __Pyx_PyUnicode_READY(op) (0)
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
+ #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBaseString_Type PyUnicode_Type
+ #define PyStringObject PyUnicodeObject
+ #define PyString_Type PyUnicode_Type
+ #define PyString_Check PyUnicode_Check
+ #define PyString_CheckExact PyUnicode_CheckExact
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PyBytesObject PyStringObject
+ #define PyBytes_Type PyString_Type
+ #define PyBytes_Check PyString_Check
+ #define PyBytes_CheckExact PyString_CheckExact
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+ #define PyBytes_FromFormat PyString_FromFormat
+ #define PyBytes_DecodeEscape PyString_DecodeEscape
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_AS_STRING PyString_AS_STRING
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
+ #define PyBytes_Repr PyString_Repr
+ #define PyBytes_Concat PyString_Concat
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+#ifndef PySet_CheckExact
+ #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
+#endif
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+#if PY_MAJOR_VERSION >= 3
+ #define PyIntObject PyLongObject
+ #define PyInt_Type PyLong_Type
+ #define PyInt_Check(op) PyLong_Check(op)
+ #define PyInt_CheckExact(op) PyLong_CheckExact(op)
+ #define PyInt_FromString PyLong_FromString
+ #define PyInt_FromUnicode PyLong_FromUnicode
+ #define PyInt_FromLong PyLong_FromLong
+ #define PyInt_FromSize_t PyLong_FromSize_t
+ #define PyInt_FromSsize_t PyLong_FromSsize_t
+ #define PyInt_AsLong PyLong_AsLong
+ #define PyInt_AS_LONG PyLong_AS_LONG
+ #define PyInt_AsSsize_t PyLong_AsSsize_t
+ #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
+ #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBoolObject PyLongObject
+#endif
+#if PY_VERSION_HEX < 0x03020000
+ typedef long Py_hash_t;
+ #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+ #define __Pyx_PyInt_AsHash_t PyInt_AsLong
+#else
+ #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+ #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
+#endif
+#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
+ #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
+ #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
+#else
+ #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
+ #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
+#else
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_NAMESTR(n) ((char *)(n))
+ #define __Pyx_DOCSTR(n) ((char *)(n))
+#else
+ #define __Pyx_NAMESTR(n) (n)
+ #define __Pyx_DOCSTR(n) (n)
+#endif
+
+
+#if PY_MAJOR_VERSION >= 3
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
+#else
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
+#endif
+
+#ifndef __PYX_EXTERN_C
+ #ifdef __cplusplus
+ #define __PYX_EXTERN_C extern "C"
+ #else
+ #define __PYX_EXTERN_C extern
+ #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#define __PYX_HAVE__bintrees__cwalker
+#define __PYX_HAVE_API__bintrees__cwalker
+#include "ctrees.h"
+#include "stack.h"
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#ifdef PYREX_WITHOUT_ASSERTIONS
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+
+/* inline attribute */
+#ifndef CYTHON_INLINE
+ #if defined(__GNUC__)
+ #define CYTHON_INLINE __inline__
+ #elif defined(_MSC_VER)
+ #define CYTHON_INLINE __inline
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_INLINE inline
+ #else
+ #define CYTHON_INLINE
+ #endif
+#endif
+
+/* unused attribute */
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+#endif
+
+typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
+
+
+/* Type Conversion Predeclarations */
+
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
+
+#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
+
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+#else
+#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
+#endif
+#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
+
+#ifdef __GNUC__
+ /* Test for GCC > 2.95 */
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
+ #define likely(x) __builtin_expect(!!(x), 1)
+ #define unlikely(x) __builtin_expect(!!(x), 0)
+ #else /* __GNUC__ > 2 ... */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+ #endif /* __GNUC__ > 2 ... */
+#else /* __GNUC__ */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+#endif /* __GNUC__ */
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+ "cwalker.pyx",
+};
+
+/*--- Type declarations ---*/
+struct __pyx_obj_8bintrees_7cwalker_cWalker;
+
+/* "bintrees\cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+struct __pyx_obj_8bintrees_7cwalker_cWalker {
+ PyObject_HEAD
+ struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab;
+ node_t *node;
+ node_t *root;
+ node_stack_t *stack;
+};
+
+
+
+/* "bintrees\cwalker.pyx":14
+ * from ctrees cimport *
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * def __cinit__(self):
+ * self.root = NULL
+ */
+
+struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker {
+ void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *);
+ PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+};
+static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker;
+#ifndef CYTHON_REFNANNY
+ #define CYTHON_REFNANNY 0
+#endif
+#if CYTHON_REFNANNY
+ typedef struct {
+ void (*INCREF)(void*, PyObject*, int);
+ void (*DECREF)(void*, PyObject*, int);
+ void (*GOTREF)(void*, PyObject*, int);
+ void (*GIVEREF)(void*, PyObject*, int);
+ void* (*SetupContext)(const char*, int, const char*);
+ void (*FinishContext)(void**);
+ } __Pyx_RefNannyAPIStruct;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
+ #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+#ifdef WITH_THREAD
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ if (acquire_gil) { \
+ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ PyGILState_Release(__pyx_gilstate_save); \
+ } else { \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ }
+#else
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+#endif
+ #define __Pyx_RefNannyFinishContext() \
+ __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+ #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+ #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+ #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+ #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+ #define __Pyx_RefNannyDeclarations
+ #define __Pyx_RefNannySetupContext(name, acquire_gil)
+ #define __Pyx_RefNannyFinishContext()
+ #define __Pyx_INCREF(r) Py_INCREF(r)
+ #define __Pyx_DECREF(r) Py_DECREF(r)
+ #define __Pyx_GOTREF(r)
+ #define __Pyx_GIVEREF(r)
+ #define __Pyx_XINCREF(r) Py_XINCREF(r)
+ #define __Pyx_XDECREF(r) Py_XDECREF(r)
+ #define __Pyx_XGOTREF(r)
+ #define __Pyx_XGIVEREF(r)
+#endif /* CYTHON_REFNANNY */
+#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
+#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+
+static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
+
+static void __Pyx_WriteUnraisable(const char *name, int clineno,
+ int lineno, const char *filename); /*proto*/
+
+static int __Pyx_check_binary_version(void);
+
+static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
+
+typedef struct {
+ int code_line;
+ PyCodeObject* code_object;
+} __Pyx_CodeObjectCacheEntry;
+struct __Pyx_CodeObjectCache {
+ int count;
+ int max_count;
+ __Pyx_CodeObjectCacheEntry* entries;
+};
+static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
+static PyCodeObject *__pyx_find_code_object(int code_line);
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
+
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+
+/* Module declarations from 'bintrees.ctrees' */
+
+/* Module declarations from 'bintrees.stack' */
+
+/* Module declarations from 'bintrees.cwalker' */
+static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0;
+#define __Pyx_MODULE_NAME "bintrees.cwalker"
+int __pyx_module_is_main_bintrees__cwalker = 0;
+
+/* Implementation of 'bintrees.cwalker' */
+static PyObject *__pyx_builtin_property;
+static PyObject *__pyx_builtin_IndexError;
+static PyObject *__pyx_builtin_KeyError;
+static int __pyx_pf_8bintrees_7cwalker_7cWalker___cinit__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static void __pyx_pf_8bintrees_7cwalker_7cWalker_2__dealloc__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_4reset(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_6key(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_8value(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_10item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_12is_valid(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_14goto(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_16push(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_18pop(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_20stack_is_empty(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_22goto_leaf(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_24has_child(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_26down(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_28go_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_30go_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_32has_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_34has_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_36succ_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_38prev_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_40floor_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_42ceiling_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static char __pyx_k_1[] = "pop(): stack is empty";
+static char __pyx_k__key[] = "key";
+static char __pyx_k__pop[] = "pop";
+static char __pyx_k__item[] = "item";
+static char __pyx_k__push[] = "push";
+static char __pyx_k__reset[] = "reset";
+static char __pyx_k__value[] = "value";
+static char __pyx_k__KeyError[] = "KeyError";
+static char __pyx_k____main__[] = "__main__";
+static char __pyx_k____test__[] = "__test__";
+static char __pyx_k__is_valid[] = "is_valid";
+static char __pyx_k__property[] = "property";
+static char __pyx_k__IndexError[] = "IndexError";
+static PyObject *__pyx_kp_s_1;
+static PyObject *__pyx_n_s__IndexError;
+static PyObject *__pyx_n_s__KeyError;
+static PyObject *__pyx_n_s____main__;
+static PyObject *__pyx_n_s____test__;
+static PyObject *__pyx_n_s__is_valid;
+static PyObject *__pyx_n_s__item;
+static PyObject *__pyx_n_s__key;
+static PyObject *__pyx_n_s__pop;
+static PyObject *__pyx_n_s__property;
+static PyObject *__pyx_n_s__push;
+static PyObject *__pyx_n_s__reset;
+static PyObject *__pyx_n_s__value;
+static PyObject *__pyx_k_tuple_2;
+
+/* Python wrapper */
+static int __pyx_pw_8bintrees_7cwalker_7cWalker_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_8bintrees_7cwalker_7cWalker_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+ if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
+ if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker___cinit__(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":15
+ *
+ * cdef class cWalker:
+ * def __cinit__(self): # <<<<<<<<<<<<<<
+ * self.root = NULL
+ * self.node = NULL
+ */
+
+static int __pyx_pf_8bintrees_7cwalker_7cWalker___cinit__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__cinit__", 0);
+
+ /* "bintrees\cwalker.pyx":16
+ * cdef class cWalker:
+ * def __cinit__(self):
+ * self.root = NULL # <<<<<<<<<<<<<<
+ * self.node = NULL
+ * self.stack = stack_init(MAXSTACK)
+ */
+ __pyx_v_self->root = NULL;
+
+ /* "bintrees\cwalker.pyx":17
+ * def __cinit__(self):
+ * self.root = NULL
+ * self.node = NULL # <<<<<<<<<<<<<<
+ * self.stack = stack_init(MAXSTACK)
+ *
+ */
+ __pyx_v_self->node = NULL;
+
+ /* "bintrees\cwalker.pyx":18
+ * self.root = NULL
+ * self.node = NULL
+ * self.stack = stack_init(MAXSTACK) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __pyx_v_self->stack = stack_init(32);
+
+ __pyx_r = 0;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static void __pyx_pw_8bintrees_7cwalker_7cWalker_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_8bintrees_7cwalker_7cWalker_3__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_pf_8bintrees_7cwalker_7cWalker_2__dealloc__(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "bintrees\cwalker.pyx":20
+ * self.stack = stack_init(MAXSTACK)
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * stack_delete(self.stack)
+ *
+ */
+
+static void __pyx_pf_8bintrees_7cwalker_7cWalker_2__dealloc__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
+
+ /* "bintrees\cwalker.pyx":21
+ *
+ * def __dealloc__(self):
+ * stack_delete(self.stack) # <<<<<<<<<<<<<<
+ *
+ * cdef void set_tree(self, node_t *root):
+ */
+ stack_delete(__pyx_v_self->stack);
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "bintrees\cwalker.pyx":23
+ * stack_delete(self.stack)
+ *
+ * cdef void set_tree(self, node_t *root): # <<<<<<<<<<<<<<
+ * self.root = root
+ * self.reset()
+ */
+
+static void __pyx_f_8bintrees_7cwalker_7cWalker_set_tree(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, node_t *__pyx_v_root) {
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("set_tree", 0);
+
+ /* "bintrees\cwalker.pyx":24
+ *
+ * cdef void set_tree(self, node_t *root):
+ * self.root = root # <<<<<<<<<<<<<<
+ * self.reset()
+ *
+ */
+ __pyx_v_self->root = __pyx_v_root;
+
+ /* "bintrees\cwalker.pyx":25
+ * cdef void set_tree(self, node_t *root):
+ * self.root = root
+ * self.reset() # <<<<<<<<<<<<<<
+ *
+ * cpdef reset(self):
+ */
+ __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->reset(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_WriteUnraisable("bintrees.cwalker.cWalker.set_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "bintrees\cwalker.pyx":27
+ * self.reset()
+ *
+ * cpdef reset(self): # <<<<<<<<<<<<<<
+ * stack_reset(self.stack)
+ * self.node = self.root
+ */
+
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_5reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_f_8bintrees_7cwalker_7cWalker_reset(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_skip_dispatch) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ node_t *__pyx_t_3;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("reset", 0);
+ /* Check if called by wrapper */
+ if (unlikely(__pyx_skip_dispatch)) ;
+ /* Check if overriden in Python */
+ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_5reset)) {
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ goto __pyx_L0;
+ }
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ }
+
+ /* "bintrees\cwalker.pyx":28
+ *
+ * cpdef reset(self):
+ * stack_reset(self.stack) # <<<<<<<<<<<<<<
+ * self.node = self.root
+ *
+ */
+ stack_reset(__pyx_v_self->stack);
+
+ /* "bintrees\cwalker.pyx":29
+ * cpdef reset(self):
+ * stack_reset(self.stack)
+ * self.node = self.root # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ __pyx_t_3 = __pyx_v_self->root;
+ __pyx_v_self->node = __pyx_t_3;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_5reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_5reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("reset (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_4reset(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":27
+ * self.reset()
+ *
+ * cpdef reset(self): # <<<<<<<<<<<<<<
+ * stack_reset(self.stack)
+ * self.node = self.root
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_4reset(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("reset", 0);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->reset(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_7key(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_7key(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("key (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_6key(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":32
+ *
+ * @property
+ * def key(self): # <<<<<<<<<<<<<<
+ * return <object> self.node.key
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_6key(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("key", 0);
+
+ /* "bintrees\cwalker.pyx":33
+ * @property
+ * def key(self):
+ * return <object> self.node.key # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key));
+ __pyx_r = ((PyObject *)__pyx_v_self->node->key);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_9value(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_9value(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("value (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_8value(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":36
+ *
+ * @property
+ * def value(self): # <<<<<<<<<<<<<<
+ * return <object> self.node.value
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_8value(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("value", 0);
+
+ /* "bintrees\cwalker.pyx":37
+ * @property
+ * def value(self):
+ * return <object> self.node.value # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value));
+ __pyx_r = ((PyObject *)__pyx_v_self->node->value);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_11item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_11item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_10item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":40
+ *
+ * @property
+ * def item(self): # <<<<<<<<<<<<<<
+ * return (<object>self.node.key, <object>self.node.value)
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_10item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("item", 0);
+
+ /* "bintrees\cwalker.pyx":41
+ * @property
+ * def item(self):
+ * return (<object>self.node.key, <object>self.node.value) # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value));
+ PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self->node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value));
+ __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_13is_valid(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_13is_valid(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("is_valid (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_12is_valid(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":44
+ *
+ * @property
+ * def is_valid(self): # <<<<<<<<<<<<<<
+ * return self.node != NULL
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_12is_valid(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("is_valid", 0);
+
+ /* "bintrees\cwalker.pyx":45
+ * @property
+ * def is_valid(self):
+ * return self.node != NULL # <<<<<<<<<<<<<<
+ *
+ * def goto(self, key):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->node != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.is_valid", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_15goto(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_15goto(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("goto (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_14goto(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":47
+ * return self.node != NULL
+ *
+ * def goto(self, key): # <<<<<<<<<<<<<<
+ * cdef int cval
+ * self.node = self.root
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_14goto(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) {
+ int __pyx_v_cval;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ node_t *__pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("goto", 0);
+
+ /* "bintrees\cwalker.pyx":49
+ * def goto(self, key):
+ * cdef int cval
+ * self.node = self.root # <<<<<<<<<<<<<<
+ * while self.node != NULL:
+ * cval = ct_compare(key, <object> self.node.key)
+ */
+ __pyx_t_1 = __pyx_v_self->root;
+ __pyx_v_self->node = __pyx_t_1;
+
+ /* "bintrees\cwalker.pyx":50
+ * cdef int cval
+ * self.node = self.root
+ * while self.node != NULL: # <<<<<<<<<<<<<<
+ * cval = ct_compare(key, <object> self.node.key)
+ * if cval == 0:
+ */
+ while (1) {
+ __pyx_t_2 = (__pyx_v_self->node != NULL);
+ if (!__pyx_t_2) break;
+
+ /* "bintrees\cwalker.pyx":51
+ * self.node = self.root
+ * while self.node != NULL:
+ * cval = ct_compare(key, <object> self.node.key) # <<<<<<<<<<<<<<
+ * if cval == 0:
+ * return True
+ */
+ __pyx_t_3 = ((PyObject *)__pyx_v_self->node->key);
+ __Pyx_INCREF(__pyx_t_3);
+ __pyx_v_cval = ct_compare(__pyx_v_key, __pyx_t_3);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+ /* "bintrees\cwalker.pyx":52
+ * while self.node != NULL:
+ * cval = ct_compare(key, <object> self.node.key)
+ * if cval == 0: # <<<<<<<<<<<<<<
+ * return True
+ * elif cval < 0:
+ */
+ __pyx_t_2 = (__pyx_v_cval == 0);
+ if (__pyx_t_2) {
+
+ /* "bintrees\cwalker.pyx":53
+ * cval = ct_compare(key, <object> self.node.key)
+ * if cval == 0:
+ * return True # <<<<<<<<<<<<<<
+ * elif cval < 0:
+ * self.node = self.node.link[0]
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+ goto __pyx_L5;
+ }
+
+ /* "bintrees\cwalker.pyx":54
+ * if cval == 0:
+ * return True
+ * elif cval < 0: # <<<<<<<<<<<<<<
+ * self.node = self.node.link[0]
+ * else:
+ */
+ __pyx_t_2 = (__pyx_v_cval < 0);
+ if (__pyx_t_2) {
+
+ /* "bintrees\cwalker.pyx":55
+ * return True
+ * elif cval < 0:
+ * self.node = self.node.link[0] # <<<<<<<<<<<<<<
+ * else:
+ * self.node = self.node.link[1]
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[0]);
+ goto __pyx_L5;
+ }
+ /*else*/ {
+
+ /* "bintrees\cwalker.pyx":57
+ * self.node = self.node.link[0]
+ * else:
+ * self.node = self.node.link[1] # <<<<<<<<<<<<<<
+ * return False
+ *
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[1]);
+ }
+ __pyx_L5:;
+ }
+
+ /* "bintrees\cwalker.pyx":58
+ * else:
+ * self.node = self.node.link[1]
+ * return False # <<<<<<<<<<<<<<
+ *
+ * cpdef push(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.goto", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":60
+ * return False
+ *
+ * cpdef push(self): # <<<<<<<<<<<<<<
+ * stack_push(self.stack, self.node)
+ *
+ */
+
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_17push(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_f_8bintrees_7cwalker_7cWalker_push(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_skip_dispatch) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("push", 0);
+ /* Check if called by wrapper */
+ if (unlikely(__pyx_skip_dispatch)) ;
+ /* Check if overriden in Python */
+ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__push); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_17push)) {
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ goto __pyx_L0;
+ }
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ }
+
+ /* "bintrees\cwalker.pyx":61
+ *
+ * cpdef push(self):
+ * stack_push(self.stack, self.node) # <<<<<<<<<<<<<<
+ *
+ * cpdef pop(self):
+ */
+ stack_push(__pyx_v_self->stack, __pyx_v_self->node);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.push", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_17push(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_17push(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("push (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_16push(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":60
+ * return False
+ *
+ * cpdef push(self): # <<<<<<<<<<<<<<
+ * stack_push(self.stack, self.node)
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_16push(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("push", 0);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->push(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.push", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":63
+ * stack_push(self.stack, self.node)
+ *
+ * cpdef pop(self): # <<<<<<<<<<<<<<
+ * if stack_is_empty(self.stack) != 0:
+ * raise IndexError('pop(): stack is empty')
+ */
+
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_19pop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_f_8bintrees_7cwalker_7cWalker_pop(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_skip_dispatch) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_t_3;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("pop", 0);
+ /* Check if called by wrapper */
+ if (unlikely(__pyx_skip_dispatch)) ;
+ /* Check if overriden in Python */
+ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_19pop)) {
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ goto __pyx_L0;
+ }
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ }
+
+ /* "bintrees\cwalker.pyx":64
+ *
+ * cpdef pop(self):
+ * if stack_is_empty(self.stack) != 0: # <<<<<<<<<<<<<<
+ * raise IndexError('pop(): stack is empty')
+ * self.node = stack_pop(self.stack)
+ */
+ __pyx_t_3 = (stack_is_empty(__pyx_v_self->stack) != 0);
+ if (__pyx_t_3) {
+
+ /* "bintrees\cwalker.pyx":65
+ * cpdef pop(self):
+ * if stack_is_empty(self.stack) != 0:
+ * raise IndexError('pop(): stack is empty') # <<<<<<<<<<<<<<
+ * self.node = stack_pop(self.stack)
+ *
+ */
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\cwalker.pyx":66
+ * if stack_is_empty(self.stack) != 0:
+ * raise IndexError('pop(): stack is empty')
+ * self.node = stack_pop(self.stack) # <<<<<<<<<<<<<<
+ *
+ * def stack_is_empty(self):
+ */
+ __pyx_v_self->node = stack_pop(__pyx_v_self->stack);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.pop", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_19pop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_19pop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("pop (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_18pop(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":63
+ * stack_push(self.stack, self.node)
+ *
+ * cpdef pop(self): # <<<<<<<<<<<<<<
+ * if stack_is_empty(self.stack) != 0:
+ * raise IndexError('pop(): stack is empty')
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_18pop(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("pop", 0);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->pop(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.pop", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_21stack_is_empty(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_21stack_is_empty(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("stack_is_empty (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_20stack_is_empty(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":68
+ * self.node = stack_pop(self.stack)
+ *
+ * def stack_is_empty(self): # <<<<<<<<<<<<<<
+ * return <bint> stack_is_empty(self.stack)
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_20stack_is_empty(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("stack_is_empty", 0);
+
+ /* "bintrees\cwalker.pyx":69
+ *
+ * def stack_is_empty(self):
+ * return <bint> stack_is_empty(self.stack) # <<<<<<<<<<<<<<
+ *
+ * def goto_leaf(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyBool_FromLong(((int)stack_is_empty(__pyx_v_self->stack))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.stack_is_empty", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_23goto_leaf(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_7cwalker_7cWalker_22goto_leaf[] = " get a leaf node ";
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_23goto_leaf(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("goto_leaf (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_22goto_leaf(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":71
+ * return <bint> stack_is_empty(self.stack)
+ *
+ * def goto_leaf(self): # <<<<<<<<<<<<<<
+ * """ get a leaf node """
+ * while self.node != NULL:
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_22goto_leaf(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ __Pyx_RefNannySetupContext("goto_leaf", 0);
+
+ /* "bintrees\cwalker.pyx":73
+ * def goto_leaf(self):
+ * """ get a leaf node """
+ * while self.node != NULL: # <<<<<<<<<<<<<<
+ * if self.node.link[0] != NULL:
+ * self.node = self.node.link[0]
+ */
+ while (1) {
+ __pyx_t_1 = (__pyx_v_self->node != NULL);
+ if (!__pyx_t_1) break;
+
+ /* "bintrees\cwalker.pyx":74
+ * """ get a leaf node """
+ * while self.node != NULL:
+ * if self.node.link[0] != NULL: # <<<<<<<<<<<<<<
+ * self.node = self.node.link[0]
+ * elif self.node.link[1] != NULL:
+ */
+ __pyx_t_1 = ((__pyx_v_self->node->link[0]) != NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\cwalker.pyx":75
+ * while self.node != NULL:
+ * if self.node.link[0] != NULL:
+ * self.node = self.node.link[0] # <<<<<<<<<<<<<<
+ * elif self.node.link[1] != NULL:
+ * self.node = self.node.link[1]
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[0]);
+ goto __pyx_L5;
+ }
+
+ /* "bintrees\cwalker.pyx":76
+ * if self.node.link[0] != NULL:
+ * self.node = self.node.link[0]
+ * elif self.node.link[1] != NULL: # <<<<<<<<<<<<<<
+ * self.node = self.node.link[1]
+ * else:
+ */
+ __pyx_t_1 = ((__pyx_v_self->node->link[1]) != NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\cwalker.pyx":77
+ * self.node = self.node.link[0]
+ * elif self.node.link[1] != NULL:
+ * self.node = self.node.link[1] # <<<<<<<<<<<<<<
+ * else:
+ * return
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[1]);
+ goto __pyx_L5;
+ }
+ /*else*/ {
+
+ /* "bintrees\cwalker.pyx":79
+ * self.node = self.node.link[1]
+ * else:
+ * return # <<<<<<<<<<<<<<
+ *
+ * def has_child(self, int direction):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ }
+ __pyx_L5:;
+ }
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_25has_child(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_25has_child(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction) {
+ int __pyx_v_direction;
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("has_child (wrapper)", 0);
+ assert(__pyx_arg_direction); {
+ __pyx_v_direction = __Pyx_PyInt_AsInt(__pyx_arg_direction); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_child", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_24has_child(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((int)__pyx_v_direction));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":81
+ * return
+ *
+ * def has_child(self, int direction): # <<<<<<<<<<<<<<
+ * return self.node.link[direction] != NULL
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_24has_child(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("has_child", 0);
+
+ /* "bintrees\cwalker.pyx":82
+ *
+ * def has_child(self, int direction):
+ * return self.node.link[direction] != NULL # <<<<<<<<<<<<<<
+ *
+ * def down(self, int direction):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->node->link[__pyx_v_direction]) != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_child", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_27down(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_27down(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction) {
+ int __pyx_v_direction;
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("down (wrapper)", 0);
+ assert(__pyx_arg_direction); {
+ __pyx_v_direction = __Pyx_PyInt_AsInt(__pyx_arg_direction); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.down", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_26down(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((int)__pyx_v_direction));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":84
+ * return self.node.link[direction] != NULL
+ *
+ * def down(self, int direction): # <<<<<<<<<<<<<<
+ * self.node = self.node.link[direction]
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_26down(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("down", 0);
+
+ /* "bintrees\cwalker.pyx":85
+ *
+ * def down(self, int direction):
+ * self.node = self.node.link[direction] # <<<<<<<<<<<<<<
+ *
+ * def go_left(self):
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[__pyx_v_direction]);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_29go_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_29go_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("go_left (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_28go_left(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":87
+ * self.node = self.node.link[direction]
+ *
+ * def go_left(self): # <<<<<<<<<<<<<<
+ * self.node = self.node.link[0]
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_28go_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("go_left", 0);
+
+ /* "bintrees\cwalker.pyx":88
+ *
+ * def go_left(self):
+ * self.node = self.node.link[0] # <<<<<<<<<<<<<<
+ *
+ * def go_right(self):
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[0]);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_31go_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_31go_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("go_right (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_30go_right(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":90
+ * self.node = self.node.link[0]
+ *
+ * def go_right(self): # <<<<<<<<<<<<<<
+ * self.node = self.node.link[1]
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_30go_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("go_right", 0);
+
+ /* "bintrees\cwalker.pyx":91
+ *
+ * def go_right(self):
+ * self.node = self.node.link[1] # <<<<<<<<<<<<<<
+ *
+ * def has_left(self):
+ */
+ __pyx_v_self->node = (__pyx_v_self->node->link[1]);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_33has_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_33has_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("has_left (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_32has_left(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":93
+ * self.node = self.node.link[1]
+ *
+ * def has_left(self): # <<<<<<<<<<<<<<
+ * return self.node.link[0] != NULL
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_32has_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("has_left", 0);
+
+ /* "bintrees\cwalker.pyx":94
+ *
+ * def has_left(self):
+ * return self.node.link[0] != NULL # <<<<<<<<<<<<<<
+ *
+ * def has_right(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->node->link[0]) != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_left", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_35has_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_35has_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("has_right (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_34has_right(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":96
+ * return self.node.link[0] != NULL
+ *
+ * def has_right(self): # <<<<<<<<<<<<<<
+ * return self.node.link[1] != NULL
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_34has_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("has_right", 0);
+
+ /* "bintrees\cwalker.pyx":97
+ *
+ * def has_right(self):
+ * return self.node.link[1] != NULL # <<<<<<<<<<<<<<
+ *
+ * def succ_item(self, key):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->node->link[1]) != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_right", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_37succ_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static char __pyx_doc_8bintrees_7cwalker_7cWalker_36succ_item[] = " Get successor (k,v) pair of key, raises KeyError if key is max key\n or key does not exist.\n ";
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_37succ_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("succ_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_36succ_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":99
+ * return self.node.link[1] != NULL
+ *
+ * def succ_item(self, key): # <<<<<<<<<<<<<<
+ * """ Get successor (k,v) pair of key, raises KeyError if key is max key
+ * or key does not exist.
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_36succ_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("succ_item", 0);
+
+ /* "bintrees\cwalker.pyx":103
+ * or key does not exist.
+ * """
+ * self.node = ct_succ_node(self.root, key) # <<<<<<<<<<<<<<
+ * if self.node == NULL: # given key is biggest in tree
+ * raise KeyError(str(key))
+ */
+ __pyx_v_self->node = ct_succ_node(__pyx_v_self->root, __pyx_v_key);
+
+ /* "bintrees\cwalker.pyx":104
+ * """
+ * self.node = ct_succ_node(self.root, key)
+ * if self.node == NULL: # given key is biggest in tree # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value)
+ */
+ __pyx_t_1 = (__pyx_v_self->node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\cwalker.pyx":105
+ * self.node = ct_succ_node(self.root, key)
+ * if self.node == NULL: # given key is biggest in tree
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * return (<object> self.node.key, <object> self.node.value)
+ *
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\cwalker.pyx":106
+ * if self.node == NULL: # given key is biggest in tree
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<<
+ *
+ * def prev_item(self, key):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value));
+ PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value));
+ __pyx_r = ((PyObject *)__pyx_t_3);
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.succ_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_39prev_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static char __pyx_doc_8bintrees_7cwalker_7cWalker_38prev_item[] = " Get predecessor (k,v) pair of key, raises KeyError if key is min key\n or key does not exist.\n ";
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_39prev_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("prev_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_38prev_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":108
+ * return (<object> self.node.key, <object> self.node.value)
+ *
+ * def prev_item(self, key): # <<<<<<<<<<<<<<
+ * """ Get predecessor (k,v) pair of key, raises KeyError if key is min key
+ * or key does not exist.
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_38prev_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("prev_item", 0);
+
+ /* "bintrees\cwalker.pyx":112
+ * or key does not exist.
+ * """
+ * self.node = ct_prev_node(self.root, key) # <<<<<<<<<<<<<<
+ * if self.node == NULL: # given key is smallest in tree
+ * raise KeyError(str(key))
+ */
+ __pyx_v_self->node = ct_prev_node(__pyx_v_self->root, __pyx_v_key);
+
+ /* "bintrees\cwalker.pyx":113
+ * """
+ * self.node = ct_prev_node(self.root, key)
+ * if self.node == NULL: # given key is smallest in tree # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value)
+ */
+ __pyx_t_1 = (__pyx_v_self->node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\cwalker.pyx":114
+ * self.node = ct_prev_node(self.root, key)
+ * if self.node == NULL: # given key is smallest in tree
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * return (<object> self.node.key, <object> self.node.value)
+ *
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\cwalker.pyx":115
+ * if self.node == NULL: # given key is smallest in tree
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<<
+ *
+ * def floor_item(self, key):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value));
+ PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value));
+ __pyx_r = ((PyObject *)__pyx_t_3);
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.prev_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_41floor_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static char __pyx_doc_8bintrees_7cwalker_7cWalker_40floor_item[] = " Get the element (k,v) pair associated with the greatest key less\n than or equal to the given key, raises KeyError if there is no such key.\n ";
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_41floor_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("floor_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_40floor_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":117
+ * return (<object> self.node.key, <object> self.node.value)
+ *
+ * def floor_item(self, key): # <<<<<<<<<<<<<<
+ * """ Get the element (k,v) pair associated with the greatest key less
+ * than or equal to the given key, raises KeyError if there is no such key.
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_40floor_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("floor_item", 0);
+
+ /* "bintrees\cwalker.pyx":121
+ * than or equal to the given key, raises KeyError if there is no such key.
+ * """
+ * self.node = ct_floor_node(self.root, key) # <<<<<<<<<<<<<<
+ * if self.node == NULL: # given key is smaller than min-key in tree
+ * raise KeyError(str(key))
+ */
+ __pyx_v_self->node = ct_floor_node(__pyx_v_self->root, __pyx_v_key);
+
+ /* "bintrees\cwalker.pyx":122
+ * """
+ * self.node = ct_floor_node(self.root, key)
+ * if self.node == NULL: # given key is smaller than min-key in tree # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value)
+ */
+ __pyx_t_1 = (__pyx_v_self->node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\cwalker.pyx":123
+ * self.node = ct_floor_node(self.root, key)
+ * if self.node == NULL: # given key is smaller than min-key in tree
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * return (<object> self.node.key, <object> self.node.value)
+ *
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\cwalker.pyx":124
+ * if self.node == NULL: # given key is smaller than min-key in tree
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<<
+ *
+ * def ceiling_item(self, key):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value));
+ PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value));
+ __pyx_r = ((PyObject *)__pyx_t_3);
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.floor_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_43ceiling_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static char __pyx_doc_8bintrees_7cwalker_7cWalker_42ceiling_item[] = " Get the element (k,v) pair associated with the smallest key greater\n than or equal to the given key, raises KeyError if there is no such key.\n ";
+static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_43ceiling_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("ceiling_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_42ceiling_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\cwalker.pyx":126
+ * return (<object> self.node.key, <object> self.node.value)
+ *
+ * def ceiling_item(self, key): # <<<<<<<<<<<<<<
+ * """ Get the element (k,v) pair associated with the smallest key greater
+ * than or equal to the given key, raises KeyError if there is no such key.
+ */
+
+static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_42ceiling_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("ceiling_item", 0);
+
+ /* "bintrees\cwalker.pyx":130
+ * than or equal to the given key, raises KeyError if there is no such key.
+ * """
+ * self.node = ct_ceiling_node(self.root, key) # <<<<<<<<<<<<<<
+ * if self.node == NULL: # given key is greater than max-key in tree
+ * raise KeyError(str(key))
+ */
+ __pyx_v_self->node = ct_ceiling_node(__pyx_v_self->root, __pyx_v_key);
+
+ /* "bintrees\cwalker.pyx":131
+ * """
+ * self.node = ct_ceiling_node(self.root, key)
+ * if self.node == NULL: # given key is greater than max-key in tree # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value)
+ */
+ __pyx_t_1 = (__pyx_v_self->node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\cwalker.pyx":132
+ * self.node = ct_ceiling_node(self.root, key)
+ * if self.node == NULL: # given key is greater than max-key in tree
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * return (<object> self.node.key, <object> self.node.value)
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\cwalker.pyx":133
+ * if self.node == NULL: # given key is greater than max-key in tree
+ * raise KeyError(str(key))
+ * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<<
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value));
+ PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value));
+ __pyx_r = ((PyObject *)__pyx_t_3);
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.cwalker.cWalker.ceiling_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker __pyx_vtable_8bintrees_7cwalker_cWalker;
+
+static PyObject *__pyx_tp_new_8bintrees_7cwalker_cWalker(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+ struct __pyx_obj_8bintrees_7cwalker_cWalker *p;
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)o);
+ p->__pyx_vtab = __pyx_vtabptr_8bintrees_7cwalker_cWalker;
+ if (__pyx_pw_8bintrees_7cwalker_7cWalker_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) {
+ Py_DECREF(o); o = 0;
+ }
+ return o;
+}
+
+static void __pyx_tp_dealloc_8bintrees_7cwalker_cWalker(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pw_8bintrees_7cwalker_7cWalker_3__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_8bintrees_7cwalker_cWalker[] = {
+ {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_5reset, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("key"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_7key, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("value"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_9value, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_11item, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("is_valid"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_13is_valid, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("goto"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_15goto, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("push"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_17push, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("pop"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_19pop, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("stack_is_empty"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_21stack_is_empty, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("goto_leaf"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_23goto_leaf, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_22goto_leaf)},
+ {__Pyx_NAMESTR("has_child"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_25has_child, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("down"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_27down, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("go_left"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_29go_left, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("go_right"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_31go_right, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("has_left"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_33has_left, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("has_right"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_35has_right, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("succ_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_37succ_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_36succ_item)},
+ {__Pyx_NAMESTR("prev_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_39prev_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_38prev_item)},
+ {__Pyx_NAMESTR("floor_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_41floor_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_40floor_item)},
+ {__Pyx_NAMESTR("ceiling_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_43ceiling_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_42ceiling_item)},
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_cWalker = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_cWalker = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_cWalker = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_cWalker = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_8bintrees_7cwalker_cWalker = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("bintrees.cwalker.cWalker"), /*tp_name*/
+ sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_8bintrees_7cwalker_cWalker, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_cWalker, /*tp_as_number*/
+ &__pyx_tp_as_sequence_cWalker, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_cWalker, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_cWalker, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_8bintrees_7cwalker_cWalker, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_8bintrees_7cwalker_cWalker, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+ {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef __pyx_moduledef = {
+ PyModuleDef_HEAD_INIT,
+ __Pyx_NAMESTR("cwalker"),
+ 0, /* m_doc */
+ -1, /* m_size */
+ __pyx_methods /* m_methods */,
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
+};
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+ {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
+ {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1},
+ {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
+ {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
+ {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
+ {&__pyx_n_s__is_valid, __pyx_k__is_valid, sizeof(__pyx_k__is_valid), 0, 0, 1, 1},
+ {&__pyx_n_s__item, __pyx_k__item, sizeof(__pyx_k__item), 0, 0, 1, 1},
+ {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
+ {&__pyx_n_s__pop, __pyx_k__pop, sizeof(__pyx_k__pop), 0, 0, 1, 1},
+ {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1},
+ {&__pyx_n_s__push, __pyx_k__push, sizeof(__pyx_k__push), 0, 0, 1, 1},
+ {&__pyx_n_s__reset, __pyx_k__reset, sizeof(__pyx_k__reset), 0, 0, 1, 1},
+ {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0}
+};
+static int __Pyx_InitCachedBuiltins(void) {
+ __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+static int __Pyx_InitCachedConstants(void) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
+
+ /* "bintrees\cwalker.pyx":65
+ * cpdef pop(self):
+ * if stack_is_empty(self.stack) != 0:
+ * raise IndexError('pop(): stack is empty') # <<<<<<<<<<<<<<
+ * self.node = stack_pop(self.stack)
+ *
+ */
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_2);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
+ __Pyx_RefNannyFinishContext();
+ return 0;
+ __pyx_L1_error:;
+ __Pyx_RefNannyFinishContext();
+ return -1;
+}
+
+static int __Pyx_InitGlobals(void) {
+ if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC initcwalker(void); /*proto*/
+PyMODINIT_FUNC initcwalker(void)
+#else
+PyMODINIT_FUNC PyInit_cwalker(void); /*proto*/
+PyMODINIT_FUNC PyInit_cwalker(void)
+#endif
+{
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ __Pyx_RefNannyDeclarations
+ #if CYTHON_REFNANNY
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+ if (!__Pyx_RefNanny) {
+ PyErr_Clear();
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+ if (!__Pyx_RefNanny)
+ Py_FatalError("failed to import 'refnanny' module");
+ }
+ #endif
+ __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_cwalker(void)", 0);
+ if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #ifdef __Pyx_CyFunction_USED
+ if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_FusedFunction_USED
+ if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_Generator_USED
+ if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ /*--- Library function declarations ---*/
+ /*--- Threads initialization code ---*/
+ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+ #ifdef WITH_THREAD /* Python build with threading support? */
+ PyEval_InitThreads();
+ #endif
+ #endif
+ /*--- Module creation code ---*/
+ #if PY_MAJOR_VERSION < 3
+ __pyx_m = Py_InitModule4(__Pyx_NAMESTR("cwalker"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+ #else
+ __pyx_m = PyModule_Create(&__pyx_moduledef);
+ #endif
+ if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if PY_MAJOR_VERSION >= 3
+ {
+ PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!PyDict_GetItemString(modules, "bintrees.cwalker")) {
+ if (unlikely(PyDict_SetItemString(modules, "bintrees.cwalker", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ }
+ #endif
+ __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if CYTHON_COMPILING_IN_PYPY
+ Py_INCREF(__pyx_b);
+ #endif
+ if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ /*--- Initialize various global constants etc. ---*/
+ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_module_is_main_bintrees__cwalker) {
+ if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ }
+ /*--- Builtin init code ---*/
+ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Constants init code ---*/
+ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Global init code ---*/
+ /*--- Variable export code ---*/
+ /*--- Function export code ---*/
+ /*--- Type init code ---*/
+ __pyx_vtabptr_8bintrees_7cwalker_cWalker = &__pyx_vtable_8bintrees_7cwalker_cWalker;
+ __pyx_vtable_8bintrees_7cwalker_cWalker.set_tree = (void (*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *))__pyx_f_8bintrees_7cwalker_7cWalker_set_tree;
+ __pyx_vtable_8bintrees_7cwalker_cWalker.reset = (PyObject *(*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch))__pyx_f_8bintrees_7cwalker_7cWalker_reset;
+ __pyx_vtable_8bintrees_7cwalker_cWalker.push = (PyObject *(*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch))__pyx_f_8bintrees_7cwalker_7cWalker_push;
+ __pyx_vtable_8bintrees_7cwalker_cWalker.pop = (PyObject *(*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch))__pyx_f_8bintrees_7cwalker_7cWalker_pop;
+ if (PyType_Ready(&__pyx_type_8bintrees_7cwalker_cWalker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetVtable(__pyx_type_8bintrees_7cwalker_cWalker.tp_dict, __pyx_vtabptr_8bintrees_7cwalker_cWalker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "cWalker", (PyObject *)&__pyx_type_8bintrees_7cwalker_cWalker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_8bintrees_7cwalker_cWalker = &__pyx_type_8bintrees_7cwalker_cWalker;
+ /*--- Type import code ---*/
+ /*--- Variable import code ---*/
+ /*--- Function import code ---*/
+ /*--- Execution code ---*/
+
+ /* "bintrees\cwalker.pyx":32
+ *
+ * @property
+ * def key(self): # <<<<<<<<<<<<<<
+ * return <object> self.node.key
+ *
+ */
+ __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__key); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__key, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker);
+
+ /* "bintrees\cwalker.pyx":36
+ *
+ * @property
+ * def value(self): # <<<<<<<<<<<<<<
+ * return <object> self.node.value
+ *
+ */
+ __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__value, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker);
+
+ /* "bintrees\cwalker.pyx":40
+ *
+ * @property
+ * def item(self): # <<<<<<<<<<<<<<
+ * return (<object>self.node.key, <object>self.node.value)
+ *
+ */
+ __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__item); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__item, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker);
+
+ /* "bintrees\cwalker.pyx":44
+ *
+ * @property
+ * def is_valid(self): # <<<<<<<<<<<<<<
+ * return self.node != NULL
+ *
+ */
+ __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__is_valid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__is_valid, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker);
+
+ /* "bintrees\cwalker.pyx":1
+ * #!/usr/bin/env python # <<<<<<<<<<<<<<
+ * #coding:utf-8
+ * # Author: mozman
+ */
+ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ if (__pyx_m) {
+ __Pyx_AddTraceback("init bintrees.cwalker", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ Py_DECREF(__pyx_m); __pyx_m = 0;
+ } else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "init bintrees.cwalker");
+ }
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ #if PY_MAJOR_VERSION < 3
+ return;
+ #else
+ return __pyx_m;
+ #endif
+}
+
+/* Runtime support code */
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+ PyObject *m = NULL, *p = NULL;
+ void *r = NULL;
+ m = PyImport_ImportModule((char *)modname);
+ if (!m) goto end;
+ p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
+ if (!p) goto end;
+ r = PyLong_AsVoidPtr(p);
+end:
+ Py_XDECREF(p);
+ Py_XDECREF(m);
+ return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif /* CYTHON_REFNANNY */
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result) {
+ if (dict != __pyx_b) {
+ PyErr_Clear();
+ result = PyObject_GetAttr(__pyx_b, name);
+ }
+ if (!result) {
+ PyErr_SetObject(PyExc_NameError, name);
+ }
+ }
+ return result;
+}
+
+static void __Pyx_RaiseArgtupleInvalid(
+ const char* func_name,
+ int exact,
+ Py_ssize_t num_min,
+ Py_ssize_t num_max,
+ Py_ssize_t num_found)
+{
+ Py_ssize_t num_expected;
+ const char *more_or_less;
+ if (num_found < num_min) {
+ num_expected = num_min;
+ more_or_less = "at least";
+ } else {
+ num_expected = num_max;
+ more_or_less = "at most";
+ }
+ if (exact) {
+ more_or_less = "exactly";
+ }
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
+ func_name, more_or_less, num_expected,
+ (num_expected == 1) ? "" : "s", num_found);
+}
+
+static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
+ PyObject *kwdict,
+ const char* function_name,
+ int kw_allowed)
+{
+ PyObject* key = 0;
+ Py_ssize_t pos = 0;
+#if CPYTHON_COMPILING_IN_PYPY
+ if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
+ goto invalid_keyword;
+ return 1;
+#else
+ while (PyDict_Next(kwdict, &pos, &key, 0)) {
+ #if PY_MAJOR_VERSION < 3
+ if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
+ #endif
+ if (unlikely(!PyUnicode_Check(key)))
+ goto invalid_keyword_type;
+ }
+ if ((!kw_allowed) && unlikely(key))
+ goto invalid_keyword;
+ return 1;
+invalid_keyword_type:
+ PyErr_Format(PyExc_TypeError,
+ "%s() keywords must be strings", function_name);
+ return 0;
+#endif
+invalid_keyword:
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION < 3
+ "%s() got an unexpected keyword argument '%s'",
+ function_name, PyString_AsString(key));
+ #else
+ "%s() got an unexpected keyword argument '%U'",
+ function_name, key);
+ #endif
+ return 0;
+}
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+ tmp_type = tstate->curexc_type;
+ tmp_value = tstate->curexc_value;
+ tmp_tb = tstate->curexc_traceback;
+ tstate->curexc_type = type;
+ tstate->curexc_value = value;
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+#else
+ PyErr_Restore(type, value, tb);
+#endif
+}
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->curexc_type;
+ *value = tstate->curexc_value;
+ *tb = tstate->curexc_traceback;
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+#else
+ PyErr_Fetch(type, value, tb);
+#endif
+}
+
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
+ CYTHON_UNUSED PyObject *cause) {
+ Py_XINCREF(type);
+ if (!value || value == Py_None)
+ value = NULL;
+ else
+ Py_INCREF(value);
+ if (!tb || tb == Py_None)
+ tb = NULL;
+ else {
+ Py_INCREF(tb);
+ if (!PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto raise_error;
+ }
+ }
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyClass_Check(type)) {
+ #else
+ if (PyType_Check(type)) {
+ #endif
+#if CYTHON_COMPILING_IN_PYPY
+ if (!value) {
+ Py_INCREF(Py_None);
+ value = Py_None;
+ }
+#endif
+ PyErr_NormalizeException(&type, &value, &tb);
+ } else {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto raise_error;
+ }
+ value = type;
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyInstance_Check(type)) {
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
+ }
+ else {
+ type = 0;
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception must be an old-style class or instance");
+ goto raise_error;
+ }
+ #else
+ type = (PyObject*) Py_TYPE(type);
+ Py_INCREF(type);
+ if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto raise_error;
+ }
+ #endif
+ }
+ __Pyx_ErrRestore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ return;
+}
+#else /* Python 3+ */
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+ PyObject* owned_instance = NULL;
+ if (tb == Py_None) {
+ tb = 0;
+ } else if (tb && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto bad;
+ }
+ if (value == Py_None)
+ value = 0;
+ if (PyExceptionInstance_Check(type)) {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto bad;
+ }
+ value = type;
+ type = (PyObject*) Py_TYPE(value);
+ } else if (PyExceptionClass_Check(type)) {
+ PyObject *args;
+ if (!value)
+ args = PyTuple_New(0);
+ else if (PyTuple_Check(value)) {
+ Py_INCREF(value);
+ args = value;
+ }
+ else
+ args = PyTuple_Pack(1, value);
+ if (!args)
+ goto bad;
+ owned_instance = PyEval_CallObject(type, args);
+ Py_DECREF(args);
+ if (!owned_instance)
+ goto bad;
+ value = owned_instance;
+ if (!PyExceptionInstance_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "calling %R should have returned an instance of "
+ "BaseException, not %R",
+ type, Py_TYPE(value));
+ goto bad;
+ }
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto bad;
+ }
+ if (cause && cause != Py_None) {
+ PyObject *fixed_cause;
+ if (PyExceptionClass_Check(cause)) {
+ fixed_cause = PyObject_CallObject(cause, NULL);
+ if (fixed_cause == NULL)
+ goto bad;
+ }
+ else if (PyExceptionInstance_Check(cause)) {
+ fixed_cause = cause;
+ Py_INCREF(fixed_cause);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
+ goto bad;
+ }
+ PyException_SetCause(value, fixed_cause);
+ }
+ PyErr_SetObject(type, value);
+ if (tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ PyObject* tmp_tb = tstate->curexc_traceback;
+ if (tb != tmp_tb) {
+ Py_INCREF(tb);
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_tb);
+ }
+ }
+bad:
+ Py_XDECREF(owned_instance);
+ return;
+}
+#endif
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
+ const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned char" :
+ "value too large to convert to unsigned char");
+ }
+ return (unsigned char)-1;
+ }
+ return (unsigned char)val;
+ }
+ return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
+ const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned short" :
+ "value too large to convert to unsigned short");
+ }
+ return (unsigned short)-1;
+ }
+ return (unsigned short)val;
+ }
+ return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
+ const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned int" :
+ "value too large to convert to unsigned int");
+ }
+ return (unsigned int)-1;
+ }
+ return (unsigned int)val;
+ }
+ return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
+ const char neg_one = (char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to char" :
+ "value too large to convert to char");
+ }
+ return (char)-1;
+ }
+ return (char)val;
+ }
+ return (char)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
+ const short neg_one = (short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to short" :
+ "value too large to convert to short");
+ }
+ return (short)-1;
+ }
+ return (short)val;
+ }
+ return (short)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
+ const signed char neg_one = (signed char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed char" :
+ "value too large to convert to signed char");
+ }
+ return (signed char)-1;
+ }
+ return (signed char)val;
+ }
+ return (signed char)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
+ const signed short neg_one = (signed short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed short" :
+ "value too large to convert to signed short");
+ }
+ return (signed short)-1;
+ }
+ return (signed short)val;
+ }
+ return (signed short)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
+ const signed int neg_one = (signed int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed int" :
+ "value too large to convert to signed int");
+ }
+ return (signed int)-1;
+ }
+ return (signed int)val;
+ }
+ return (signed int)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
+ const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (unsigned long)PyLong_AsLong(x);
+ }
+ } else {
+ unsigned long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned long)-1;
+ val = __Pyx_PyInt_AsUnsignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
+ const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ unsigned PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
+ const long neg_one = (long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (long)PyLong_AsLong(x);
+ }
+ } else {
+ long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (long)-1;
+ val = __Pyx_PyInt_AsLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
+ const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
+ const signed long neg_one = (signed long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (signed long)PyLong_AsLong(x);
+ }
+ } else {
+ signed long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed long)-1;
+ val = __Pyx_PyInt_AsSignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
+ const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ signed PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsSignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
+ CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) {
+ PyObject *old_exc, *old_val, *old_tb;
+ PyObject *ctx;
+ __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
+ #if PY_MAJOR_VERSION < 3
+ ctx = PyString_FromString(name);
+ #else
+ ctx = PyUnicode_FromString(name);
+ #endif
+ __Pyx_ErrRestore(old_exc, old_val, old_tb);
+ if (!ctx) {
+ PyErr_WriteUnraisable(Py_None);
+ } else {
+ PyErr_WriteUnraisable(ctx);
+ Py_DECREF(ctx);
+ }
+}
+
+static int __Pyx_check_binary_version(void) {
+ char ctversion[4], rtversion[4];
+ PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+ PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+ if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+ char message[200];
+ PyOS_snprintf(message, sizeof(message),
+ "compiletime version %s of module '%.100s' "
+ "does not match runtime version %s",
+ ctversion, __Pyx_MODULE_NAME, rtversion);
+ #if PY_VERSION_HEX < 0x02050000
+ return PyErr_Warn(NULL, message);
+ #else
+ return PyErr_WarnEx(NULL, message, 1);
+ #endif
+ }
+ return 0;
+}
+
+static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
+#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
+ PyObject *ob = PyCapsule_New(vtable, 0, 0);
+#else
+ PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
+#endif
+ if (!ob)
+ goto bad;
+ if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
+ goto bad;
+ Py_DECREF(ob);
+ return 0;
+bad:
+ Py_XDECREF(ob);
+ return -1;
+}
+
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+ int start = 0, mid = 0, end = count - 1;
+ if (end >= 0 && code_line > entries[end].code_line) {
+ return count;
+ }
+ while (start < end) {
+ mid = (start + end) / 2;
+ if (code_line < entries[mid].code_line) {
+ end = mid;
+ } else if (code_line > entries[mid].code_line) {
+ start = mid + 1;
+ } else {
+ return mid;
+ }
+ }
+ if (code_line <= entries[mid].code_line) {
+ return mid;
+ } else {
+ return mid + 1;
+ }
+}
+static PyCodeObject *__pyx_find_code_object(int code_line) {
+ PyCodeObject* code_object;
+ int pos;
+ if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
+ return NULL;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
+ return NULL;
+ }
+ code_object = __pyx_code_cache.entries[pos].code_object;
+ Py_INCREF(code_object);
+ return code_object;
+}
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
+ int pos, i;
+ __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
+ if (unlikely(!code_line)) {
+ return;
+ }
+ if (unlikely(!entries)) {
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (likely(entries)) {
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = 64;
+ __pyx_code_cache.count = 1;
+ entries[0].code_line = code_line;
+ entries[0].code_object = code_object;
+ Py_INCREF(code_object);
+ }
+ return;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
+ PyCodeObject* tmp = entries[pos].code_object;
+ entries[pos].code_object = code_object;
+ Py_DECREF(tmp);
+ return;
+ }
+ if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
+ int new_max = __pyx_code_cache.max_count + 64;
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
+ __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (unlikely(!entries)) {
+ return;
+ }
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = new_max;
+ }
+ for (i=__pyx_code_cache.count; i>pos; i--) {
+ entries[i] = entries[i-1];
+ }
+ entries[pos].code_line = code_line;
+ entries[pos].code_object = code_object;
+ __pyx_code_cache.count++;
+ Py_INCREF(code_object);
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
+ const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ #if PY_MAJOR_VERSION < 3
+ py_srcfile = PyString_FromString(filename);
+ #else
+ py_srcfile = PyUnicode_FromString(filename);
+ #endif
+ if (!py_srcfile) goto bad;
+ if (c_line) {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #else
+ py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #endif
+ }
+ else {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromString(funcname);
+ #else
+ py_funcname = PyUnicode_FromString(funcname);
+ #endif
+ }
+ if (!py_funcname) goto bad;
+ py_code = __Pyx_PyCode_New(
+ 0, /*int argcount,*/
+ 0, /*int kwonlyargcount,*/
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ __pyx_empty_bytes, /*PyObject *code,*/
+ __pyx_empty_tuple, /*PyObject *consts,*/
+ __pyx_empty_tuple, /*PyObject *names,*/
+ __pyx_empty_tuple, /*PyObject *varnames,*/
+ __pyx_empty_tuple, /*PyObject *freevars,*/
+ __pyx_empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ py_line, /*int firstlineno,*/
+ __pyx_empty_bytes /*PyObject *lnotab*/
+ );
+ Py_DECREF(py_srcfile);
+ Py_DECREF(py_funcname);
+ return py_code;
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ return NULL;
+}
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_globals = 0;
+ PyFrameObject *py_frame = 0;
+ py_code = __pyx_find_code_object(c_line ? c_line : py_line);
+ if (!py_code) {
+ py_code = __Pyx_CreateCodeObjectForTraceback(
+ funcname, c_line, py_line, filename);
+ if (!py_code) goto bad;
+ __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
+ }
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_GET(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = py_line;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+ while (t->p) {
+ #if PY_MAJOR_VERSION < 3
+ if (t->is_unicode) {
+ *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+ } else if (t->intern) {
+ *t->p = PyString_InternFromString(t->s);
+ } else {
+ *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+ }
+ #else /* Python 3+ has unicode identifiers */
+ if (t->is_unicode | t->is_str) {
+ if (t->intern) {
+ *t->p = PyUnicode_InternFromString(t->s);
+ } else if (t->encoding) {
+ *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+ } else {
+ *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+ }
+ } else {
+ *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+ }
+ #endif
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+
+/* Type Conversion Functions */
+
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+ int is_true = x == Py_True;
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+ else return PyObject_IsTrue(x);
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
+ PyNumberMethods *m;
+ const char *name = NULL;
+ PyObject *res = NULL;
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_Check(x) || PyLong_Check(x))
+#else
+ if (PyLong_Check(x))
+#endif
+ return Py_INCREF(x), x;
+ m = Py_TYPE(x)->tp_as_number;
+#if PY_VERSION_HEX < 0x03000000
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Int(x);
+ }
+ else if (m && m->nb_long) {
+ name = "long";
+ res = PyNumber_Long(x);
+ }
+#else
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Long(x);
+ }
+#endif
+ if (res) {
+#if PY_VERSION_HEX < 0x03000000
+ if (!PyInt_Check(res) && !PyLong_Check(res)) {
+#else
+ if (!PyLong_Check(res)) {
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "__%s__ returned non-%s (type %.200s)",
+ name, name, Py_TYPE(res)->tp_name);
+ Py_DECREF(res);
+ return NULL;
+ }
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "an integer is required");
+ }
+ return res;
+}
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+ Py_ssize_t ival;
+ PyObject* x = PyNumber_Index(b);
+ if (!x) return -1;
+ ival = PyInt_AsSsize_t(x);
+ Py_DECREF(x);
+ return ival;
+}
+
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+#if PY_VERSION_HEX < 0x02050000
+ if (ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ else {
+ unsigned char *bytes = (unsigned char *) &ival;
+ int one = 1; int little = (int)*(unsigned char*)&one;
+ return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
+ }
+#else
+ return PyInt_FromSize_t(ival);
+#endif
+}
+
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
+ unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
+ if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
+ return (size_t)-1;
+ } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "value too large to convert to size_t");
+ return (size_t)-1;
+ }
+ return (size_t)val;
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/chromium/third_party/bintrees/bintrees/cwalker.pxd b/chromium/third_party/bintrees/bintrees/cwalker.pxd
new file mode 100644
index 00000000000..412f80364fe
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/cwalker.pxd
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Created: 08.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+from ctrees cimport node_t
+from stack cimport node_stack_t
+
+cdef class cWalker:
+ cdef node_t *node
+ cdef node_t *root
+ cdef node_stack_t *stack
+
+ cdef void set_tree(self, node_t *root)
+ cpdef reset(self)
+ cpdef push(self)
+ cpdef pop(self)
diff --git a/chromium/third_party/bintrees/bintrees/cwalker.pyx b/chromium/third_party/bintrees/bintrees/cwalker.pyx
new file mode 100644
index 00000000000..eb94104b775
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/cwalker.pyx
@@ -0,0 +1,133 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: tree walker for cython trees
+# Created: 07.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+DEF MAXSTACK=32
+
+from stack cimport *
+from ctrees cimport *
+
+cdef class cWalker:
+ def __cinit__(self):
+ self.root = NULL
+ self.node = NULL
+ self.stack = stack_init(MAXSTACK)
+
+ def __dealloc__(self):
+ stack_delete(self.stack)
+
+ cdef void set_tree(self, node_t *root):
+ self.root = root
+ self.reset()
+
+ cpdef reset(self):
+ stack_reset(self.stack)
+ self.node = self.root
+
+ @property
+ def key(self):
+ return <object> self.node.key
+
+ @property
+ def value(self):
+ return <object> self.node.value
+
+ @property
+ def item(self):
+ return (<object>self.node.key, <object>self.node.value)
+
+ @property
+ def is_valid(self):
+ return self.node != NULL
+
+ def goto(self, key):
+ cdef int cval
+ self.node = self.root
+ while self.node != NULL:
+ cval = ct_compare(key, <object> self.node.key)
+ if cval == 0:
+ return True
+ elif cval < 0:
+ self.node = self.node.link[0]
+ else:
+ self.node = self.node.link[1]
+ return False
+
+ cpdef push(self):
+ stack_push(self.stack, self.node)
+
+ cpdef pop(self):
+ if stack_is_empty(self.stack) != 0:
+ raise IndexError('pop(): stack is empty')
+ self.node = stack_pop(self.stack)
+
+ def stack_is_empty(self):
+ return <bint> stack_is_empty(self.stack)
+
+ def goto_leaf(self):
+ """ get a leaf node """
+ while self.node != NULL:
+ if self.node.link[0] != NULL:
+ self.node = self.node.link[0]
+ elif self.node.link[1] != NULL:
+ self.node = self.node.link[1]
+ else:
+ return
+
+ def has_child(self, int direction):
+ return self.node.link[direction] != NULL
+
+ def down(self, int direction):
+ self.node = self.node.link[direction]
+
+ def go_left(self):
+ self.node = self.node.link[0]
+
+ def go_right(self):
+ self.node = self.node.link[1]
+
+ def has_left(self):
+ return self.node.link[0] != NULL
+
+ def has_right(self):
+ return self.node.link[1] != NULL
+
+ def succ_item(self, key):
+ """ Get successor (k,v) pair of key, raises KeyError if key is max key
+ or key does not exist.
+ """
+ self.node = ct_succ_node(self.root, key)
+ if self.node == NULL: # given key is biggest in tree
+ raise KeyError(str(key))
+ return (<object> self.node.key, <object> self.node.value)
+
+ def prev_item(self, key):
+ """ Get predecessor (k,v) pair of key, raises KeyError if key is min key
+ or key does not exist.
+ """
+ self.node = ct_prev_node(self.root, key)
+ if self.node == NULL: # given key is smallest in tree
+ raise KeyError(str(key))
+ return (<object> self.node.key, <object> self.node.value)
+
+ def floor_item(self, key):
+ """ Get the element (k,v) pair associated with the greatest key less
+ than or equal to the given key, raises KeyError if there is no such key.
+ """
+ self.node = ct_floor_node(self.root, key)
+ if self.node == NULL: # given key is smaller than min-key in tree
+ raise KeyError(str(key))
+ return (<object> self.node.key, <object> self.node.value)
+
+ def ceiling_item(self, key):
+ """ Get the element (k,v) pair associated with the smallest key greater
+ than or equal to the given key, raises KeyError if there is no such key.
+ """
+ self.node = ct_ceiling_node(self.root, key)
+ if self.node == NULL: # given key is greater than max-key in tree
+ raise KeyError(str(key))
+ return (<object> self.node.key, <object> self.node.value)
diff --git a/chromium/third_party/bintrees/bintrees/qavltree.c b/chromium/third_party/bintrees/bintrees/qavltree.c
new file mode 100644
index 00000000000..8c7c563f52f
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/qavltree.c
@@ -0,0 +1,3402 @@
+/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+ #error Python headers needed to compile C extensions, please install development version of Python.
+#elif PY_VERSION_HEX < 0x02040000
+ #error Cython requires Python 2.4+.
+#else
+#include <stddef.h> /* For offsetof */
+#ifndef offsetof
+#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+ #ifndef __stdcall
+ #define __stdcall
+ #endif
+ #ifndef __cdecl
+ #define __cdecl
+ #endif
+ #ifndef __fastcall
+ #define __fastcall
+ #endif
+#endif
+#ifndef DL_IMPORT
+ #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+ #define DL_EXPORT(t) t
+#endif
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef Py_HUGE_VAL
+ #define Py_HUGE_VAL HUGE_VAL
+#endif
+#ifdef PYPY_VERSION
+#define CYTHON_COMPILING_IN_PYPY 1
+#define CYTHON_COMPILING_IN_CPYTHON 0
+#else
+#define CYTHON_COMPILING_IN_PYPY 0
+#define CYTHON_COMPILING_IN_CPYTHON 1
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+ #define PY_SSIZE_T_MAX INT_MAX
+ #define PY_SSIZE_T_MIN INT_MIN
+ #define PY_FORMAT_SIZE_T ""
+ #define CYTHON_FORMAT_SSIZE_T ""
+ #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+ #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
+ #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
+ (PyErr_Format(PyExc_TypeError, \
+ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
+ (PyObject*)0))
+ #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
+ !PyComplex_Check(o))
+ #define PyIndex_Check __Pyx_PyIndex_Check
+ #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
+ #define __PYX_BUILD_PY_SSIZE_T "i"
+#else
+ #define __PYX_BUILD_PY_SSIZE_T "n"
+ #define CYTHON_FORMAT_SSIZE_T "z"
+ #define __Pyx_PyIndex_Check PyIndex_Check
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+ #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+ #define PyVarObject_HEAD_INIT(type, size) \
+ PyObject_HEAD_INIT(type) size,
+ #define PyType_Modified(t)
+ typedef struct {
+ void *buf;
+ PyObject *obj;
+ Py_ssize_t len;
+ Py_ssize_t itemsize;
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets;
+ void *internal;
+ } Py_buffer;
+ #define PyBUF_SIMPLE 0
+ #define PyBUF_WRITABLE 0x0001
+ #define PyBUF_FORMAT 0x0004
+ #define PyBUF_ND 0x0008
+ #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+ #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+ #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+ #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+ #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
+ #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
+ #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
+ typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
+ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
+#endif
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#else
+ #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#endif
+#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
+ #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define Py_TPFLAGS_CHECKTYPES 0
+ #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+ #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
+ #define CYTHON_PEP393_ENABLED 1
+ #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \
+ 0 : _PyUnicode_Ready((PyObject *)(op)))
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
+ #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
+#else
+ #define CYTHON_PEP393_ENABLED 0
+ #define __Pyx_PyUnicode_READY(op) (0)
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
+ #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBaseString_Type PyUnicode_Type
+ #define PyStringObject PyUnicodeObject
+ #define PyString_Type PyUnicode_Type
+ #define PyString_Check PyUnicode_Check
+ #define PyString_CheckExact PyUnicode_CheckExact
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PyBytesObject PyStringObject
+ #define PyBytes_Type PyString_Type
+ #define PyBytes_Check PyString_Check
+ #define PyBytes_CheckExact PyString_CheckExact
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+ #define PyBytes_FromFormat PyString_FromFormat
+ #define PyBytes_DecodeEscape PyString_DecodeEscape
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_AS_STRING PyString_AS_STRING
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
+ #define PyBytes_Repr PyString_Repr
+ #define PyBytes_Concat PyString_Concat
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+#ifndef PySet_CheckExact
+ #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
+#endif
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+#if PY_MAJOR_VERSION >= 3
+ #define PyIntObject PyLongObject
+ #define PyInt_Type PyLong_Type
+ #define PyInt_Check(op) PyLong_Check(op)
+ #define PyInt_CheckExact(op) PyLong_CheckExact(op)
+ #define PyInt_FromString PyLong_FromString
+ #define PyInt_FromUnicode PyLong_FromUnicode
+ #define PyInt_FromLong PyLong_FromLong
+ #define PyInt_FromSize_t PyLong_FromSize_t
+ #define PyInt_FromSsize_t PyLong_FromSsize_t
+ #define PyInt_AsLong PyLong_AsLong
+ #define PyInt_AS_LONG PyLong_AS_LONG
+ #define PyInt_AsSsize_t PyLong_AsSsize_t
+ #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
+ #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBoolObject PyLongObject
+#endif
+#if PY_VERSION_HEX < 0x03020000
+ typedef long Py_hash_t;
+ #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+ #define __Pyx_PyInt_AsHash_t PyInt_AsLong
+#else
+ #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+ #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
+#endif
+#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
+ #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
+ #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
+#else
+ #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
+ #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
+#else
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_NAMESTR(n) ((char *)(n))
+ #define __Pyx_DOCSTR(n) ((char *)(n))
+#else
+ #define __Pyx_NAMESTR(n) (n)
+ #define __Pyx_DOCSTR(n) (n)
+#endif
+
+
+#if PY_MAJOR_VERSION >= 3
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
+#else
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
+#endif
+
+#ifndef __PYX_EXTERN_C
+ #ifdef __cplusplus
+ #define __PYX_EXTERN_C extern "C"
+ #else
+ #define __PYX_EXTERN_C extern
+ #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#define __PYX_HAVE__bintrees__qavltree
+#define __PYX_HAVE_API__bintrees__qavltree
+#include "ctrees.h"
+#include "stack.h"
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#ifdef PYREX_WITHOUT_ASSERTIONS
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+
+/* inline attribute */
+#ifndef CYTHON_INLINE
+ #if defined(__GNUC__)
+ #define CYTHON_INLINE __inline__
+ #elif defined(_MSC_VER)
+ #define CYTHON_INLINE __inline
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_INLINE inline
+ #else
+ #define CYTHON_INLINE
+ #endif
+#endif
+
+/* unused attribute */
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+#endif
+
+typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
+
+
+/* Type Conversion Predeclarations */
+
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
+
+#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
+
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+#else
+#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
+#endif
+#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
+
+#ifdef __GNUC__
+ /* Test for GCC > 2.95 */
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
+ #define likely(x) __builtin_expect(!!(x), 1)
+ #define unlikely(x) __builtin_expect(!!(x), 0)
+ #else /* __GNUC__ > 2 ... */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+ #endif /* __GNUC__ > 2 ... */
+#else /* __GNUC__ */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+#endif /* __GNUC__ */
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+ "qavltree.pyx",
+ "cwalker.pxd",
+};
+
+/*--- Type declarations ---*/
+struct __pyx_obj_8bintrees_7cwalker_cWalker;
+struct __pyx_obj_8bintrees_8qavltree_cAVLTree;
+
+/* "cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+struct __pyx_obj_8bintrees_7cwalker_cWalker {
+ PyObject_HEAD
+ struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab;
+ node_t *node;
+ node_t *root;
+ node_stack_t *stack;
+};
+
+
+/* "bintrees\qavltree.pyx":16
+ * from ctrees cimport *
+ *
+ * cdef class cAVLTree: # <<<<<<<<<<<<<<
+ * cdef node_t *_root
+ * cdef int _count
+ */
+struct __pyx_obj_8bintrees_8qavltree_cAVLTree {
+ PyObject_HEAD
+ node_t *_root;
+ int _count;
+};
+
+
+
+/* "cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+
+struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker {
+ void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *);
+ PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+};
+static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker;
+#ifndef CYTHON_REFNANNY
+ #define CYTHON_REFNANNY 0
+#endif
+#if CYTHON_REFNANNY
+ typedef struct {
+ void (*INCREF)(void*, PyObject*, int);
+ void (*DECREF)(void*, PyObject*, int);
+ void (*GOTREF)(void*, PyObject*, int);
+ void (*GIVEREF)(void*, PyObject*, int);
+ void* (*SetupContext)(const char*, int, const char*);
+ void (*FinishContext)(void**);
+ } __Pyx_RefNannyAPIStruct;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
+ #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+#ifdef WITH_THREAD
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ if (acquire_gil) { \
+ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ PyGILState_Release(__pyx_gilstate_save); \
+ } else { \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ }
+#else
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+#endif
+ #define __Pyx_RefNannyFinishContext() \
+ __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+ #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+ #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+ #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+ #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+ #define __Pyx_RefNannyDeclarations
+ #define __Pyx_RefNannySetupContext(name, acquire_gil)
+ #define __Pyx_RefNannyFinishContext()
+ #define __Pyx_INCREF(r) Py_INCREF(r)
+ #define __Pyx_DECREF(r) Py_DECREF(r)
+ #define __Pyx_GOTREF(r)
+ #define __Pyx_GIVEREF(r)
+ #define __Pyx_XINCREF(r) Py_XINCREF(r)
+ #define __Pyx_XDECREF(r) Py_XDECREF(r)
+ #define __Pyx_XGOTREF(r)
+ #define __Pyx_XGIVEREF(r)
+#endif /* CYTHON_REFNANNY */
+#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
+#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
+
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
+ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
+ const char* function_name); /*proto*/
+
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
+
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+ PyObject *r;
+ if (!j) return NULL;
+ r = PyObject_GetItem(o, j);
+ Py_DECREF(j);
+ return r;
+}
+#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_List_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
+ PyObject *r = PyList_GET_ITEM(o, i);
+ Py_INCREF(r);
+ return r;
+ }
+ else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
+ PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
+ Py_INCREF(r);
+ return r;
+ }
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+ return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Tuple_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
+ PyObject *r = PyTuple_GET_ITEM(o, i);
+ Py_INCREF(r);
+ return r;
+ }
+ else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
+ PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
+ Py_INCREF(r);
+ return r;
+ }
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+ return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (PyList_CheckExact(o)) {
+ Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+ if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
+ PyObject *r = PyList_GET_ITEM(o, n);
+ Py_INCREF(r);
+ return r;
+ }
+ }
+ else if (PyTuple_CheckExact(o)) {
+ Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+ if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
+ PyObject *r = PyTuple_GET_ITEM(o, n);
+ Py_INCREF(r);
+ return r;
+ }
+ } else { /* inlined PySequence_GetItem() */
+ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ if (likely(m && m->sq_item)) {
+ if (unlikely(i < 0) && likely(m->sq_length)) {
+ Py_ssize_t l = m->sq_length(o);
+ if (unlikely(l < 0)) return NULL;
+ i += l;
+ }
+ return m->sq_item(o, i);
+ }
+ }
+#else
+ if (PySequence_Check(o)) {
+ return PySequence_GetItem(o, i);
+ }
+#endif
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
+
+static int __Pyx_check_binary_version(void);
+
+#if !defined(__Pyx_PyIdentifier_FromString)
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
+#else
+ #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
+#endif
+#endif
+
+static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
+
+static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/
+
+static void* __Pyx_GetVtable(PyObject *dict); /*proto*/
+
+typedef struct {
+ int code_line;
+ PyCodeObject* code_object;
+} __Pyx_CodeObjectCacheEntry;
+struct __Pyx_CodeObjectCache {
+ int count;
+ int max_count;
+ __Pyx_CodeObjectCacheEntry* entries;
+};
+static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
+static PyCodeObject *__pyx_find_code_object(int code_line);
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
+
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+
+/* Module declarations from 'bintrees.ctrees' */
+
+/* Module declarations from 'bintrees.stack' */
+
+/* Module declarations from 'bintrees.cwalker' */
+static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0;
+
+/* Module declarations from 'bintrees.qavltree' */
+static PyTypeObject *__pyx_ptype_8bintrees_8qavltree_cAVLTree = 0;
+#define __Pyx_MODULE_NAME "bintrees.qavltree"
+int __pyx_module_is_main_bintrees__qavltree = 0;
+
+/* Implementation of 'bintrees.qavltree' */
+static PyObject *__pyx_builtin_property;
+static PyObject *__pyx_builtin_KeyError;
+static PyObject *__pyx_builtin_MemoryError;
+static PyObject *__pyx_builtin_ValueError;
+static int __pyx_pf_8bintrees_8qavltree_8cAVLTree___cinit__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_items); /* proto */
+static void __pyx_pf_8bintrees_8qavltree_8cAVLTree_2__dealloc__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_4count(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_6__getstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_8__setstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_state); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_10clear(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_12get_value(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_14get_walker(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_16insert(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_18remove(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_20max_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_22min_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */
+static char __pyx_k_1[] = "Can not allocate memory for node structure.";
+static char __pyx_k_3[] = "Tree is empty";
+static char __pyx_k__key[] = "key";
+static char __pyx_k__count[] = "count";
+static char __pyx_k__items[] = "items";
+static char __pyx_k__value[] = "value";
+static char __pyx_k__update[] = "update";
+static char __pyx_k____all__[] = "__all__";
+static char __pyx_k__cWalker[] = "cWalker";
+static char __pyx_k__cwalker[] = "cwalker";
+static char __pyx_k__KeyError[] = "KeyError";
+static char __pyx_k____main__[] = "__main__";
+static char __pyx_k____test__[] = "__test__";
+static char __pyx_k__cAVLTree[] = "cAVLTree";
+static char __pyx_k__property[] = "property";
+static char __pyx_k__ValueError[] = "ValueError";
+static char __pyx_k__MemoryError[] = "MemoryError";
+static PyObject *__pyx_kp_s_1;
+static PyObject *__pyx_kp_s_3;
+static PyObject *__pyx_n_s__KeyError;
+static PyObject *__pyx_n_s__MemoryError;
+static PyObject *__pyx_n_s__ValueError;
+static PyObject *__pyx_n_s____all__;
+static PyObject *__pyx_n_s____main__;
+static PyObject *__pyx_n_s____test__;
+static PyObject *__pyx_n_s__cAVLTree;
+static PyObject *__pyx_n_s__cWalker;
+static PyObject *__pyx_n_s__count;
+static PyObject *__pyx_n_s__cwalker;
+static PyObject *__pyx_n_s__items;
+static PyObject *__pyx_n_s__key;
+static PyObject *__pyx_n_s__property;
+static PyObject *__pyx_n_s__update;
+static PyObject *__pyx_n_s__value;
+static PyObject *__pyx_int_0;
+static PyObject *__pyx_k_tuple_2;
+static PyObject *__pyx_k_tuple_4;
+static PyObject *__pyx_k_tuple_5;
+
+/* Python wrapper */
+static int __pyx_pw_8bintrees_8qavltree_8cAVLTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_8bintrees_8qavltree_8cAVLTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_items = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__items,0};
+ PyObject* values[1] = {0};
+
+ /* "bintrees\qavltree.pyx":20
+ * cdef int _count
+ *
+ * def __cinit__(self, items=None): # <<<<<<<<<<<<<<
+ * self._root = NULL
+ * self._count = 0
+ */
+ values[0] = ((PyObject *)Py_None);
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (kw_args > 0) {
+ PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__items);
+ if (value) { values[0] = value; kw_args--; }
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else {
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ }
+ __pyx_v_items = values[0];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree___cinit__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), __pyx_v_items);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static int __pyx_pf_8bintrees_8qavltree_8cAVLTree___cinit__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_items) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__cinit__", 0);
+
+ /* "bintrees\qavltree.pyx":21
+ *
+ * def __cinit__(self, items=None):
+ * self._root = NULL # <<<<<<<<<<<<<<
+ * self._count = 0
+ * if items:
+ */
+ __pyx_v_self->_root = NULL;
+
+ /* "bintrees\qavltree.pyx":22
+ * def __cinit__(self, items=None):
+ * self._root = NULL
+ * self._count = 0 # <<<<<<<<<<<<<<
+ * if items:
+ * self.update(items)
+ */
+ __pyx_v_self->_count = 0;
+
+ /* "bintrees\qavltree.pyx":23
+ * self._root = NULL
+ * self._count = 0
+ * if items: # <<<<<<<<<<<<<<
+ * self.update(items)
+ *
+ */
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_items); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_t_1) {
+
+ /* "bintrees\qavltree.pyx":24
+ * self._count = 0
+ * if items:
+ * self.update(items) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_items);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_items);
+ __Pyx_GIVEREF(__pyx_v_items);
+ __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static void __pyx_pw_8bintrees_8qavltree_8cAVLTree_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_8bintrees_8qavltree_8cAVLTree_3__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_pf_8bintrees_8qavltree_8cAVLTree_2__dealloc__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "bintrees\qavltree.pyx":26
+ * self.update(items)
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * ct_delete_tree(self._root)
+ *
+ */
+
+static void __pyx_pf_8bintrees_8qavltree_8cAVLTree_2__dealloc__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
+
+ /* "bintrees\qavltree.pyx":27
+ *
+ * def __dealloc__(self):
+ * ct_delete_tree(self._root) # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ ct_delete_tree(__pyx_v_self->_root);
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("count (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_4count(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":30
+ *
+ * @property
+ * def count(self): # <<<<<<<<<<<<<<
+ * return self._count
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_4count(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("count", 0);
+
+ /* "bintrees\qavltree.pyx":31
+ * @property
+ * def count(self):
+ * return self._count # <<<<<<<<<<<<<<
+ *
+ * def __getstate__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_6__getstate__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":33
+ * return self._count
+ *
+ * def __getstate__(self): # <<<<<<<<<<<<<<
+ * return dict(self.items())
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_6__getstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__getstate__", 0);
+
+ /* "bintrees\qavltree.pyx":34
+ *
+ * def __getstate__(self):
+ * return dict(self.items()) # <<<<<<<<<<<<<<
+ *
+ * def __setstate__(self, state):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_8__setstate__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), ((PyObject *)__pyx_v_state));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":36
+ * return dict(self.items())
+ *
+ * def __setstate__(self, state): # <<<<<<<<<<<<<<
+ * self.update(state)
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_8__setstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_state) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setstate__", 0);
+
+ /* "bintrees\qavltree.pyx":37
+ *
+ * def __setstate__(self, state):
+ * self.update(state) # <<<<<<<<<<<<<<
+ *
+ * def clear(self):
+ */
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_state);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state);
+ __Pyx_GIVEREF(__pyx_v_state);
+ __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("clear (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_10clear(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":39
+ * self.update(state)
+ *
+ * def clear(self): # <<<<<<<<<<<<<<
+ * ct_delete_tree(self._root)
+ * self._count = 0
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_10clear(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("clear", 0);
+
+ /* "bintrees\qavltree.pyx":40
+ *
+ * def clear(self):
+ * ct_delete_tree(self._root) # <<<<<<<<<<<<<<
+ * self._count = 0
+ * self._root = NULL
+ */
+ ct_delete_tree(__pyx_v_self->_root);
+
+ /* "bintrees\qavltree.pyx":41
+ * def clear(self):
+ * ct_delete_tree(self._root)
+ * self._count = 0 # <<<<<<<<<<<<<<
+ * self._root = NULL
+ *
+ */
+ __pyx_v_self->_count = 0;
+
+ /* "bintrees\qavltree.pyx":42
+ * ct_delete_tree(self._root)
+ * self._count = 0
+ * self._root = NULL # <<<<<<<<<<<<<<
+ *
+ * def get_value(self, key):
+ */
+ __pyx_v_self->_root = NULL;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("get_value (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_12get_value(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":44
+ * self._root = NULL
+ *
+ * def get_value(self, key): # <<<<<<<<<<<<<<
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None:
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_12get_value(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_v_result = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_value", 0);
+
+ /* "bintrees\qavltree.pyx":45
+ *
+ * def get_value(self, key):
+ * result = <object> ct_get_item(self._root, key) # <<<<<<<<<<<<<<
+ * if result is None:
+ * raise KeyError(key)
+ */
+ __pyx_t_1 = ct_get_item(__pyx_v_self->_root, __pyx_v_key);
+ __Pyx_INCREF(((PyObject *)__pyx_t_1));
+ __pyx_v_result = ((PyObject *)__pyx_t_1);
+
+ /* "bintrees\qavltree.pyx":46
+ * def get_value(self, key):
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None: # <<<<<<<<<<<<<<
+ * raise KeyError(key)
+ * else:
+ */
+ __pyx_t_2 = (__pyx_v_result == Py_None);
+ if (__pyx_t_2) {
+
+ /* "bintrees\qavltree.pyx":47
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None:
+ * raise KeyError(key) # <<<<<<<<<<<<<<
+ * else:
+ * return result[1]
+ */
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qavltree.pyx":49
+ * raise KeyError(key)
+ * else:
+ * return result[1] # <<<<<<<<<<<<<<
+ *
+ * def get_walker(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_result, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_r = __pyx_t_4;
+ __pyx_t_4 = 0;
+ goto __pyx_L0;
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_result);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("get_walker (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_14get_walker(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":51
+ * return result[1]
+ *
+ * def get_walker(self): # <<<<<<<<<<<<<<
+ * cdef cWalker walker
+ * walker = cWalker()
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_14get_walker(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_walker = 0;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_walker", 0);
+
+ /* "bintrees\qavltree.pyx":53
+ * def get_walker(self):
+ * cdef cWalker walker
+ * walker = cWalker() # <<<<<<<<<<<<<<
+ * walker.set_tree(self._root)
+ * return walker
+ */
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8bintrees_7cwalker_cWalker)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_walker = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_t_1);
+ __pyx_t_1 = 0;
+
+ /* "bintrees\qavltree.pyx":54
+ * cdef cWalker walker
+ * walker = cWalker()
+ * walker.set_tree(self._root) # <<<<<<<<<<<<<<
+ * return walker
+ *
+ */
+ ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_walker->__pyx_vtab)->set_tree(__pyx_v_walker, __pyx_v_self->_root);
+
+ /* "bintrees\qavltree.pyx":55
+ * walker = cWalker()
+ * walker.set_tree(self._root)
+ * return walker # <<<<<<<<<<<<<<
+ *
+ * def insert(self, key, value):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_walker));
+ __pyx_r = ((PyObject *)__pyx_v_walker);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.get_walker", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_walker);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_key = 0;
+ PyObject *__pyx_v_value = 0;
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("insert (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__value,0};
+ PyObject* values[2] = {0,0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key)) != 0)) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ case 1:
+ if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ }
+ __pyx_v_key = values[0];
+ __pyx_v_value = values[1];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_16insert(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), __pyx_v_key, __pyx_v_value);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":57
+ * return walker
+ *
+ * def insert(self, key, value): # <<<<<<<<<<<<<<
+ * res = avl_insert(&self._root, key, value)
+ * if res < 0:
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_16insert(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) {
+ PyObject *__pyx_v_res = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_4;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("insert", 0);
+
+ /* "bintrees\qavltree.pyx":58
+ *
+ * def insert(self, key, value):
+ * res = avl_insert(&self._root, key, value) # <<<<<<<<<<<<<<
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.')
+ */
+ __pyx_t_1 = PyInt_FromLong(avl_insert((&__pyx_v_self->_root), __pyx_v_key, __pyx_v_value)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_res = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "bintrees\qavltree.pyx":59
+ * def insert(self, key, value):
+ * res = avl_insert(&self._root, key, value)
+ * if res < 0: # <<<<<<<<<<<<<<
+ * raise MemoryError('Can not allocate memory for node structure.')
+ * else:
+ */
+ __pyx_t_1 = PyObject_RichCompare(__pyx_v_res, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (__pyx_t_2) {
+
+ /* "bintrees\qavltree.pyx":60
+ * res = avl_insert(&self._root, key, value)
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<<
+ * else:
+ * self._count += res
+ */
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qavltree.pyx":62
+ * raise MemoryError('Can not allocate memory for node structure.')
+ * else:
+ * self._count += res # <<<<<<<<<<<<<<
+ *
+ * def remove(self, key):
+ */
+ __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_res); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_self->_count = __pyx_t_4;
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_res);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("remove (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_18remove(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":64
+ * self._count += res
+ *
+ * def remove(self, key): # <<<<<<<<<<<<<<
+ * cdef int result
+ * result = avl_remove(&self._root, key)
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_18remove(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key) {
+ int __pyx_v_result;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("remove", 0);
+
+ /* "bintrees\qavltree.pyx":66
+ * def remove(self, key):
+ * cdef int result
+ * result = avl_remove(&self._root, key) # <<<<<<<<<<<<<<
+ * if result == 0:
+ * raise KeyError(str(key))
+ */
+ __pyx_v_result = avl_remove((&__pyx_v_self->_root), __pyx_v_key);
+
+ /* "bintrees\qavltree.pyx":67
+ * cdef int result
+ * result = avl_remove(&self._root, key)
+ * if result == 0: # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * else:
+ */
+ __pyx_t_1 = (__pyx_v_result == 0);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qavltree.pyx":68
+ * result = avl_remove(&self._root, key)
+ * if result == 0:
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * else:
+ * self._count -= 1
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qavltree.pyx":70
+ * raise KeyError(str(key))
+ * else:
+ * self._count -= 1 # <<<<<<<<<<<<<<
+ *
+ * def max_item(self):
+ */
+ __pyx_v_self->_count = (__pyx_v_self->_count - 1);
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.remove", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_8qavltree_8cAVLTree_20max_item[] = " Get item with max key of tree, raises ValueError if tree is empty. ";
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("max_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_20max_item(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":72
+ * self._count -= 1
+ *
+ * def max_item(self): # <<<<<<<<<<<<<<
+ * """ Get item with max key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_20max_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ node_t *__pyx_v_node;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("max_item", 0);
+
+ /* "bintrees\qavltree.pyx":75
+ * """ Get item with max key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ * node = ct_max_node(self._root) # <<<<<<<<<<<<<<
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ */
+ __pyx_v_node = ct_max_node(__pyx_v_self->_root);
+
+ /* "bintrees\qavltree.pyx":76
+ * cdef node_t *node
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None # <<<<<<<<<<<<<<
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_1 = (__pyx_v_node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qavltree.pyx":77
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qavltree.pyx":78
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<<
+ *
+ * def min_item(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->key));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->value));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value));
+ __pyx_r = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.max_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_8qavltree_8cAVLTree_22min_item[] = " Get item with min key of tree, raises ValueError if tree is empty. ";
+static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("min_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_22min_item(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qavltree.pyx":80
+ * return (<object>node.key, <object>node.value)
+ *
+ * def min_item(self): # <<<<<<<<<<<<<<
+ * """ Get item with min key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_22min_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) {
+ node_t *__pyx_v_node;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("min_item", 0);
+
+ /* "bintrees\qavltree.pyx":83
+ * """ Get item with min key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ * node = ct_min_node(self._root) # <<<<<<<<<<<<<<
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ */
+ __pyx_v_node = ct_min_node(__pyx_v_self->_root);
+
+ /* "bintrees\qavltree.pyx":84
+ * cdef node_t *node
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None # <<<<<<<<<<<<<<
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_1 = (__pyx_v_node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qavltree.pyx":85
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qavltree.pyx":86
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<<
+ *
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->key));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->value));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value));
+ __pyx_r = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.min_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_tp_new_8bintrees_8qavltree_cAVLTree(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ if (__pyx_pw_8bintrees_8qavltree_8cAVLTree_1__cinit__(o, a, k) < 0) {
+ Py_DECREF(o); o = 0;
+ }
+ return o;
+}
+
+static void __pyx_tp_dealloc_8bintrees_8qavltree_cAVLTree(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pw_8bintrees_8qavltree_8cAVLTree_3__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_8bintrees_8qavltree_cAVLTree[] = {
+ {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_5count, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_7__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_9__setstate__, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_11clear, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("get_value"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_13get_value, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("get_walker"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_15get_walker, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_17insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("remove"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_19remove, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("max_item"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_21max_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qavltree_8cAVLTree_20max_item)},
+ {__Pyx_NAMESTR("min_item"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_23min_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qavltree_8cAVLTree_22min_item)},
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_cAVLTree = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_cAVLTree = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_cAVLTree = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_cAVLTree = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_8bintrees_8qavltree_cAVLTree = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("bintrees.qavltree.cAVLTree"), /*tp_name*/
+ sizeof(struct __pyx_obj_8bintrees_8qavltree_cAVLTree), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_8bintrees_8qavltree_cAVLTree, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_cAVLTree, /*tp_as_number*/
+ &__pyx_tp_as_sequence_cAVLTree, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_cAVLTree, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_cAVLTree, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_8bintrees_8qavltree_cAVLTree, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_8bintrees_8qavltree_cAVLTree, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+ {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef __pyx_moduledef = {
+ PyModuleDef_HEAD_INIT,
+ __Pyx_NAMESTR("qavltree"),
+ 0, /* m_doc */
+ -1, /* m_size */
+ __pyx_methods /* m_methods */,
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
+};
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+ {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
+ {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
+ {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
+ {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1},
+ {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
+ {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
+ {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
+ {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
+ {&__pyx_n_s__cAVLTree, __pyx_k__cAVLTree, sizeof(__pyx_k__cAVLTree), 0, 0, 1, 1},
+ {&__pyx_n_s__cWalker, __pyx_k__cWalker, sizeof(__pyx_k__cWalker), 0, 0, 1, 1},
+ {&__pyx_n_s__count, __pyx_k__count, sizeof(__pyx_k__count), 0, 0, 1, 1},
+ {&__pyx_n_s__cwalker, __pyx_k__cwalker, sizeof(__pyx_k__cwalker), 0, 0, 1, 1},
+ {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1},
+ {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
+ {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1},
+ {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1},
+ {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0}
+};
+static int __Pyx_InitCachedBuiltins(void) {
+ __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+static int __Pyx_InitCachedConstants(void) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
+
+ /* "bintrees\qavltree.pyx":60
+ * res = avl_insert(&self._root, key, value)
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<<
+ * else:
+ * self._count += res
+ */
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_2);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
+
+ /* "bintrees\qavltree.pyx":77
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_4);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
+
+ /* "bintrees\qavltree.pyx":85
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_5);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
+ __Pyx_RefNannyFinishContext();
+ return 0;
+ __pyx_L1_error:;
+ __Pyx_RefNannyFinishContext();
+ return -1;
+}
+
+static int __Pyx_InitGlobals(void) {
+ if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC initqavltree(void); /*proto*/
+PyMODINIT_FUNC initqavltree(void)
+#else
+PyMODINIT_FUNC PyInit_qavltree(void); /*proto*/
+PyMODINIT_FUNC PyInit_qavltree(void)
+#endif
+{
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ __Pyx_RefNannyDeclarations
+ #if CYTHON_REFNANNY
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+ if (!__Pyx_RefNanny) {
+ PyErr_Clear();
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+ if (!__Pyx_RefNanny)
+ Py_FatalError("failed to import 'refnanny' module");
+ }
+ #endif
+ __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_qavltree(void)", 0);
+ if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #ifdef __Pyx_CyFunction_USED
+ if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_FusedFunction_USED
+ if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_Generator_USED
+ if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ /*--- Library function declarations ---*/
+ /*--- Threads initialization code ---*/
+ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+ #ifdef WITH_THREAD /* Python build with threading support? */
+ PyEval_InitThreads();
+ #endif
+ #endif
+ /*--- Module creation code ---*/
+ #if PY_MAJOR_VERSION < 3
+ __pyx_m = Py_InitModule4(__Pyx_NAMESTR("qavltree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+ #else
+ __pyx_m = PyModule_Create(&__pyx_moduledef);
+ #endif
+ if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if PY_MAJOR_VERSION >= 3
+ {
+ PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!PyDict_GetItemString(modules, "bintrees.qavltree")) {
+ if (unlikely(PyDict_SetItemString(modules, "bintrees.qavltree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ }
+ #endif
+ __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if CYTHON_COMPILING_IN_PYPY
+ Py_INCREF(__pyx_b);
+ #endif
+ if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ /*--- Initialize various global constants etc. ---*/
+ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_module_is_main_bintrees__qavltree) {
+ if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ }
+ /*--- Builtin init code ---*/
+ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Constants init code ---*/
+ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Global init code ---*/
+ /*--- Variable export code ---*/
+ /*--- Function export code ---*/
+ /*--- Type init code ---*/
+ if (PyType_Ready(&__pyx_type_8bintrees_8qavltree_cAVLTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "cAVLTree", (PyObject *)&__pyx_type_8bintrees_8qavltree_cAVLTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_8bintrees_8qavltree_cAVLTree = &__pyx_type_8bintrees_8qavltree_cAVLTree;
+ /*--- Type import code ---*/
+ __pyx_ptype_8bintrees_7cwalker_cWalker = __Pyx_ImportType("bintrees.cwalker", "cWalker", sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), 1); if (unlikely(!__pyx_ptype_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_vtabptr_8bintrees_7cwalker_cWalker = (struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker*)__Pyx_GetVtable(__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict); if (unlikely(!__pyx_vtabptr_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Variable import code ---*/
+ /*--- Function import code ---*/
+ /*--- Execution code ---*/
+
+ /* "bintrees\qavltree.pyx":9
+ * # License: MIT License
+ *
+ * __all__ = ['cAVLTree'] # <<<<<<<<<<<<<<
+ *
+ * from cwalker import cWalker
+ */
+ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__cAVLTree));
+ PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cAVLTree));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cAVLTree));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+
+ /* "bintrees\qavltree.pyx":11
+ * __all__ = ['cAVLTree']
+ *
+ * from cwalker import cWalker # <<<<<<<<<<<<<<
+ *
+ * from cwalker cimport *
+ */
+ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__cWalker));
+ PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cWalker));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cWalker));
+ __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__cwalker), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+ /* "bintrees\qavltree.pyx":30
+ *
+ * @property
+ * def count(self): # <<<<<<<<<<<<<<
+ * return self._count
+ *
+ */
+ __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_8qavltree_cAVLTree, __pyx_n_s__count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_8qavltree_cAVLTree->tp_dict, __pyx_n_s__count, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_8qavltree_cAVLTree);
+
+ /* "bintrees\qavltree.pyx":1
+ * #!/usr/bin/env python # <<<<<<<<<<<<<<
+ * #coding:utf-8
+ * # Author: mozman
+ */
+ __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ if (__pyx_m) {
+ __Pyx_AddTraceback("init bintrees.qavltree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ Py_DECREF(__pyx_m); __pyx_m = 0;
+ } else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "init bintrees.qavltree");
+ }
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ #if PY_MAJOR_VERSION < 3
+ return;
+ #else
+ return __pyx_m;
+ #endif
+}
+
+/* Runtime support code */
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+ PyObject *m = NULL, *p = NULL;
+ void *r = NULL;
+ m = PyImport_ImportModule((char *)modname);
+ if (!m) goto end;
+ p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
+ if (!p) goto end;
+ r = PyLong_AsVoidPtr(p);
+end:
+ Py_XDECREF(p);
+ Py_XDECREF(m);
+ return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif /* CYTHON_REFNANNY */
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result) {
+ if (dict != __pyx_b) {
+ PyErr_Clear();
+ result = PyObject_GetAttr(__pyx_b, name);
+ }
+ if (!result) {
+ PyErr_SetObject(PyExc_NameError, name);
+ }
+ }
+ return result;
+}
+
+static void __Pyx_RaiseDoubleKeywordsError(
+ const char* func_name,
+ PyObject* kw_name)
+{
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION >= 3
+ "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+ #else
+ "%s() got multiple values for keyword argument '%s'", func_name,
+ PyString_AsString(kw_name));
+ #endif
+}
+
+static int __Pyx_ParseOptionalKeywords(
+ PyObject *kwds,
+ PyObject **argnames[],
+ PyObject *kwds2,
+ PyObject *values[],
+ Py_ssize_t num_pos_args,
+ const char* function_name)
+{
+ PyObject *key = 0, *value = 0;
+ Py_ssize_t pos = 0;
+ PyObject*** name;
+ PyObject*** first_kw_arg = argnames + num_pos_args;
+ while (PyDict_Next(kwds, &pos, &key, &value)) {
+ name = first_kw_arg;
+ while (*name && (**name != key)) name++;
+ if (*name) {
+ values[name-argnames] = value;
+ continue;
+ }
+ name = first_kw_arg;
+ #if PY_MAJOR_VERSION < 3
+ if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
+ while (*name) {
+ if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
+ && _PyString_Eq(**name, key)) {
+ values[name-argnames] = value;
+ break;
+ }
+ name++;
+ }
+ if (*name) continue;
+ else {
+ PyObject*** argname = argnames;
+ while (argname != first_kw_arg) {
+ if ((**argname == key) || (
+ (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
+ && _PyString_Eq(**argname, key))) {
+ goto arg_passed_twice;
+ }
+ argname++;
+ }
+ }
+ } else
+ #endif
+ if (likely(PyUnicode_Check(key))) {
+ while (*name) {
+ int cmp = (**name == key) ? 0 :
+ #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+ (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
+ #endif
+ PyUnicode_Compare(**name, key);
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+ if (cmp == 0) {
+ values[name-argnames] = value;
+ break;
+ }
+ name++;
+ }
+ if (*name) continue;
+ else {
+ PyObject*** argname = argnames;
+ while (argname != first_kw_arg) {
+ int cmp = (**argname == key) ? 0 :
+ #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+ (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
+ #endif
+ PyUnicode_Compare(**argname, key);
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+ if (cmp == 0) goto arg_passed_twice;
+ argname++;
+ }
+ }
+ } else
+ goto invalid_keyword_type;
+ if (kwds2) {
+ if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+ } else {
+ goto invalid_keyword;
+ }
+ }
+ return 0;
+arg_passed_twice:
+ __Pyx_RaiseDoubleKeywordsError(function_name, key);
+ goto bad;
+invalid_keyword_type:
+ PyErr_Format(PyExc_TypeError,
+ "%s() keywords must be strings", function_name);
+ goto bad;
+invalid_keyword:
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION < 3
+ "%s() got an unexpected keyword argument '%s'",
+ function_name, PyString_AsString(key));
+ #else
+ "%s() got an unexpected keyword argument '%U'",
+ function_name, key);
+ #endif
+bad:
+ return -1;
+}
+
+static void __Pyx_RaiseArgtupleInvalid(
+ const char* func_name,
+ int exact,
+ Py_ssize_t num_min,
+ Py_ssize_t num_max,
+ Py_ssize_t num_found)
+{
+ Py_ssize_t num_expected;
+ const char *more_or_less;
+ if (num_found < num_min) {
+ num_expected = num_min;
+ more_or_less = "at least";
+ } else {
+ num_expected = num_max;
+ more_or_less = "at most";
+ }
+ if (exact) {
+ more_or_less = "exactly";
+ }
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
+ func_name, more_or_less, num_expected,
+ (num_expected == 1) ? "" : "s", num_found);
+}
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+ tmp_type = tstate->curexc_type;
+ tmp_value = tstate->curexc_value;
+ tmp_tb = tstate->curexc_traceback;
+ tstate->curexc_type = type;
+ tstate->curexc_value = value;
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+#else
+ PyErr_Restore(type, value, tb);
+#endif
+}
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->curexc_type;
+ *value = tstate->curexc_value;
+ *tb = tstate->curexc_traceback;
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+#else
+ PyErr_Fetch(type, value, tb);
+#endif
+}
+
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
+ CYTHON_UNUSED PyObject *cause) {
+ Py_XINCREF(type);
+ if (!value || value == Py_None)
+ value = NULL;
+ else
+ Py_INCREF(value);
+ if (!tb || tb == Py_None)
+ tb = NULL;
+ else {
+ Py_INCREF(tb);
+ if (!PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto raise_error;
+ }
+ }
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyClass_Check(type)) {
+ #else
+ if (PyType_Check(type)) {
+ #endif
+#if CYTHON_COMPILING_IN_PYPY
+ if (!value) {
+ Py_INCREF(Py_None);
+ value = Py_None;
+ }
+#endif
+ PyErr_NormalizeException(&type, &value, &tb);
+ } else {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto raise_error;
+ }
+ value = type;
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyInstance_Check(type)) {
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
+ }
+ else {
+ type = 0;
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception must be an old-style class or instance");
+ goto raise_error;
+ }
+ #else
+ type = (PyObject*) Py_TYPE(type);
+ Py_INCREF(type);
+ if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto raise_error;
+ }
+ #endif
+ }
+ __Pyx_ErrRestore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ return;
+}
+#else /* Python 3+ */
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+ PyObject* owned_instance = NULL;
+ if (tb == Py_None) {
+ tb = 0;
+ } else if (tb && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto bad;
+ }
+ if (value == Py_None)
+ value = 0;
+ if (PyExceptionInstance_Check(type)) {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto bad;
+ }
+ value = type;
+ type = (PyObject*) Py_TYPE(value);
+ } else if (PyExceptionClass_Check(type)) {
+ PyObject *args;
+ if (!value)
+ args = PyTuple_New(0);
+ else if (PyTuple_Check(value)) {
+ Py_INCREF(value);
+ args = value;
+ }
+ else
+ args = PyTuple_Pack(1, value);
+ if (!args)
+ goto bad;
+ owned_instance = PyEval_CallObject(type, args);
+ Py_DECREF(args);
+ if (!owned_instance)
+ goto bad;
+ value = owned_instance;
+ if (!PyExceptionInstance_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "calling %R should have returned an instance of "
+ "BaseException, not %R",
+ type, Py_TYPE(value));
+ goto bad;
+ }
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto bad;
+ }
+ if (cause && cause != Py_None) {
+ PyObject *fixed_cause;
+ if (PyExceptionClass_Check(cause)) {
+ fixed_cause = PyObject_CallObject(cause, NULL);
+ if (fixed_cause == NULL)
+ goto bad;
+ }
+ else if (PyExceptionInstance_Check(cause)) {
+ fixed_cause = cause;
+ Py_INCREF(fixed_cause);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
+ goto bad;
+ }
+ PyException_SetCause(value, fixed_cause);
+ }
+ PyErr_SetObject(type, value);
+ if (tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ PyObject* tmp_tb = tstate->curexc_traceback;
+ if (tb != tmp_tb) {
+ Py_INCREF(tb);
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_tb);
+ }
+ }
+bad:
+ Py_XDECREF(owned_instance);
+ return;
+}
+#endif
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
+ PyObject *py_import = 0;
+ PyObject *empty_list = 0;
+ PyObject *module = 0;
+ PyObject *global_dict = 0;
+ PyObject *empty_dict = 0;
+ PyObject *list;
+ py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
+ if (!py_import)
+ goto bad;
+ if (from_list)
+ list = from_list;
+ else {
+ empty_list = PyList_New(0);
+ if (!empty_list)
+ goto bad;
+ list = empty_list;
+ }
+ global_dict = PyModule_GetDict(__pyx_m);
+ if (!global_dict)
+ goto bad;
+ empty_dict = PyDict_New();
+ if (!empty_dict)
+ goto bad;
+ #if PY_VERSION_HEX >= 0x02050000
+ {
+ #if PY_MAJOR_VERSION >= 3
+ if (level == -1) {
+ if (strchr(__Pyx_MODULE_NAME, '.')) {
+ /* try package relative import first */
+ PyObject *py_level = PyInt_FromLong(1);
+ if (!py_level)
+ goto bad;
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, py_level, NULL);
+ Py_DECREF(py_level);
+ if (!module) {
+ if (!PyErr_ExceptionMatches(PyExc_ImportError))
+ goto bad;
+ PyErr_Clear();
+ }
+ }
+ level = 0; /* try absolute import on failure */
+ }
+ #endif
+ if (!module) {
+ PyObject *py_level = PyInt_FromLong(level);
+ if (!py_level)
+ goto bad;
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, py_level, NULL);
+ Py_DECREF(py_level);
+ }
+ }
+ #else
+ if (level>0) {
+ PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
+ goto bad;
+ }
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, NULL);
+ #endif
+bad:
+ Py_XDECREF(empty_list);
+ Py_XDECREF(py_import);
+ Py_XDECREF(empty_dict);
+ return module;
+}
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
+ const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned char" :
+ "value too large to convert to unsigned char");
+ }
+ return (unsigned char)-1;
+ }
+ return (unsigned char)val;
+ }
+ return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
+ const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned short" :
+ "value too large to convert to unsigned short");
+ }
+ return (unsigned short)-1;
+ }
+ return (unsigned short)val;
+ }
+ return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
+ const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned int" :
+ "value too large to convert to unsigned int");
+ }
+ return (unsigned int)-1;
+ }
+ return (unsigned int)val;
+ }
+ return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
+ const char neg_one = (char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to char" :
+ "value too large to convert to char");
+ }
+ return (char)-1;
+ }
+ return (char)val;
+ }
+ return (char)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
+ const short neg_one = (short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to short" :
+ "value too large to convert to short");
+ }
+ return (short)-1;
+ }
+ return (short)val;
+ }
+ return (short)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
+ const signed char neg_one = (signed char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed char" :
+ "value too large to convert to signed char");
+ }
+ return (signed char)-1;
+ }
+ return (signed char)val;
+ }
+ return (signed char)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
+ const signed short neg_one = (signed short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed short" :
+ "value too large to convert to signed short");
+ }
+ return (signed short)-1;
+ }
+ return (signed short)val;
+ }
+ return (signed short)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
+ const signed int neg_one = (signed int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed int" :
+ "value too large to convert to signed int");
+ }
+ return (signed int)-1;
+ }
+ return (signed int)val;
+ }
+ return (signed int)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
+ const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (unsigned long)PyLong_AsLong(x);
+ }
+ } else {
+ unsigned long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned long)-1;
+ val = __Pyx_PyInt_AsUnsignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
+ const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ unsigned PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
+ const long neg_one = (long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (long)PyLong_AsLong(x);
+ }
+ } else {
+ long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (long)-1;
+ val = __Pyx_PyInt_AsLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
+ const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
+ const signed long neg_one = (signed long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (signed long)PyLong_AsLong(x);
+ }
+ } else {
+ signed long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed long)-1;
+ val = __Pyx_PyInt_AsSignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
+ const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ signed PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsSignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static int __Pyx_check_binary_version(void) {
+ char ctversion[4], rtversion[4];
+ PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+ PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+ if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+ char message[200];
+ PyOS_snprintf(message, sizeof(message),
+ "compiletime version %s of module '%.100s' "
+ "does not match runtime version %s",
+ ctversion, __Pyx_MODULE_NAME, rtversion);
+ #if PY_VERSION_HEX < 0x02050000
+ return PyErr_Warn(NULL, message);
+ #else
+ return PyErr_WarnEx(NULL, message, 1);
+ #endif
+ }
+ return 0;
+}
+
+#ifndef __PYX_HAVE_RT_ImportModule
+#define __PYX_HAVE_RT_ImportModule
+static PyObject *__Pyx_ImportModule(const char *name) {
+ PyObject *py_name = 0;
+ PyObject *py_module = 0;
+ py_name = __Pyx_PyIdentifier_FromString(name);
+ if (!py_name)
+ goto bad;
+ py_module = PyImport_Import(py_name);
+ Py_DECREF(py_name);
+ return py_module;
+bad:
+ Py_XDECREF(py_name);
+ return 0;
+}
+#endif
+
+#ifndef __PYX_HAVE_RT_ImportType
+#define __PYX_HAVE_RT_ImportType
+static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
+ size_t size, int strict)
+{
+ PyObject *py_module = 0;
+ PyObject *result = 0;
+ PyObject *py_name = 0;
+ char warning[200];
+ py_module = __Pyx_ImportModule(module_name);
+ if (!py_module)
+ goto bad;
+ py_name = __Pyx_PyIdentifier_FromString(class_name);
+ if (!py_name)
+ goto bad;
+ result = PyObject_GetAttr(py_module, py_name);
+ Py_DECREF(py_name);
+ py_name = 0;
+ Py_DECREF(py_module);
+ py_module = 0;
+ if (!result)
+ goto bad;
+ if (!PyType_Check(result)) {
+ PyErr_Format(PyExc_TypeError,
+ "%s.%s is not a type object",
+ module_name, class_name);
+ goto bad;
+ }
+ if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) {
+ PyOS_snprintf(warning, sizeof(warning),
+ "%s.%s size changed, may indicate binary incompatibility",
+ module_name, class_name);
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyErr_Warn(NULL, warning) < 0) goto bad;
+ #else
+ if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
+ #endif
+ }
+ else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) {
+ PyErr_Format(PyExc_ValueError,
+ "%s.%s has the wrong size, try recompiling",
+ module_name, class_name);
+ goto bad;
+ }
+ return (PyTypeObject *)result;
+bad:
+ Py_XDECREF(py_module);
+ Py_XDECREF(result);
+ return NULL;
+}
+#endif
+
+static void* __Pyx_GetVtable(PyObject *dict) {
+ void* ptr;
+ PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
+ if (!ob)
+ goto bad;
+#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
+ ptr = PyCapsule_GetPointer(ob, 0);
+#else
+ ptr = PyCObject_AsVoidPtr(ob);
+#endif
+ if (!ptr && !PyErr_Occurred())
+ PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
+ Py_DECREF(ob);
+ return ptr;
+bad:
+ Py_XDECREF(ob);
+ return NULL;
+}
+
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+ int start = 0, mid = 0, end = count - 1;
+ if (end >= 0 && code_line > entries[end].code_line) {
+ return count;
+ }
+ while (start < end) {
+ mid = (start + end) / 2;
+ if (code_line < entries[mid].code_line) {
+ end = mid;
+ } else if (code_line > entries[mid].code_line) {
+ start = mid + 1;
+ } else {
+ return mid;
+ }
+ }
+ if (code_line <= entries[mid].code_line) {
+ return mid;
+ } else {
+ return mid + 1;
+ }
+}
+static PyCodeObject *__pyx_find_code_object(int code_line) {
+ PyCodeObject* code_object;
+ int pos;
+ if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
+ return NULL;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
+ return NULL;
+ }
+ code_object = __pyx_code_cache.entries[pos].code_object;
+ Py_INCREF(code_object);
+ return code_object;
+}
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
+ int pos, i;
+ __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
+ if (unlikely(!code_line)) {
+ return;
+ }
+ if (unlikely(!entries)) {
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (likely(entries)) {
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = 64;
+ __pyx_code_cache.count = 1;
+ entries[0].code_line = code_line;
+ entries[0].code_object = code_object;
+ Py_INCREF(code_object);
+ }
+ return;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
+ PyCodeObject* tmp = entries[pos].code_object;
+ entries[pos].code_object = code_object;
+ Py_DECREF(tmp);
+ return;
+ }
+ if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
+ int new_max = __pyx_code_cache.max_count + 64;
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
+ __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (unlikely(!entries)) {
+ return;
+ }
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = new_max;
+ }
+ for (i=__pyx_code_cache.count; i>pos; i--) {
+ entries[i] = entries[i-1];
+ }
+ entries[pos].code_line = code_line;
+ entries[pos].code_object = code_object;
+ __pyx_code_cache.count++;
+ Py_INCREF(code_object);
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
+ const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ #if PY_MAJOR_VERSION < 3
+ py_srcfile = PyString_FromString(filename);
+ #else
+ py_srcfile = PyUnicode_FromString(filename);
+ #endif
+ if (!py_srcfile) goto bad;
+ if (c_line) {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #else
+ py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #endif
+ }
+ else {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromString(funcname);
+ #else
+ py_funcname = PyUnicode_FromString(funcname);
+ #endif
+ }
+ if (!py_funcname) goto bad;
+ py_code = __Pyx_PyCode_New(
+ 0, /*int argcount,*/
+ 0, /*int kwonlyargcount,*/
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ __pyx_empty_bytes, /*PyObject *code,*/
+ __pyx_empty_tuple, /*PyObject *consts,*/
+ __pyx_empty_tuple, /*PyObject *names,*/
+ __pyx_empty_tuple, /*PyObject *varnames,*/
+ __pyx_empty_tuple, /*PyObject *freevars,*/
+ __pyx_empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ py_line, /*int firstlineno,*/
+ __pyx_empty_bytes /*PyObject *lnotab*/
+ );
+ Py_DECREF(py_srcfile);
+ Py_DECREF(py_funcname);
+ return py_code;
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ return NULL;
+}
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_globals = 0;
+ PyFrameObject *py_frame = 0;
+ py_code = __pyx_find_code_object(c_line ? c_line : py_line);
+ if (!py_code) {
+ py_code = __Pyx_CreateCodeObjectForTraceback(
+ funcname, c_line, py_line, filename);
+ if (!py_code) goto bad;
+ __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
+ }
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_GET(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = py_line;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+ while (t->p) {
+ #if PY_MAJOR_VERSION < 3
+ if (t->is_unicode) {
+ *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+ } else if (t->intern) {
+ *t->p = PyString_InternFromString(t->s);
+ } else {
+ *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+ }
+ #else /* Python 3+ has unicode identifiers */
+ if (t->is_unicode | t->is_str) {
+ if (t->intern) {
+ *t->p = PyUnicode_InternFromString(t->s);
+ } else if (t->encoding) {
+ *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+ } else {
+ *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+ }
+ } else {
+ *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+ }
+ #endif
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+
+/* Type Conversion Functions */
+
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+ int is_true = x == Py_True;
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+ else return PyObject_IsTrue(x);
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
+ PyNumberMethods *m;
+ const char *name = NULL;
+ PyObject *res = NULL;
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_Check(x) || PyLong_Check(x))
+#else
+ if (PyLong_Check(x))
+#endif
+ return Py_INCREF(x), x;
+ m = Py_TYPE(x)->tp_as_number;
+#if PY_VERSION_HEX < 0x03000000
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Int(x);
+ }
+ else if (m && m->nb_long) {
+ name = "long";
+ res = PyNumber_Long(x);
+ }
+#else
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Long(x);
+ }
+#endif
+ if (res) {
+#if PY_VERSION_HEX < 0x03000000
+ if (!PyInt_Check(res) && !PyLong_Check(res)) {
+#else
+ if (!PyLong_Check(res)) {
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "__%s__ returned non-%s (type %.200s)",
+ name, name, Py_TYPE(res)->tp_name);
+ Py_DECREF(res);
+ return NULL;
+ }
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "an integer is required");
+ }
+ return res;
+}
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+ Py_ssize_t ival;
+ PyObject* x = PyNumber_Index(b);
+ if (!x) return -1;
+ ival = PyInt_AsSsize_t(x);
+ Py_DECREF(x);
+ return ival;
+}
+
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+#if PY_VERSION_HEX < 0x02050000
+ if (ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ else {
+ unsigned char *bytes = (unsigned char *) &ival;
+ int one = 1; int little = (int)*(unsigned char*)&one;
+ return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
+ }
+#else
+ return PyInt_FromSize_t(ival);
+#endif
+}
+
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
+ unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
+ if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
+ return (size_t)-1;
+ } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "value too large to convert to size_t");
+ return (size_t)-1;
+ }
+ return (size_t)val;
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/chromium/third_party/bintrees/bintrees/qavltree.pyx b/chromium/third_party/bintrees/bintrees/qavltree.pyx
new file mode 100644
index 00000000000..b6844b81641
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/qavltree.pyx
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: cython unbalanced binary tree module
+# Created: 28.04.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+__all__ = ['cAVLTree']
+
+from cwalker import cWalker
+
+from cwalker cimport *
+from ctrees cimport *
+
+cdef class cAVLTree:
+ cdef node_t *_root
+ cdef int _count
+
+ def __cinit__(self, items=None):
+ self._root = NULL
+ self._count = 0
+ if items:
+ self.update(items)
+
+ def __dealloc__(self):
+ ct_delete_tree(self._root)
+
+ @property
+ def count(self):
+ return self._count
+
+ def __getstate__(self):
+ return dict(self.items())
+
+ def __setstate__(self, state):
+ self.update(state)
+
+ def clear(self):
+ ct_delete_tree(self._root)
+ self._count = 0
+ self._root = NULL
+
+ def get_value(self, key):
+ result = <object> ct_get_item(self._root, key)
+ if result is None:
+ raise KeyError(key)
+ else:
+ return result[1]
+
+ def get_walker(self):
+ cdef cWalker walker
+ walker = cWalker()
+ walker.set_tree(self._root)
+ return walker
+
+ def insert(self, key, value):
+ res = avl_insert(&self._root, key, value)
+ if res < 0:
+ raise MemoryError('Can not allocate memory for node structure.')
+ else:
+ self._count += res
+
+ def remove(self, key):
+ cdef int result
+ result = avl_remove(&self._root, key)
+ if result == 0:
+ raise KeyError(str(key))
+ else:
+ self._count -= 1
+
+ def max_item(self):
+ """ Get item with max key of tree, raises ValueError if tree is empty. """
+ cdef node_t *node
+ node = ct_max_node(self._root)
+ if node == NULL: # root is None
+ raise ValueError("Tree is empty")
+ return (<object>node.key, <object>node.value)
+
+ def min_item(self):
+ """ Get item with min key of tree, raises ValueError if tree is empty. """
+ cdef node_t *node
+ node = ct_min_node(self._root)
+ if node == NULL: # root is None
+ raise ValueError("Tree is empty")
+ return (<object>node.key, <object>node.value)
+
diff --git a/chromium/third_party/bintrees/bintrees/qbintree.c b/chromium/third_party/bintrees/bintrees/qbintree.c
new file mode 100644
index 00000000000..e3c390d8fce
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/qbintree.c
@@ -0,0 +1,3397 @@
+/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+ #error Python headers needed to compile C extensions, please install development version of Python.
+#elif PY_VERSION_HEX < 0x02040000
+ #error Cython requires Python 2.4+.
+#else
+#include <stddef.h> /* For offsetof */
+#ifndef offsetof
+#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+ #ifndef __stdcall
+ #define __stdcall
+ #endif
+ #ifndef __cdecl
+ #define __cdecl
+ #endif
+ #ifndef __fastcall
+ #define __fastcall
+ #endif
+#endif
+#ifndef DL_IMPORT
+ #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+ #define DL_EXPORT(t) t
+#endif
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef Py_HUGE_VAL
+ #define Py_HUGE_VAL HUGE_VAL
+#endif
+#ifdef PYPY_VERSION
+#define CYTHON_COMPILING_IN_PYPY 1
+#define CYTHON_COMPILING_IN_CPYTHON 0
+#else
+#define CYTHON_COMPILING_IN_PYPY 0
+#define CYTHON_COMPILING_IN_CPYTHON 1
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+ #define PY_SSIZE_T_MAX INT_MAX
+ #define PY_SSIZE_T_MIN INT_MIN
+ #define PY_FORMAT_SIZE_T ""
+ #define CYTHON_FORMAT_SSIZE_T ""
+ #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+ #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
+ #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
+ (PyErr_Format(PyExc_TypeError, \
+ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
+ (PyObject*)0))
+ #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
+ !PyComplex_Check(o))
+ #define PyIndex_Check __Pyx_PyIndex_Check
+ #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
+ #define __PYX_BUILD_PY_SSIZE_T "i"
+#else
+ #define __PYX_BUILD_PY_SSIZE_T "n"
+ #define CYTHON_FORMAT_SSIZE_T "z"
+ #define __Pyx_PyIndex_Check PyIndex_Check
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+ #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+ #define PyVarObject_HEAD_INIT(type, size) \
+ PyObject_HEAD_INIT(type) size,
+ #define PyType_Modified(t)
+ typedef struct {
+ void *buf;
+ PyObject *obj;
+ Py_ssize_t len;
+ Py_ssize_t itemsize;
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets;
+ void *internal;
+ } Py_buffer;
+ #define PyBUF_SIMPLE 0
+ #define PyBUF_WRITABLE 0x0001
+ #define PyBUF_FORMAT 0x0004
+ #define PyBUF_ND 0x0008
+ #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+ #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+ #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+ #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+ #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
+ #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
+ #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
+ typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
+ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
+#endif
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#else
+ #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#endif
+#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
+ #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define Py_TPFLAGS_CHECKTYPES 0
+ #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+ #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
+ #define CYTHON_PEP393_ENABLED 1
+ #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \
+ 0 : _PyUnicode_Ready((PyObject *)(op)))
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
+ #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
+#else
+ #define CYTHON_PEP393_ENABLED 0
+ #define __Pyx_PyUnicode_READY(op) (0)
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
+ #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBaseString_Type PyUnicode_Type
+ #define PyStringObject PyUnicodeObject
+ #define PyString_Type PyUnicode_Type
+ #define PyString_Check PyUnicode_Check
+ #define PyString_CheckExact PyUnicode_CheckExact
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PyBytesObject PyStringObject
+ #define PyBytes_Type PyString_Type
+ #define PyBytes_Check PyString_Check
+ #define PyBytes_CheckExact PyString_CheckExact
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+ #define PyBytes_FromFormat PyString_FromFormat
+ #define PyBytes_DecodeEscape PyString_DecodeEscape
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_AS_STRING PyString_AS_STRING
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
+ #define PyBytes_Repr PyString_Repr
+ #define PyBytes_Concat PyString_Concat
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+#ifndef PySet_CheckExact
+ #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
+#endif
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+#if PY_MAJOR_VERSION >= 3
+ #define PyIntObject PyLongObject
+ #define PyInt_Type PyLong_Type
+ #define PyInt_Check(op) PyLong_Check(op)
+ #define PyInt_CheckExact(op) PyLong_CheckExact(op)
+ #define PyInt_FromString PyLong_FromString
+ #define PyInt_FromUnicode PyLong_FromUnicode
+ #define PyInt_FromLong PyLong_FromLong
+ #define PyInt_FromSize_t PyLong_FromSize_t
+ #define PyInt_FromSsize_t PyLong_FromSsize_t
+ #define PyInt_AsLong PyLong_AsLong
+ #define PyInt_AS_LONG PyLong_AS_LONG
+ #define PyInt_AsSsize_t PyLong_AsSsize_t
+ #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
+ #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBoolObject PyLongObject
+#endif
+#if PY_VERSION_HEX < 0x03020000
+ typedef long Py_hash_t;
+ #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+ #define __Pyx_PyInt_AsHash_t PyInt_AsLong
+#else
+ #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+ #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
+#endif
+#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
+ #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
+ #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
+#else
+ #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
+ #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
+#else
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_NAMESTR(n) ((char *)(n))
+ #define __Pyx_DOCSTR(n) ((char *)(n))
+#else
+ #define __Pyx_NAMESTR(n) (n)
+ #define __Pyx_DOCSTR(n) (n)
+#endif
+
+
+#if PY_MAJOR_VERSION >= 3
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
+#else
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
+#endif
+
+#ifndef __PYX_EXTERN_C
+ #ifdef __cplusplus
+ #define __PYX_EXTERN_C extern "C"
+ #else
+ #define __PYX_EXTERN_C extern
+ #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#define __PYX_HAVE__bintrees__qbintree
+#define __PYX_HAVE_API__bintrees__qbintree
+#include "ctrees.h"
+#include "stack.h"
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#ifdef PYREX_WITHOUT_ASSERTIONS
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+
+/* inline attribute */
+#ifndef CYTHON_INLINE
+ #if defined(__GNUC__)
+ #define CYTHON_INLINE __inline__
+ #elif defined(_MSC_VER)
+ #define CYTHON_INLINE __inline
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_INLINE inline
+ #else
+ #define CYTHON_INLINE
+ #endif
+#endif
+
+/* unused attribute */
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+#endif
+
+typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
+
+
+/* Type Conversion Predeclarations */
+
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
+
+#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
+
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+#else
+#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
+#endif
+#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
+
+#ifdef __GNUC__
+ /* Test for GCC > 2.95 */
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
+ #define likely(x) __builtin_expect(!!(x), 1)
+ #define unlikely(x) __builtin_expect(!!(x), 0)
+ #else /* __GNUC__ > 2 ... */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+ #endif /* __GNUC__ > 2 ... */
+#else /* __GNUC__ */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+#endif /* __GNUC__ */
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+ "qbintree.pyx",
+ "cwalker.pxd",
+};
+
+/*--- Type declarations ---*/
+struct __pyx_obj_8bintrees_7cwalker_cWalker;
+struct __pyx_obj_8bintrees_8qbintree_cBinaryTree;
+
+/* "cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+struct __pyx_obj_8bintrees_7cwalker_cWalker {
+ PyObject_HEAD
+ struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab;
+ node_t *node;
+ node_t *root;
+ node_stack_t *stack;
+};
+
+
+/* "bintrees\qbintree.pyx":16
+ * from ctrees cimport *
+ *
+ * cdef class cBinaryTree: # <<<<<<<<<<<<<<
+ * cdef node_t *_root
+ * cdef int _count
+ */
+struct __pyx_obj_8bintrees_8qbintree_cBinaryTree {
+ PyObject_HEAD
+ node_t *_root;
+ int _count;
+};
+
+
+
+/* "cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+
+struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker {
+ void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *);
+ PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+};
+static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker;
+#ifndef CYTHON_REFNANNY
+ #define CYTHON_REFNANNY 0
+#endif
+#if CYTHON_REFNANNY
+ typedef struct {
+ void (*INCREF)(void*, PyObject*, int);
+ void (*DECREF)(void*, PyObject*, int);
+ void (*GOTREF)(void*, PyObject*, int);
+ void (*GIVEREF)(void*, PyObject*, int);
+ void* (*SetupContext)(const char*, int, const char*);
+ void (*FinishContext)(void**);
+ } __Pyx_RefNannyAPIStruct;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
+ #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+#ifdef WITH_THREAD
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ if (acquire_gil) { \
+ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ PyGILState_Release(__pyx_gilstate_save); \
+ } else { \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ }
+#else
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+#endif
+ #define __Pyx_RefNannyFinishContext() \
+ __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+ #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+ #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+ #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+ #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+ #define __Pyx_RefNannyDeclarations
+ #define __Pyx_RefNannySetupContext(name, acquire_gil)
+ #define __Pyx_RefNannyFinishContext()
+ #define __Pyx_INCREF(r) Py_INCREF(r)
+ #define __Pyx_DECREF(r) Py_DECREF(r)
+ #define __Pyx_GOTREF(r)
+ #define __Pyx_GIVEREF(r)
+ #define __Pyx_XINCREF(r) Py_XINCREF(r)
+ #define __Pyx_XDECREF(r) Py_XDECREF(r)
+ #define __Pyx_XGOTREF(r)
+ #define __Pyx_XGIVEREF(r)
+#endif /* CYTHON_REFNANNY */
+#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
+#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
+
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
+ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
+ const char* function_name); /*proto*/
+
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
+
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+ PyObject *r;
+ if (!j) return NULL;
+ r = PyObject_GetItem(o, j);
+ Py_DECREF(j);
+ return r;
+}
+#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_List_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
+ PyObject *r = PyList_GET_ITEM(o, i);
+ Py_INCREF(r);
+ return r;
+ }
+ else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
+ PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
+ Py_INCREF(r);
+ return r;
+ }
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+ return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Tuple_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
+ PyObject *r = PyTuple_GET_ITEM(o, i);
+ Py_INCREF(r);
+ return r;
+ }
+ else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
+ PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
+ Py_INCREF(r);
+ return r;
+ }
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+ return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (PyList_CheckExact(o)) {
+ Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+ if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
+ PyObject *r = PyList_GET_ITEM(o, n);
+ Py_INCREF(r);
+ return r;
+ }
+ }
+ else if (PyTuple_CheckExact(o)) {
+ Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+ if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
+ PyObject *r = PyTuple_GET_ITEM(o, n);
+ Py_INCREF(r);
+ return r;
+ }
+ } else { /* inlined PySequence_GetItem() */
+ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ if (likely(m && m->sq_item)) {
+ if (unlikely(i < 0) && likely(m->sq_length)) {
+ Py_ssize_t l = m->sq_length(o);
+ if (unlikely(l < 0)) return NULL;
+ i += l;
+ }
+ return m->sq_item(o, i);
+ }
+ }
+#else
+ if (PySequence_Check(o)) {
+ return PySequence_GetItem(o, i);
+ }
+#endif
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
+
+static int __Pyx_check_binary_version(void);
+
+#if !defined(__Pyx_PyIdentifier_FromString)
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
+#else
+ #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
+#endif
+#endif
+
+static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
+
+static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/
+
+static void* __Pyx_GetVtable(PyObject *dict); /*proto*/
+
+typedef struct {
+ int code_line;
+ PyCodeObject* code_object;
+} __Pyx_CodeObjectCacheEntry;
+struct __Pyx_CodeObjectCache {
+ int count;
+ int max_count;
+ __Pyx_CodeObjectCacheEntry* entries;
+};
+static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
+static PyCodeObject *__pyx_find_code_object(int code_line);
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
+
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+
+/* Module declarations from 'bintrees.ctrees' */
+
+/* Module declarations from 'bintrees.stack' */
+
+/* Module declarations from 'bintrees.cwalker' */
+static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0;
+
+/* Module declarations from 'bintrees.qbintree' */
+static PyTypeObject *__pyx_ptype_8bintrees_8qbintree_cBinaryTree = 0;
+#define __Pyx_MODULE_NAME "bintrees.qbintree"
+int __pyx_module_is_main_bintrees__qbintree = 0;
+
+/* Implementation of 'bintrees.qbintree' */
+static PyObject *__pyx_builtin_property;
+static PyObject *__pyx_builtin_KeyError;
+static PyObject *__pyx_builtin_MemoryError;
+static PyObject *__pyx_builtin_ValueError;
+static int __pyx_pf_8bintrees_8qbintree_11cBinaryTree___cinit__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_items); /* proto */
+static void __pyx_pf_8bintrees_8qbintree_11cBinaryTree_2__dealloc__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_4count(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_6__getstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_8__setstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_state); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_10clear(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_12get_value(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_14get_walker(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_16insert(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_18remove(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_20max_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_22min_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */
+static char __pyx_k_1[] = "Can not allocate memory for node structure.";
+static char __pyx_k_3[] = "Tree is empty";
+static char __pyx_k__key[] = "key";
+static char __pyx_k__count[] = "count";
+static char __pyx_k__items[] = "items";
+static char __pyx_k__value[] = "value";
+static char __pyx_k__update[] = "update";
+static char __pyx_k____all__[] = "__all__";
+static char __pyx_k__cWalker[] = "cWalker";
+static char __pyx_k__cwalker[] = "cwalker";
+static char __pyx_k__KeyError[] = "KeyError";
+static char __pyx_k____main__[] = "__main__";
+static char __pyx_k____test__[] = "__test__";
+static char __pyx_k__property[] = "property";
+static char __pyx_k__ValueError[] = "ValueError";
+static char __pyx_k__MemoryError[] = "MemoryError";
+static char __pyx_k__cBinaryTree[] = "cBinaryTree";
+static PyObject *__pyx_kp_s_1;
+static PyObject *__pyx_kp_s_3;
+static PyObject *__pyx_n_s__KeyError;
+static PyObject *__pyx_n_s__MemoryError;
+static PyObject *__pyx_n_s__ValueError;
+static PyObject *__pyx_n_s____all__;
+static PyObject *__pyx_n_s____main__;
+static PyObject *__pyx_n_s____test__;
+static PyObject *__pyx_n_s__cBinaryTree;
+static PyObject *__pyx_n_s__cWalker;
+static PyObject *__pyx_n_s__count;
+static PyObject *__pyx_n_s__cwalker;
+static PyObject *__pyx_n_s__items;
+static PyObject *__pyx_n_s__key;
+static PyObject *__pyx_n_s__property;
+static PyObject *__pyx_n_s__update;
+static PyObject *__pyx_n_s__value;
+static PyObject *__pyx_int_0;
+static PyObject *__pyx_k_tuple_2;
+static PyObject *__pyx_k_tuple_4;
+static PyObject *__pyx_k_tuple_5;
+
+/* Python wrapper */
+static int __pyx_pw_8bintrees_8qbintree_11cBinaryTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_8bintrees_8qbintree_11cBinaryTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_items = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__items,0};
+ PyObject* values[1] = {0};
+
+ /* "bintrees\qbintree.pyx":20
+ * cdef int _count
+ *
+ * def __cinit__(self, items=None): # <<<<<<<<<<<<<<
+ * self._root = NULL
+ * self._count = 0
+ */
+ values[0] = ((PyObject *)Py_None);
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (kw_args > 0) {
+ PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__items);
+ if (value) { values[0] = value; kw_args--; }
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else {
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ }
+ __pyx_v_items = values[0];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree___cinit__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), __pyx_v_items);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static int __pyx_pf_8bintrees_8qbintree_11cBinaryTree___cinit__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_items) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__cinit__", 0);
+
+ /* "bintrees\qbintree.pyx":21
+ *
+ * def __cinit__(self, items=None):
+ * self._root = NULL # <<<<<<<<<<<<<<
+ * self._count = 0
+ * if items:
+ */
+ __pyx_v_self->_root = NULL;
+
+ /* "bintrees\qbintree.pyx":22
+ * def __cinit__(self, items=None):
+ * self._root = NULL
+ * self._count = 0 # <<<<<<<<<<<<<<
+ * if items:
+ * self.update(items)
+ */
+ __pyx_v_self->_count = 0;
+
+ /* "bintrees\qbintree.pyx":23
+ * self._root = NULL
+ * self._count = 0
+ * if items: # <<<<<<<<<<<<<<
+ * self.update(items)
+ *
+ */
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_items); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_t_1) {
+
+ /* "bintrees\qbintree.pyx":24
+ * self._count = 0
+ * if items:
+ * self.update(items) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_items);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_items);
+ __Pyx_GIVEREF(__pyx_v_items);
+ __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static void __pyx_pw_8bintrees_8qbintree_11cBinaryTree_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_8bintrees_8qbintree_11cBinaryTree_3__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_pf_8bintrees_8qbintree_11cBinaryTree_2__dealloc__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "bintrees\qbintree.pyx":26
+ * self.update(items)
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * ct_delete_tree(self._root)
+ *
+ */
+
+static void __pyx_pf_8bintrees_8qbintree_11cBinaryTree_2__dealloc__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
+
+ /* "bintrees\qbintree.pyx":27
+ *
+ * def __dealloc__(self):
+ * ct_delete_tree(self._root) # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ ct_delete_tree(__pyx_v_self->_root);
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("count (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_4count(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":30
+ *
+ * @property
+ * def count(self): # <<<<<<<<<<<<<<
+ * return self._count
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_4count(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("count", 0);
+
+ /* "bintrees\qbintree.pyx":31
+ * @property
+ * def count(self):
+ * return self._count # <<<<<<<<<<<<<<
+ *
+ * def __getstate__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_6__getstate__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":33
+ * return self._count
+ *
+ * def __getstate__(self): # <<<<<<<<<<<<<<
+ * return dict(self.items())
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_6__getstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__getstate__", 0);
+
+ /* "bintrees\qbintree.pyx":34
+ *
+ * def __getstate__(self):
+ * return dict(self.items()) # <<<<<<<<<<<<<<
+ *
+ * def __setstate__(self, state):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_8__setstate__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), ((PyObject *)__pyx_v_state));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":36
+ * return dict(self.items())
+ *
+ * def __setstate__(self, state): # <<<<<<<<<<<<<<
+ * self.update(state)
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_8__setstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_state) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setstate__", 0);
+
+ /* "bintrees\qbintree.pyx":37
+ *
+ * def __setstate__(self, state):
+ * self.update(state) # <<<<<<<<<<<<<<
+ *
+ * def clear(self):
+ */
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_state);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state);
+ __Pyx_GIVEREF(__pyx_v_state);
+ __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("clear (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_10clear(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":39
+ * self.update(state)
+ *
+ * def clear(self): # <<<<<<<<<<<<<<
+ * ct_delete_tree(self._root)
+ * self._count = 0
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_10clear(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("clear", 0);
+
+ /* "bintrees\qbintree.pyx":40
+ *
+ * def clear(self):
+ * ct_delete_tree(self._root) # <<<<<<<<<<<<<<
+ * self._count = 0
+ * self._root = NULL
+ */
+ ct_delete_tree(__pyx_v_self->_root);
+
+ /* "bintrees\qbintree.pyx":41
+ * def clear(self):
+ * ct_delete_tree(self._root)
+ * self._count = 0 # <<<<<<<<<<<<<<
+ * self._root = NULL
+ *
+ */
+ __pyx_v_self->_count = 0;
+
+ /* "bintrees\qbintree.pyx":42
+ * ct_delete_tree(self._root)
+ * self._count = 0
+ * self._root = NULL # <<<<<<<<<<<<<<
+ *
+ * def get_value(self, key):
+ */
+ __pyx_v_self->_root = NULL;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("get_value (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_12get_value(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":44
+ * self._root = NULL
+ *
+ * def get_value(self, key): # <<<<<<<<<<<<<<
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None:
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_12get_value(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_v_result = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_value", 0);
+
+ /* "bintrees\qbintree.pyx":45
+ *
+ * def get_value(self, key):
+ * result = <object> ct_get_item(self._root, key) # <<<<<<<<<<<<<<
+ * if result is None:
+ * raise KeyError(key)
+ */
+ __pyx_t_1 = ct_get_item(__pyx_v_self->_root, __pyx_v_key);
+ __Pyx_INCREF(((PyObject *)__pyx_t_1));
+ __pyx_v_result = ((PyObject *)__pyx_t_1);
+
+ /* "bintrees\qbintree.pyx":46
+ * def get_value(self, key):
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None: # <<<<<<<<<<<<<<
+ * raise KeyError(key)
+ * else:
+ */
+ __pyx_t_2 = (__pyx_v_result == Py_None);
+ if (__pyx_t_2) {
+
+ /* "bintrees\qbintree.pyx":47
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None:
+ * raise KeyError(key) # <<<<<<<<<<<<<<
+ * else:
+ * return result[1]
+ */
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qbintree.pyx":49
+ * raise KeyError(key)
+ * else:
+ * return result[1] # <<<<<<<<<<<<<<
+ *
+ * def get_walker(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_result, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_r = __pyx_t_4;
+ __pyx_t_4 = 0;
+ goto __pyx_L0;
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_result);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("get_walker (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_14get_walker(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":51
+ * return result[1]
+ *
+ * def get_walker(self): # <<<<<<<<<<<<<<
+ * cdef cWalker walker
+ * walker = cWalker()
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_14get_walker(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_walker = 0;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_walker", 0);
+
+ /* "bintrees\qbintree.pyx":53
+ * def get_walker(self):
+ * cdef cWalker walker
+ * walker = cWalker() # <<<<<<<<<<<<<<
+ * walker.set_tree(self._root)
+ * return walker
+ */
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8bintrees_7cwalker_cWalker)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_walker = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_t_1);
+ __pyx_t_1 = 0;
+
+ /* "bintrees\qbintree.pyx":54
+ * cdef cWalker walker
+ * walker = cWalker()
+ * walker.set_tree(self._root) # <<<<<<<<<<<<<<
+ * return walker
+ *
+ */
+ ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_walker->__pyx_vtab)->set_tree(__pyx_v_walker, __pyx_v_self->_root);
+
+ /* "bintrees\qbintree.pyx":55
+ * walker = cWalker()
+ * walker.set_tree(self._root)
+ * return walker # <<<<<<<<<<<<<<
+ *
+ * def insert(self, key, value):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_walker));
+ __pyx_r = ((PyObject *)__pyx_v_walker);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.get_walker", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_walker);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_key = 0;
+ PyObject *__pyx_v_value = 0;
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("insert (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__value,0};
+ PyObject* values[2] = {0,0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key)) != 0)) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ case 1:
+ if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ }
+ __pyx_v_key = values[0];
+ __pyx_v_value = values[1];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_16insert(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), __pyx_v_key, __pyx_v_value);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":57
+ * return walker
+ *
+ * def insert(self, key, value): # <<<<<<<<<<<<<<
+ * res = ct_bintree_insert(&self._root, key, value)
+ * if res < 0:
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_16insert(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) {
+ PyObject *__pyx_v_res = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_4;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("insert", 0);
+
+ /* "bintrees\qbintree.pyx":58
+ *
+ * def insert(self, key, value):
+ * res = ct_bintree_insert(&self._root, key, value) # <<<<<<<<<<<<<<
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.')
+ */
+ __pyx_t_1 = PyInt_FromLong(ct_bintree_insert((&__pyx_v_self->_root), __pyx_v_key, __pyx_v_value)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_res = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "bintrees\qbintree.pyx":59
+ * def insert(self, key, value):
+ * res = ct_bintree_insert(&self._root, key, value)
+ * if res < 0: # <<<<<<<<<<<<<<
+ * raise MemoryError('Can not allocate memory for node structure.')
+ * self._count += res
+ */
+ __pyx_t_1 = PyObject_RichCompare(__pyx_v_res, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (__pyx_t_2) {
+
+ /* "bintrees\qbintree.pyx":60
+ * res = ct_bintree_insert(&self._root, key, value)
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<<
+ * self._count += res
+ *
+ */
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qbintree.pyx":61
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.')
+ * self._count += res # <<<<<<<<<<<<<<
+ *
+ * def remove(self, key):
+ */
+ __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_res); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_self->_count = __pyx_t_4;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_res);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("remove (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_18remove(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":63
+ * self._count += res
+ *
+ * def remove(self, key): # <<<<<<<<<<<<<<
+ * cdef int result
+ * result = ct_bintree_remove(&self._root, key)
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_18remove(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key) {
+ int __pyx_v_result;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("remove", 0);
+
+ /* "bintrees\qbintree.pyx":65
+ * def remove(self, key):
+ * cdef int result
+ * result = ct_bintree_remove(&self._root, key) # <<<<<<<<<<<<<<
+ * if result == 0:
+ * raise KeyError(str(key))
+ */
+ __pyx_v_result = ct_bintree_remove((&__pyx_v_self->_root), __pyx_v_key);
+
+ /* "bintrees\qbintree.pyx":66
+ * cdef int result
+ * result = ct_bintree_remove(&self._root, key)
+ * if result == 0: # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * else:
+ */
+ __pyx_t_1 = (__pyx_v_result == 0);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qbintree.pyx":67
+ * result = ct_bintree_remove(&self._root, key)
+ * if result == 0:
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * else:
+ * self._count -= 1
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qbintree.pyx":69
+ * raise KeyError(str(key))
+ * else:
+ * self._count -= 1 # <<<<<<<<<<<<<<
+ *
+ * def max_item(self):
+ */
+ __pyx_v_self->_count = (__pyx_v_self->_count - 1);
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.remove", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_8qbintree_11cBinaryTree_20max_item[] = " Get item with max key of tree, raises ValueError if tree is empty. ";
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("max_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_20max_item(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":71
+ * self._count -= 1
+ *
+ * def max_item(self): # <<<<<<<<<<<<<<
+ * """ Get item with max key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_20max_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ node_t *__pyx_v_node;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("max_item", 0);
+
+ /* "bintrees\qbintree.pyx":74
+ * """ Get item with max key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ * node = ct_max_node(self._root) # <<<<<<<<<<<<<<
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ */
+ __pyx_v_node = ct_max_node(__pyx_v_self->_root);
+
+ /* "bintrees\qbintree.pyx":75
+ * cdef node_t *node
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None # <<<<<<<<<<<<<<
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_1 = (__pyx_v_node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qbintree.pyx":76
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qbintree.pyx":77
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<<
+ *
+ * def min_item(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->key));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->value));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value));
+ __pyx_r = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.max_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_8qbintree_11cBinaryTree_22min_item[] = " Get item with min key of tree, raises ValueError if tree is empty. ";
+static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("min_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_22min_item(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qbintree.pyx":79
+ * return (<object>node.key, <object>node.value)
+ *
+ * def min_item(self): # <<<<<<<<<<<<<<
+ * """ Get item with min key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ */
+
+static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_22min_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) {
+ node_t *__pyx_v_node;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("min_item", 0);
+
+ /* "bintrees\qbintree.pyx":82
+ * """ Get item with min key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ * node = ct_min_node(self._root) # <<<<<<<<<<<<<<
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ */
+ __pyx_v_node = ct_min_node(__pyx_v_self->_root);
+
+ /* "bintrees\qbintree.pyx":83
+ * cdef node_t *node
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None # <<<<<<<<<<<<<<
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_1 = (__pyx_v_node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qbintree.pyx":84
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qbintree.pyx":85
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<<
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->key));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->value));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value));
+ __pyx_r = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.min_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_tp_new_8bintrees_8qbintree_cBinaryTree(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ if (__pyx_pw_8bintrees_8qbintree_11cBinaryTree_1__cinit__(o, a, k) < 0) {
+ Py_DECREF(o); o = 0;
+ }
+ return o;
+}
+
+static void __pyx_tp_dealloc_8bintrees_8qbintree_cBinaryTree(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pw_8bintrees_8qbintree_11cBinaryTree_3__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_8bintrees_8qbintree_cBinaryTree[] = {
+ {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_5count, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_7__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_9__setstate__, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_11clear, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("get_value"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_13get_value, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("get_walker"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_15get_walker, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_17insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("remove"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_19remove, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("max_item"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_21max_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qbintree_11cBinaryTree_20max_item)},
+ {__Pyx_NAMESTR("min_item"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_23min_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qbintree_11cBinaryTree_22min_item)},
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_cBinaryTree = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_cBinaryTree = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_cBinaryTree = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_cBinaryTree = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_8bintrees_8qbintree_cBinaryTree = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("bintrees.qbintree.cBinaryTree"), /*tp_name*/
+ sizeof(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_8bintrees_8qbintree_cBinaryTree, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_cBinaryTree, /*tp_as_number*/
+ &__pyx_tp_as_sequence_cBinaryTree, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_cBinaryTree, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_cBinaryTree, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_8bintrees_8qbintree_cBinaryTree, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_8bintrees_8qbintree_cBinaryTree, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+ {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef __pyx_moduledef = {
+ PyModuleDef_HEAD_INIT,
+ __Pyx_NAMESTR("qbintree"),
+ 0, /* m_doc */
+ -1, /* m_size */
+ __pyx_methods /* m_methods */,
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
+};
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+ {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
+ {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
+ {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
+ {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1},
+ {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
+ {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
+ {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
+ {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
+ {&__pyx_n_s__cBinaryTree, __pyx_k__cBinaryTree, sizeof(__pyx_k__cBinaryTree), 0, 0, 1, 1},
+ {&__pyx_n_s__cWalker, __pyx_k__cWalker, sizeof(__pyx_k__cWalker), 0, 0, 1, 1},
+ {&__pyx_n_s__count, __pyx_k__count, sizeof(__pyx_k__count), 0, 0, 1, 1},
+ {&__pyx_n_s__cwalker, __pyx_k__cwalker, sizeof(__pyx_k__cwalker), 0, 0, 1, 1},
+ {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1},
+ {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
+ {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1},
+ {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1},
+ {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0}
+};
+static int __Pyx_InitCachedBuiltins(void) {
+ __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+static int __Pyx_InitCachedConstants(void) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
+
+ /* "bintrees\qbintree.pyx":60
+ * res = ct_bintree_insert(&self._root, key, value)
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<<
+ * self._count += res
+ *
+ */
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_2);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
+
+ /* "bintrees\qbintree.pyx":76
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_4);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
+
+ /* "bintrees\qbintree.pyx":84
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_5);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
+ __Pyx_RefNannyFinishContext();
+ return 0;
+ __pyx_L1_error:;
+ __Pyx_RefNannyFinishContext();
+ return -1;
+}
+
+static int __Pyx_InitGlobals(void) {
+ if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC initqbintree(void); /*proto*/
+PyMODINIT_FUNC initqbintree(void)
+#else
+PyMODINIT_FUNC PyInit_qbintree(void); /*proto*/
+PyMODINIT_FUNC PyInit_qbintree(void)
+#endif
+{
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ __Pyx_RefNannyDeclarations
+ #if CYTHON_REFNANNY
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+ if (!__Pyx_RefNanny) {
+ PyErr_Clear();
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+ if (!__Pyx_RefNanny)
+ Py_FatalError("failed to import 'refnanny' module");
+ }
+ #endif
+ __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_qbintree(void)", 0);
+ if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #ifdef __Pyx_CyFunction_USED
+ if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_FusedFunction_USED
+ if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_Generator_USED
+ if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ /*--- Library function declarations ---*/
+ /*--- Threads initialization code ---*/
+ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+ #ifdef WITH_THREAD /* Python build with threading support? */
+ PyEval_InitThreads();
+ #endif
+ #endif
+ /*--- Module creation code ---*/
+ #if PY_MAJOR_VERSION < 3
+ __pyx_m = Py_InitModule4(__Pyx_NAMESTR("qbintree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+ #else
+ __pyx_m = PyModule_Create(&__pyx_moduledef);
+ #endif
+ if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if PY_MAJOR_VERSION >= 3
+ {
+ PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!PyDict_GetItemString(modules, "bintrees.qbintree")) {
+ if (unlikely(PyDict_SetItemString(modules, "bintrees.qbintree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ }
+ #endif
+ __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if CYTHON_COMPILING_IN_PYPY
+ Py_INCREF(__pyx_b);
+ #endif
+ if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ /*--- Initialize various global constants etc. ---*/
+ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_module_is_main_bintrees__qbintree) {
+ if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ }
+ /*--- Builtin init code ---*/
+ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Constants init code ---*/
+ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Global init code ---*/
+ /*--- Variable export code ---*/
+ /*--- Function export code ---*/
+ /*--- Type init code ---*/
+ if (PyType_Ready(&__pyx_type_8bintrees_8qbintree_cBinaryTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "cBinaryTree", (PyObject *)&__pyx_type_8bintrees_8qbintree_cBinaryTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_8bintrees_8qbintree_cBinaryTree = &__pyx_type_8bintrees_8qbintree_cBinaryTree;
+ /*--- Type import code ---*/
+ __pyx_ptype_8bintrees_7cwalker_cWalker = __Pyx_ImportType("bintrees.cwalker", "cWalker", sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), 1); if (unlikely(!__pyx_ptype_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_vtabptr_8bintrees_7cwalker_cWalker = (struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker*)__Pyx_GetVtable(__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict); if (unlikely(!__pyx_vtabptr_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Variable import code ---*/
+ /*--- Function import code ---*/
+ /*--- Execution code ---*/
+
+ /* "bintrees\qbintree.pyx":9
+ * # License: MIT License
+ *
+ * __all__ = ['cBinaryTree'] # <<<<<<<<<<<<<<
+ *
+ * from cwalker import cWalker
+ */
+ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__cBinaryTree));
+ PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cBinaryTree));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cBinaryTree));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+
+ /* "bintrees\qbintree.pyx":11
+ * __all__ = ['cBinaryTree']
+ *
+ * from cwalker import cWalker # <<<<<<<<<<<<<<
+ *
+ * from cwalker cimport *
+ */
+ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__cWalker));
+ PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cWalker));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cWalker));
+ __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__cwalker), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+ /* "bintrees\qbintree.pyx":30
+ *
+ * @property
+ * def count(self): # <<<<<<<<<<<<<<
+ * return self._count
+ *
+ */
+ __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_8qbintree_cBinaryTree, __pyx_n_s__count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_8qbintree_cBinaryTree->tp_dict, __pyx_n_s__count, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_8qbintree_cBinaryTree);
+
+ /* "bintrees\qbintree.pyx":1
+ * #!/usr/bin/env python # <<<<<<<<<<<<<<
+ * #coding:utf-8
+ * # Author: mozman
+ */
+ __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ if (__pyx_m) {
+ __Pyx_AddTraceback("init bintrees.qbintree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ Py_DECREF(__pyx_m); __pyx_m = 0;
+ } else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "init bintrees.qbintree");
+ }
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ #if PY_MAJOR_VERSION < 3
+ return;
+ #else
+ return __pyx_m;
+ #endif
+}
+
+/* Runtime support code */
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+ PyObject *m = NULL, *p = NULL;
+ void *r = NULL;
+ m = PyImport_ImportModule((char *)modname);
+ if (!m) goto end;
+ p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
+ if (!p) goto end;
+ r = PyLong_AsVoidPtr(p);
+end:
+ Py_XDECREF(p);
+ Py_XDECREF(m);
+ return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif /* CYTHON_REFNANNY */
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result) {
+ if (dict != __pyx_b) {
+ PyErr_Clear();
+ result = PyObject_GetAttr(__pyx_b, name);
+ }
+ if (!result) {
+ PyErr_SetObject(PyExc_NameError, name);
+ }
+ }
+ return result;
+}
+
+static void __Pyx_RaiseDoubleKeywordsError(
+ const char* func_name,
+ PyObject* kw_name)
+{
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION >= 3
+ "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+ #else
+ "%s() got multiple values for keyword argument '%s'", func_name,
+ PyString_AsString(kw_name));
+ #endif
+}
+
+static int __Pyx_ParseOptionalKeywords(
+ PyObject *kwds,
+ PyObject **argnames[],
+ PyObject *kwds2,
+ PyObject *values[],
+ Py_ssize_t num_pos_args,
+ const char* function_name)
+{
+ PyObject *key = 0, *value = 0;
+ Py_ssize_t pos = 0;
+ PyObject*** name;
+ PyObject*** first_kw_arg = argnames + num_pos_args;
+ while (PyDict_Next(kwds, &pos, &key, &value)) {
+ name = first_kw_arg;
+ while (*name && (**name != key)) name++;
+ if (*name) {
+ values[name-argnames] = value;
+ continue;
+ }
+ name = first_kw_arg;
+ #if PY_MAJOR_VERSION < 3
+ if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
+ while (*name) {
+ if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
+ && _PyString_Eq(**name, key)) {
+ values[name-argnames] = value;
+ break;
+ }
+ name++;
+ }
+ if (*name) continue;
+ else {
+ PyObject*** argname = argnames;
+ while (argname != first_kw_arg) {
+ if ((**argname == key) || (
+ (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
+ && _PyString_Eq(**argname, key))) {
+ goto arg_passed_twice;
+ }
+ argname++;
+ }
+ }
+ } else
+ #endif
+ if (likely(PyUnicode_Check(key))) {
+ while (*name) {
+ int cmp = (**name == key) ? 0 :
+ #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+ (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
+ #endif
+ PyUnicode_Compare(**name, key);
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+ if (cmp == 0) {
+ values[name-argnames] = value;
+ break;
+ }
+ name++;
+ }
+ if (*name) continue;
+ else {
+ PyObject*** argname = argnames;
+ while (argname != first_kw_arg) {
+ int cmp = (**argname == key) ? 0 :
+ #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+ (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
+ #endif
+ PyUnicode_Compare(**argname, key);
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+ if (cmp == 0) goto arg_passed_twice;
+ argname++;
+ }
+ }
+ } else
+ goto invalid_keyword_type;
+ if (kwds2) {
+ if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+ } else {
+ goto invalid_keyword;
+ }
+ }
+ return 0;
+arg_passed_twice:
+ __Pyx_RaiseDoubleKeywordsError(function_name, key);
+ goto bad;
+invalid_keyword_type:
+ PyErr_Format(PyExc_TypeError,
+ "%s() keywords must be strings", function_name);
+ goto bad;
+invalid_keyword:
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION < 3
+ "%s() got an unexpected keyword argument '%s'",
+ function_name, PyString_AsString(key));
+ #else
+ "%s() got an unexpected keyword argument '%U'",
+ function_name, key);
+ #endif
+bad:
+ return -1;
+}
+
+static void __Pyx_RaiseArgtupleInvalid(
+ const char* func_name,
+ int exact,
+ Py_ssize_t num_min,
+ Py_ssize_t num_max,
+ Py_ssize_t num_found)
+{
+ Py_ssize_t num_expected;
+ const char *more_or_less;
+ if (num_found < num_min) {
+ num_expected = num_min;
+ more_or_less = "at least";
+ } else {
+ num_expected = num_max;
+ more_or_less = "at most";
+ }
+ if (exact) {
+ more_or_less = "exactly";
+ }
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
+ func_name, more_or_less, num_expected,
+ (num_expected == 1) ? "" : "s", num_found);
+}
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+ tmp_type = tstate->curexc_type;
+ tmp_value = tstate->curexc_value;
+ tmp_tb = tstate->curexc_traceback;
+ tstate->curexc_type = type;
+ tstate->curexc_value = value;
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+#else
+ PyErr_Restore(type, value, tb);
+#endif
+}
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->curexc_type;
+ *value = tstate->curexc_value;
+ *tb = tstate->curexc_traceback;
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+#else
+ PyErr_Fetch(type, value, tb);
+#endif
+}
+
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
+ CYTHON_UNUSED PyObject *cause) {
+ Py_XINCREF(type);
+ if (!value || value == Py_None)
+ value = NULL;
+ else
+ Py_INCREF(value);
+ if (!tb || tb == Py_None)
+ tb = NULL;
+ else {
+ Py_INCREF(tb);
+ if (!PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto raise_error;
+ }
+ }
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyClass_Check(type)) {
+ #else
+ if (PyType_Check(type)) {
+ #endif
+#if CYTHON_COMPILING_IN_PYPY
+ if (!value) {
+ Py_INCREF(Py_None);
+ value = Py_None;
+ }
+#endif
+ PyErr_NormalizeException(&type, &value, &tb);
+ } else {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto raise_error;
+ }
+ value = type;
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyInstance_Check(type)) {
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
+ }
+ else {
+ type = 0;
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception must be an old-style class or instance");
+ goto raise_error;
+ }
+ #else
+ type = (PyObject*) Py_TYPE(type);
+ Py_INCREF(type);
+ if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto raise_error;
+ }
+ #endif
+ }
+ __Pyx_ErrRestore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ return;
+}
+#else /* Python 3+ */
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+ PyObject* owned_instance = NULL;
+ if (tb == Py_None) {
+ tb = 0;
+ } else if (tb && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto bad;
+ }
+ if (value == Py_None)
+ value = 0;
+ if (PyExceptionInstance_Check(type)) {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto bad;
+ }
+ value = type;
+ type = (PyObject*) Py_TYPE(value);
+ } else if (PyExceptionClass_Check(type)) {
+ PyObject *args;
+ if (!value)
+ args = PyTuple_New(0);
+ else if (PyTuple_Check(value)) {
+ Py_INCREF(value);
+ args = value;
+ }
+ else
+ args = PyTuple_Pack(1, value);
+ if (!args)
+ goto bad;
+ owned_instance = PyEval_CallObject(type, args);
+ Py_DECREF(args);
+ if (!owned_instance)
+ goto bad;
+ value = owned_instance;
+ if (!PyExceptionInstance_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "calling %R should have returned an instance of "
+ "BaseException, not %R",
+ type, Py_TYPE(value));
+ goto bad;
+ }
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto bad;
+ }
+ if (cause && cause != Py_None) {
+ PyObject *fixed_cause;
+ if (PyExceptionClass_Check(cause)) {
+ fixed_cause = PyObject_CallObject(cause, NULL);
+ if (fixed_cause == NULL)
+ goto bad;
+ }
+ else if (PyExceptionInstance_Check(cause)) {
+ fixed_cause = cause;
+ Py_INCREF(fixed_cause);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
+ goto bad;
+ }
+ PyException_SetCause(value, fixed_cause);
+ }
+ PyErr_SetObject(type, value);
+ if (tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ PyObject* tmp_tb = tstate->curexc_traceback;
+ if (tb != tmp_tb) {
+ Py_INCREF(tb);
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_tb);
+ }
+ }
+bad:
+ Py_XDECREF(owned_instance);
+ return;
+}
+#endif
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
+ PyObject *py_import = 0;
+ PyObject *empty_list = 0;
+ PyObject *module = 0;
+ PyObject *global_dict = 0;
+ PyObject *empty_dict = 0;
+ PyObject *list;
+ py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
+ if (!py_import)
+ goto bad;
+ if (from_list)
+ list = from_list;
+ else {
+ empty_list = PyList_New(0);
+ if (!empty_list)
+ goto bad;
+ list = empty_list;
+ }
+ global_dict = PyModule_GetDict(__pyx_m);
+ if (!global_dict)
+ goto bad;
+ empty_dict = PyDict_New();
+ if (!empty_dict)
+ goto bad;
+ #if PY_VERSION_HEX >= 0x02050000
+ {
+ #if PY_MAJOR_VERSION >= 3
+ if (level == -1) {
+ if (strchr(__Pyx_MODULE_NAME, '.')) {
+ /* try package relative import first */
+ PyObject *py_level = PyInt_FromLong(1);
+ if (!py_level)
+ goto bad;
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, py_level, NULL);
+ Py_DECREF(py_level);
+ if (!module) {
+ if (!PyErr_ExceptionMatches(PyExc_ImportError))
+ goto bad;
+ PyErr_Clear();
+ }
+ }
+ level = 0; /* try absolute import on failure */
+ }
+ #endif
+ if (!module) {
+ PyObject *py_level = PyInt_FromLong(level);
+ if (!py_level)
+ goto bad;
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, py_level, NULL);
+ Py_DECREF(py_level);
+ }
+ }
+ #else
+ if (level>0) {
+ PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
+ goto bad;
+ }
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, NULL);
+ #endif
+bad:
+ Py_XDECREF(empty_list);
+ Py_XDECREF(py_import);
+ Py_XDECREF(empty_dict);
+ return module;
+}
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
+ const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned char" :
+ "value too large to convert to unsigned char");
+ }
+ return (unsigned char)-1;
+ }
+ return (unsigned char)val;
+ }
+ return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
+ const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned short" :
+ "value too large to convert to unsigned short");
+ }
+ return (unsigned short)-1;
+ }
+ return (unsigned short)val;
+ }
+ return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
+ const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned int" :
+ "value too large to convert to unsigned int");
+ }
+ return (unsigned int)-1;
+ }
+ return (unsigned int)val;
+ }
+ return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
+ const char neg_one = (char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to char" :
+ "value too large to convert to char");
+ }
+ return (char)-1;
+ }
+ return (char)val;
+ }
+ return (char)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
+ const short neg_one = (short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to short" :
+ "value too large to convert to short");
+ }
+ return (short)-1;
+ }
+ return (short)val;
+ }
+ return (short)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
+ const signed char neg_one = (signed char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed char" :
+ "value too large to convert to signed char");
+ }
+ return (signed char)-1;
+ }
+ return (signed char)val;
+ }
+ return (signed char)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
+ const signed short neg_one = (signed short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed short" :
+ "value too large to convert to signed short");
+ }
+ return (signed short)-1;
+ }
+ return (signed short)val;
+ }
+ return (signed short)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
+ const signed int neg_one = (signed int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed int" :
+ "value too large to convert to signed int");
+ }
+ return (signed int)-1;
+ }
+ return (signed int)val;
+ }
+ return (signed int)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
+ const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (unsigned long)PyLong_AsLong(x);
+ }
+ } else {
+ unsigned long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned long)-1;
+ val = __Pyx_PyInt_AsUnsignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
+ const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ unsigned PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
+ const long neg_one = (long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (long)PyLong_AsLong(x);
+ }
+ } else {
+ long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (long)-1;
+ val = __Pyx_PyInt_AsLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
+ const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
+ const signed long neg_one = (signed long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (signed long)PyLong_AsLong(x);
+ }
+ } else {
+ signed long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed long)-1;
+ val = __Pyx_PyInt_AsSignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
+ const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ signed PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsSignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static int __Pyx_check_binary_version(void) {
+ char ctversion[4], rtversion[4];
+ PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+ PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+ if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+ char message[200];
+ PyOS_snprintf(message, sizeof(message),
+ "compiletime version %s of module '%.100s' "
+ "does not match runtime version %s",
+ ctversion, __Pyx_MODULE_NAME, rtversion);
+ #if PY_VERSION_HEX < 0x02050000
+ return PyErr_Warn(NULL, message);
+ #else
+ return PyErr_WarnEx(NULL, message, 1);
+ #endif
+ }
+ return 0;
+}
+
+#ifndef __PYX_HAVE_RT_ImportModule
+#define __PYX_HAVE_RT_ImportModule
+static PyObject *__Pyx_ImportModule(const char *name) {
+ PyObject *py_name = 0;
+ PyObject *py_module = 0;
+ py_name = __Pyx_PyIdentifier_FromString(name);
+ if (!py_name)
+ goto bad;
+ py_module = PyImport_Import(py_name);
+ Py_DECREF(py_name);
+ return py_module;
+bad:
+ Py_XDECREF(py_name);
+ return 0;
+}
+#endif
+
+#ifndef __PYX_HAVE_RT_ImportType
+#define __PYX_HAVE_RT_ImportType
+static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
+ size_t size, int strict)
+{
+ PyObject *py_module = 0;
+ PyObject *result = 0;
+ PyObject *py_name = 0;
+ char warning[200];
+ py_module = __Pyx_ImportModule(module_name);
+ if (!py_module)
+ goto bad;
+ py_name = __Pyx_PyIdentifier_FromString(class_name);
+ if (!py_name)
+ goto bad;
+ result = PyObject_GetAttr(py_module, py_name);
+ Py_DECREF(py_name);
+ py_name = 0;
+ Py_DECREF(py_module);
+ py_module = 0;
+ if (!result)
+ goto bad;
+ if (!PyType_Check(result)) {
+ PyErr_Format(PyExc_TypeError,
+ "%s.%s is not a type object",
+ module_name, class_name);
+ goto bad;
+ }
+ if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) {
+ PyOS_snprintf(warning, sizeof(warning),
+ "%s.%s size changed, may indicate binary incompatibility",
+ module_name, class_name);
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyErr_Warn(NULL, warning) < 0) goto bad;
+ #else
+ if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
+ #endif
+ }
+ else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) {
+ PyErr_Format(PyExc_ValueError,
+ "%s.%s has the wrong size, try recompiling",
+ module_name, class_name);
+ goto bad;
+ }
+ return (PyTypeObject *)result;
+bad:
+ Py_XDECREF(py_module);
+ Py_XDECREF(result);
+ return NULL;
+}
+#endif
+
+static void* __Pyx_GetVtable(PyObject *dict) {
+ void* ptr;
+ PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
+ if (!ob)
+ goto bad;
+#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
+ ptr = PyCapsule_GetPointer(ob, 0);
+#else
+ ptr = PyCObject_AsVoidPtr(ob);
+#endif
+ if (!ptr && !PyErr_Occurred())
+ PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
+ Py_DECREF(ob);
+ return ptr;
+bad:
+ Py_XDECREF(ob);
+ return NULL;
+}
+
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+ int start = 0, mid = 0, end = count - 1;
+ if (end >= 0 && code_line > entries[end].code_line) {
+ return count;
+ }
+ while (start < end) {
+ mid = (start + end) / 2;
+ if (code_line < entries[mid].code_line) {
+ end = mid;
+ } else if (code_line > entries[mid].code_line) {
+ start = mid + 1;
+ } else {
+ return mid;
+ }
+ }
+ if (code_line <= entries[mid].code_line) {
+ return mid;
+ } else {
+ return mid + 1;
+ }
+}
+static PyCodeObject *__pyx_find_code_object(int code_line) {
+ PyCodeObject* code_object;
+ int pos;
+ if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
+ return NULL;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
+ return NULL;
+ }
+ code_object = __pyx_code_cache.entries[pos].code_object;
+ Py_INCREF(code_object);
+ return code_object;
+}
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
+ int pos, i;
+ __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
+ if (unlikely(!code_line)) {
+ return;
+ }
+ if (unlikely(!entries)) {
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (likely(entries)) {
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = 64;
+ __pyx_code_cache.count = 1;
+ entries[0].code_line = code_line;
+ entries[0].code_object = code_object;
+ Py_INCREF(code_object);
+ }
+ return;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
+ PyCodeObject* tmp = entries[pos].code_object;
+ entries[pos].code_object = code_object;
+ Py_DECREF(tmp);
+ return;
+ }
+ if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
+ int new_max = __pyx_code_cache.max_count + 64;
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
+ __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (unlikely(!entries)) {
+ return;
+ }
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = new_max;
+ }
+ for (i=__pyx_code_cache.count; i>pos; i--) {
+ entries[i] = entries[i-1];
+ }
+ entries[pos].code_line = code_line;
+ entries[pos].code_object = code_object;
+ __pyx_code_cache.count++;
+ Py_INCREF(code_object);
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
+ const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ #if PY_MAJOR_VERSION < 3
+ py_srcfile = PyString_FromString(filename);
+ #else
+ py_srcfile = PyUnicode_FromString(filename);
+ #endif
+ if (!py_srcfile) goto bad;
+ if (c_line) {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #else
+ py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #endif
+ }
+ else {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromString(funcname);
+ #else
+ py_funcname = PyUnicode_FromString(funcname);
+ #endif
+ }
+ if (!py_funcname) goto bad;
+ py_code = __Pyx_PyCode_New(
+ 0, /*int argcount,*/
+ 0, /*int kwonlyargcount,*/
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ __pyx_empty_bytes, /*PyObject *code,*/
+ __pyx_empty_tuple, /*PyObject *consts,*/
+ __pyx_empty_tuple, /*PyObject *names,*/
+ __pyx_empty_tuple, /*PyObject *varnames,*/
+ __pyx_empty_tuple, /*PyObject *freevars,*/
+ __pyx_empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ py_line, /*int firstlineno,*/
+ __pyx_empty_bytes /*PyObject *lnotab*/
+ );
+ Py_DECREF(py_srcfile);
+ Py_DECREF(py_funcname);
+ return py_code;
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ return NULL;
+}
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_globals = 0;
+ PyFrameObject *py_frame = 0;
+ py_code = __pyx_find_code_object(c_line ? c_line : py_line);
+ if (!py_code) {
+ py_code = __Pyx_CreateCodeObjectForTraceback(
+ funcname, c_line, py_line, filename);
+ if (!py_code) goto bad;
+ __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
+ }
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_GET(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = py_line;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+ while (t->p) {
+ #if PY_MAJOR_VERSION < 3
+ if (t->is_unicode) {
+ *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+ } else if (t->intern) {
+ *t->p = PyString_InternFromString(t->s);
+ } else {
+ *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+ }
+ #else /* Python 3+ has unicode identifiers */
+ if (t->is_unicode | t->is_str) {
+ if (t->intern) {
+ *t->p = PyUnicode_InternFromString(t->s);
+ } else if (t->encoding) {
+ *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+ } else {
+ *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+ }
+ } else {
+ *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+ }
+ #endif
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+
+/* Type Conversion Functions */
+
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+ int is_true = x == Py_True;
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+ else return PyObject_IsTrue(x);
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
+ PyNumberMethods *m;
+ const char *name = NULL;
+ PyObject *res = NULL;
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_Check(x) || PyLong_Check(x))
+#else
+ if (PyLong_Check(x))
+#endif
+ return Py_INCREF(x), x;
+ m = Py_TYPE(x)->tp_as_number;
+#if PY_VERSION_HEX < 0x03000000
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Int(x);
+ }
+ else if (m && m->nb_long) {
+ name = "long";
+ res = PyNumber_Long(x);
+ }
+#else
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Long(x);
+ }
+#endif
+ if (res) {
+#if PY_VERSION_HEX < 0x03000000
+ if (!PyInt_Check(res) && !PyLong_Check(res)) {
+#else
+ if (!PyLong_Check(res)) {
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "__%s__ returned non-%s (type %.200s)",
+ name, name, Py_TYPE(res)->tp_name);
+ Py_DECREF(res);
+ return NULL;
+ }
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "an integer is required");
+ }
+ return res;
+}
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+ Py_ssize_t ival;
+ PyObject* x = PyNumber_Index(b);
+ if (!x) return -1;
+ ival = PyInt_AsSsize_t(x);
+ Py_DECREF(x);
+ return ival;
+}
+
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+#if PY_VERSION_HEX < 0x02050000
+ if (ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ else {
+ unsigned char *bytes = (unsigned char *) &ival;
+ int one = 1; int little = (int)*(unsigned char*)&one;
+ return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
+ }
+#else
+ return PyInt_FromSize_t(ival);
+#endif
+}
+
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
+ unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
+ if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
+ return (size_t)-1;
+ } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "value too large to convert to size_t");
+ return (size_t)-1;
+ }
+ return (size_t)val;
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/chromium/third_party/bintrees/bintrees/qbintree.pyx b/chromium/third_party/bintrees/bintrees/qbintree.pyx
new file mode 100644
index 00000000000..01d129fc075
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/qbintree.pyx
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: cython unbalanced binary tree module
+# Created: 28.04.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+__all__ = ['cBinaryTree']
+
+from cwalker import cWalker
+
+from cwalker cimport *
+from ctrees cimport *
+
+cdef class cBinaryTree:
+ cdef node_t *_root
+ cdef int _count
+
+ def __cinit__(self, items=None):
+ self._root = NULL
+ self._count = 0
+ if items:
+ self.update(items)
+
+ def __dealloc__(self):
+ ct_delete_tree(self._root)
+
+ @property
+ def count(self):
+ return self._count
+
+ def __getstate__(self):
+ return dict(self.items())
+
+ def __setstate__(self, state):
+ self.update(state)
+
+ def clear(self):
+ ct_delete_tree(self._root)
+ self._count = 0
+ self._root = NULL
+
+ def get_value(self, key):
+ result = <object> ct_get_item(self._root, key)
+ if result is None:
+ raise KeyError(key)
+ else:
+ return result[1]
+
+ def get_walker(self):
+ cdef cWalker walker
+ walker = cWalker()
+ walker.set_tree(self._root)
+ return walker
+
+ def insert(self, key, value):
+ res = ct_bintree_insert(&self._root, key, value)
+ if res < 0:
+ raise MemoryError('Can not allocate memory for node structure.')
+ self._count += res
+
+ def remove(self, key):
+ cdef int result
+ result = ct_bintree_remove(&self._root, key)
+ if result == 0:
+ raise KeyError(str(key))
+ else:
+ self._count -= 1
+
+ def max_item(self):
+ """ Get item with max key of tree, raises ValueError if tree is empty. """
+ cdef node_t *node
+ node = ct_max_node(self._root)
+ if node == NULL: # root is None
+ raise ValueError("Tree is empty")
+ return (<object>node.key, <object>node.value)
+
+ def min_item(self):
+ """ Get item with min key of tree, raises ValueError if tree is empty. """
+ cdef node_t *node
+ node = ct_min_node(self._root)
+ if node == NULL: # root is None
+ raise ValueError("Tree is empty")
+ return (<object>node.key, <object>node.value)
diff --git a/chromium/third_party/bintrees/bintrees/qrbtree.c b/chromium/third_party/bintrees/bintrees/qrbtree.c
new file mode 100644
index 00000000000..f5aa162fd48
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/qrbtree.c
@@ -0,0 +1,3399 @@
+/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+ #error Python headers needed to compile C extensions, please install development version of Python.
+#elif PY_VERSION_HEX < 0x02040000
+ #error Cython requires Python 2.4+.
+#else
+#include <stddef.h> /* For offsetof */
+#ifndef offsetof
+#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+ #ifndef __stdcall
+ #define __stdcall
+ #endif
+ #ifndef __cdecl
+ #define __cdecl
+ #endif
+ #ifndef __fastcall
+ #define __fastcall
+ #endif
+#endif
+#ifndef DL_IMPORT
+ #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+ #define DL_EXPORT(t) t
+#endif
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef Py_HUGE_VAL
+ #define Py_HUGE_VAL HUGE_VAL
+#endif
+#ifdef PYPY_VERSION
+#define CYTHON_COMPILING_IN_PYPY 1
+#define CYTHON_COMPILING_IN_CPYTHON 0
+#else
+#define CYTHON_COMPILING_IN_PYPY 0
+#define CYTHON_COMPILING_IN_CPYTHON 1
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+ #define PY_SSIZE_T_MAX INT_MAX
+ #define PY_SSIZE_T_MIN INT_MIN
+ #define PY_FORMAT_SIZE_T ""
+ #define CYTHON_FORMAT_SSIZE_T ""
+ #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+ #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
+ #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
+ (PyErr_Format(PyExc_TypeError, \
+ "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
+ (PyObject*)0))
+ #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
+ !PyComplex_Check(o))
+ #define PyIndex_Check __Pyx_PyIndex_Check
+ #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
+ #define __PYX_BUILD_PY_SSIZE_T "i"
+#else
+ #define __PYX_BUILD_PY_SSIZE_T "n"
+ #define CYTHON_FORMAT_SSIZE_T "z"
+ #define __Pyx_PyIndex_Check PyIndex_Check
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+ #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+ #define PyVarObject_HEAD_INIT(type, size) \
+ PyObject_HEAD_INIT(type) size,
+ #define PyType_Modified(t)
+ typedef struct {
+ void *buf;
+ PyObject *obj;
+ Py_ssize_t len;
+ Py_ssize_t itemsize;
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets;
+ void *internal;
+ } Py_buffer;
+ #define PyBUF_SIMPLE 0
+ #define PyBUF_WRITABLE 0x0001
+ #define PyBUF_FORMAT 0x0004
+ #define PyBUF_ND 0x0008
+ #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+ #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+ #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+ #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+ #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
+ #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
+ #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
+ typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
+ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
+#endif
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#else
+ #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+ #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+#endif
+#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
+ #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define Py_TPFLAGS_CHECKTYPES 0
+ #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+ #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
+ #define CYTHON_PEP393_ENABLED 1
+ #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \
+ 0 : _PyUnicode_Ready((PyObject *)(op)))
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
+ #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
+#else
+ #define CYTHON_PEP393_ENABLED 0
+ #define __Pyx_PyUnicode_READY(op) (0)
+ #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
+ #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
+ #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBaseString_Type PyUnicode_Type
+ #define PyStringObject PyUnicodeObject
+ #define PyString_Type PyUnicode_Type
+ #define PyString_Check PyUnicode_Check
+ #define PyString_CheckExact PyUnicode_CheckExact
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PyBytesObject PyStringObject
+ #define PyBytes_Type PyString_Type
+ #define PyBytes_Check PyString_Check
+ #define PyBytes_CheckExact PyString_CheckExact
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+ #define PyBytes_FromFormat PyString_FromFormat
+ #define PyBytes_DecodeEscape PyString_DecodeEscape
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_AS_STRING PyString_AS_STRING
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
+ #define PyBytes_Repr PyString_Repr
+ #define PyBytes_Concat PyString_Concat
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
+#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+#ifndef PySet_CheckExact
+ #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
+#endif
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+#if PY_MAJOR_VERSION >= 3
+ #define PyIntObject PyLongObject
+ #define PyInt_Type PyLong_Type
+ #define PyInt_Check(op) PyLong_Check(op)
+ #define PyInt_CheckExact(op) PyLong_CheckExact(op)
+ #define PyInt_FromString PyLong_FromString
+ #define PyInt_FromUnicode PyLong_FromUnicode
+ #define PyInt_FromLong PyLong_FromLong
+ #define PyInt_FromSize_t PyLong_FromSize_t
+ #define PyInt_FromSsize_t PyLong_FromSsize_t
+ #define PyInt_AsLong PyLong_AsLong
+ #define PyInt_AS_LONG PyLong_AS_LONG
+ #define PyInt_AsSsize_t PyLong_AsSsize_t
+ #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
+ #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyBoolObject PyLongObject
+#endif
+#if PY_VERSION_HEX < 0x03020000
+ typedef long Py_hash_t;
+ #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+ #define __Pyx_PyInt_AsHash_t PyInt_AsLong
+#else
+ #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+ #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
+#endif
+#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
+ #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
+ #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
+#else
+ #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
+ #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
+#endif
+#if PY_MAJOR_VERSION >= 3
+ #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
+#else
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
+#endif
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_NAMESTR(n) ((char *)(n))
+ #define __Pyx_DOCSTR(n) ((char *)(n))
+#else
+ #define __Pyx_NAMESTR(n) (n)
+ #define __Pyx_DOCSTR(n) (n)
+#endif
+
+
+#if PY_MAJOR_VERSION >= 3
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
+#else
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
+#endif
+
+#ifndef __PYX_EXTERN_C
+ #ifdef __cplusplus
+ #define __PYX_EXTERN_C extern "C"
+ #else
+ #define __PYX_EXTERN_C extern
+ #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#define __PYX_HAVE__bintrees__qrbtree
+#define __PYX_HAVE_API__bintrees__qrbtree
+#include "ctrees.h"
+#include "stack.h"
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#ifdef PYREX_WITHOUT_ASSERTIONS
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+
+/* inline attribute */
+#ifndef CYTHON_INLINE
+ #if defined(__GNUC__)
+ #define CYTHON_INLINE __inline__
+ #elif defined(_MSC_VER)
+ #define CYTHON_INLINE __inline
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_INLINE inline
+ #else
+ #define CYTHON_INLINE
+ #endif
+#endif
+
+/* unused attribute */
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+#endif
+
+typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
+
+
+/* Type Conversion Predeclarations */
+
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
+
+#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
+
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+#else
+#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
+#endif
+#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
+
+#ifdef __GNUC__
+ /* Test for GCC > 2.95 */
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
+ #define likely(x) __builtin_expect(!!(x), 1)
+ #define unlikely(x) __builtin_expect(!!(x), 0)
+ #else /* __GNUC__ > 2 ... */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+ #endif /* __GNUC__ > 2 ... */
+#else /* __GNUC__ */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+#endif /* __GNUC__ */
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+ "qrbtree.pyx",
+ "cwalker.pxd",
+};
+
+/*--- Type declarations ---*/
+struct __pyx_obj_8bintrees_7cwalker_cWalker;
+struct __pyx_obj_8bintrees_7qrbtree_cRBTree;
+
+/* "cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+struct __pyx_obj_8bintrees_7cwalker_cWalker {
+ PyObject_HEAD
+ struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab;
+ node_t *node;
+ node_t *root;
+ node_stack_t *stack;
+};
+
+
+/* "bintrees\qrbtree.pyx":16
+ * from ctrees cimport *
+ *
+ * cdef class cRBTree: # <<<<<<<<<<<<<<
+ * cdef node_t *_root
+ * cdef int _count
+ */
+struct __pyx_obj_8bintrees_7qrbtree_cRBTree {
+ PyObject_HEAD
+ node_t *_root;
+ int _count;
+};
+
+
+
+/* "cwalker.pxd":11
+ * from stack cimport node_stack_t
+ *
+ * cdef class cWalker: # <<<<<<<<<<<<<<
+ * cdef node_t *node
+ * cdef node_t *root
+ */
+
+struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker {
+ void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *);
+ PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+ PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch);
+};
+static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker;
+#ifndef CYTHON_REFNANNY
+ #define CYTHON_REFNANNY 0
+#endif
+#if CYTHON_REFNANNY
+ typedef struct {
+ void (*INCREF)(void*, PyObject*, int);
+ void (*DECREF)(void*, PyObject*, int);
+ void (*GOTREF)(void*, PyObject*, int);
+ void (*GIVEREF)(void*, PyObject*, int);
+ void* (*SetupContext)(const char*, int, const char*);
+ void (*FinishContext)(void**);
+ } __Pyx_RefNannyAPIStruct;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
+ #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+#ifdef WITH_THREAD
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ if (acquire_gil) { \
+ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ PyGILState_Release(__pyx_gilstate_save); \
+ } else { \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+ }
+#else
+ #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+#endif
+ #define __Pyx_RefNannyFinishContext() \
+ __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+ #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+ #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+ #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+ #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+ #define __Pyx_RefNannyDeclarations
+ #define __Pyx_RefNannySetupContext(name, acquire_gil)
+ #define __Pyx_RefNannyFinishContext()
+ #define __Pyx_INCREF(r) Py_INCREF(r)
+ #define __Pyx_DECREF(r) Py_DECREF(r)
+ #define __Pyx_GOTREF(r)
+ #define __Pyx_GIVEREF(r)
+ #define __Pyx_XINCREF(r) Py_XINCREF(r)
+ #define __Pyx_XDECREF(r) Py_XDECREF(r)
+ #define __Pyx_XGOTREF(r)
+ #define __Pyx_XGIVEREF(r)
+#endif /* CYTHON_REFNANNY */
+#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
+#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
+
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
+ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
+ const char* function_name); /*proto*/
+
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
+
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+ PyObject *r;
+ if (!j) return NULL;
+ r = PyObject_GetItem(o, j);
+ Py_DECREF(j);
+ return r;
+}
+#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_List_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
+ PyObject *r = PyList_GET_ITEM(o, i);
+ Py_INCREF(r);
+ return r;
+ }
+ else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
+ PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
+ Py_INCREF(r);
+ return r;
+ }
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+ return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Tuple_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
+ PyObject *r = PyTuple_GET_ITEM(o, i);
+ Py_INCREF(r);
+ return r;
+ }
+ else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
+ PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
+ Py_INCREF(r);
+ return r;
+ }
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+ return PySequence_GetItem(o, i);
+#endif
+}
+#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+ __Pyx_GetItemInt_Fast(o, i) : \
+ __Pyx_GetItemInt_Generic(o, to_py_func(i)))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ if (PyList_CheckExact(o)) {
+ Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+ if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
+ PyObject *r = PyList_GET_ITEM(o, n);
+ Py_INCREF(r);
+ return r;
+ }
+ }
+ else if (PyTuple_CheckExact(o)) {
+ Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+ if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
+ PyObject *r = PyTuple_GET_ITEM(o, n);
+ Py_INCREF(r);
+ return r;
+ }
+ } else { /* inlined PySequence_GetItem() */
+ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ if (likely(m && m->sq_item)) {
+ if (unlikely(i < 0) && likely(m->sq_length)) {
+ Py_ssize_t l = m->sq_length(o);
+ if (unlikely(l < 0)) return NULL;
+ i += l;
+ }
+ return m->sq_item(o, i);
+ }
+ }
+#else
+ if (PySequence_Check(o)) {
+ return PySequence_GetItem(o, i);
+ }
+#endif
+ return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
+
+static int __Pyx_check_binary_version(void);
+
+#if !defined(__Pyx_PyIdentifier_FromString)
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
+#else
+ #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
+#endif
+#endif
+
+static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
+
+static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/
+
+static void* __Pyx_GetVtable(PyObject *dict); /*proto*/
+
+typedef struct {
+ int code_line;
+ PyCodeObject* code_object;
+} __Pyx_CodeObjectCacheEntry;
+struct __Pyx_CodeObjectCache {
+ int count;
+ int max_count;
+ __Pyx_CodeObjectCacheEntry* entries;
+};
+static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
+static PyCodeObject *__pyx_find_code_object(int code_line);
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
+
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+
+/* Module declarations from 'bintrees.ctrees' */
+
+/* Module declarations from 'bintrees.stack' */
+
+/* Module declarations from 'bintrees.cwalker' */
+static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0;
+
+/* Module declarations from 'bintrees.qrbtree' */
+static PyTypeObject *__pyx_ptype_8bintrees_7qrbtree_cRBTree = 0;
+#define __Pyx_MODULE_NAME "bintrees.qrbtree"
+int __pyx_module_is_main_bintrees__qrbtree = 0;
+
+/* Implementation of 'bintrees.qrbtree' */
+static PyObject *__pyx_builtin_property;
+static PyObject *__pyx_builtin_KeyError;
+static PyObject *__pyx_builtin_MemoryError;
+static PyObject *__pyx_builtin_ValueError;
+static int __pyx_pf_8bintrees_7qrbtree_7cRBTree___cinit__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_items); /* proto */
+static void __pyx_pf_8bintrees_7qrbtree_7cRBTree_2__dealloc__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_4count(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_6__getstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_8__setstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_state); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_10clear(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_12get_value(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_14get_walker(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_16insert(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_18remove(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_20max_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_22min_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */
+static char __pyx_k_1[] = "Can not allocate memory for node structure.";
+static char __pyx_k_3[] = "Tree is empty";
+static char __pyx_k__key[] = "key";
+static char __pyx_k__count[] = "count";
+static char __pyx_k__items[] = "items";
+static char __pyx_k__value[] = "value";
+static char __pyx_k__update[] = "update";
+static char __pyx_k____all__[] = "__all__";
+static char __pyx_k__cRBTree[] = "cRBTree";
+static char __pyx_k__cWalker[] = "cWalker";
+static char __pyx_k__cwalker[] = "cwalker";
+static char __pyx_k__KeyError[] = "KeyError";
+static char __pyx_k____main__[] = "__main__";
+static char __pyx_k____test__[] = "__test__";
+static char __pyx_k__property[] = "property";
+static char __pyx_k__ValueError[] = "ValueError";
+static char __pyx_k__MemoryError[] = "MemoryError";
+static PyObject *__pyx_kp_s_1;
+static PyObject *__pyx_kp_s_3;
+static PyObject *__pyx_n_s__KeyError;
+static PyObject *__pyx_n_s__MemoryError;
+static PyObject *__pyx_n_s__ValueError;
+static PyObject *__pyx_n_s____all__;
+static PyObject *__pyx_n_s____main__;
+static PyObject *__pyx_n_s____test__;
+static PyObject *__pyx_n_s__cRBTree;
+static PyObject *__pyx_n_s__cWalker;
+static PyObject *__pyx_n_s__count;
+static PyObject *__pyx_n_s__cwalker;
+static PyObject *__pyx_n_s__items;
+static PyObject *__pyx_n_s__key;
+static PyObject *__pyx_n_s__property;
+static PyObject *__pyx_n_s__update;
+static PyObject *__pyx_n_s__value;
+static PyObject *__pyx_int_0;
+static PyObject *__pyx_k_tuple_2;
+static PyObject *__pyx_k_tuple_4;
+static PyObject *__pyx_k_tuple_5;
+
+/* Python wrapper */
+static int __pyx_pw_8bintrees_7qrbtree_7cRBTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_8bintrees_7qrbtree_7cRBTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_items = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__items,0};
+ PyObject* values[1] = {0};
+
+ /* "bintrees\qrbtree.pyx":20
+ * cdef int _count
+ *
+ * def __cinit__(self, items=None): # <<<<<<<<<<<<<<
+ * self._root = NULL
+ * self._count = 0
+ */
+ values[0] = ((PyObject *)Py_None);
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (kw_args > 0) {
+ PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__items);
+ if (value) { values[0] = value; kw_args--; }
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else {
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ }
+ __pyx_v_items = values[0];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree___cinit__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), __pyx_v_items);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static int __pyx_pf_8bintrees_7qrbtree_7cRBTree___cinit__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_items) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__cinit__", 0);
+
+ /* "bintrees\qrbtree.pyx":21
+ *
+ * def __cinit__(self, items=None):
+ * self._root = NULL # <<<<<<<<<<<<<<
+ * self._count = 0
+ * if items:
+ */
+ __pyx_v_self->_root = NULL;
+
+ /* "bintrees\qrbtree.pyx":22
+ * def __cinit__(self, items=None):
+ * self._root = NULL
+ * self._count = 0 # <<<<<<<<<<<<<<
+ * if items:
+ * self.update(items)
+ */
+ __pyx_v_self->_count = 0;
+
+ /* "bintrees\qrbtree.pyx":23
+ * self._root = NULL
+ * self._count = 0
+ * if items: # <<<<<<<<<<<<<<
+ * self.update(items)
+ *
+ */
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_items); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_t_1) {
+
+ /* "bintrees\qrbtree.pyx":24
+ * self._count = 0
+ * if items:
+ * self.update(items) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_items);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_items);
+ __Pyx_GIVEREF(__pyx_v_items);
+ __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static void __pyx_pw_8bintrees_7qrbtree_7cRBTree_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_8bintrees_7qrbtree_7cRBTree_3__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_pf_8bintrees_7qrbtree_7cRBTree_2__dealloc__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "bintrees\qrbtree.pyx":26
+ * self.update(items)
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * ct_delete_tree(self._root)
+ *
+ */
+
+static void __pyx_pf_8bintrees_7qrbtree_7cRBTree_2__dealloc__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
+
+ /* "bintrees\qrbtree.pyx":27
+ *
+ * def __dealloc__(self):
+ * ct_delete_tree(self._root) # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ ct_delete_tree(__pyx_v_self->_root);
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("count (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_4count(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":30
+ *
+ * @property
+ * def count(self): # <<<<<<<<<<<<<<
+ * return self._count
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_4count(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("count", 0);
+
+ /* "bintrees\qrbtree.pyx":31
+ * @property
+ * def count(self):
+ * return self._count # <<<<<<<<<<<<<<
+ *
+ * def __getstate__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_6__getstate__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":33
+ * return self._count
+ *
+ * def __getstate__(self): # <<<<<<<<<<<<<<
+ * return dict(self.items())
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_6__getstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__getstate__", 0);
+
+ /* "bintrees\qrbtree.pyx":34
+ *
+ * def __getstate__(self):
+ * return dict(self.items()) # <<<<<<<<<<<<<<
+ *
+ * def __setstate__(self, state):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_8__setstate__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), ((PyObject *)__pyx_v_state));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":36
+ * return dict(self.items())
+ *
+ * def __setstate__(self, state): # <<<<<<<<<<<<<<
+ * self.update(state)
+ *
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_8__setstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_state) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setstate__", 0);
+
+ /* "bintrees\qrbtree.pyx":37
+ *
+ * def __setstate__(self, state):
+ * self.update(state) # <<<<<<<<<<<<<<
+ *
+ * def clear(self):
+ */
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_state);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state);
+ __Pyx_GIVEREF(__pyx_v_state);
+ __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("clear (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_10clear(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":39
+ * self.update(state)
+ *
+ * def clear(self): # <<<<<<<<<<<<<<
+ * ct_delete_tree(self._root)
+ * self._count = 0
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_10clear(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("clear", 0);
+
+ /* "bintrees\qrbtree.pyx":40
+ *
+ * def clear(self):
+ * ct_delete_tree(self._root) # <<<<<<<<<<<<<<
+ * self._count = 0
+ * self._root = NULL
+ */
+ ct_delete_tree(__pyx_v_self->_root);
+
+ /* "bintrees\qrbtree.pyx":41
+ * def clear(self):
+ * ct_delete_tree(self._root)
+ * self._count = 0 # <<<<<<<<<<<<<<
+ * self._root = NULL
+ *
+ */
+ __pyx_v_self->_count = 0;
+
+ /* "bintrees\qrbtree.pyx":42
+ * ct_delete_tree(self._root)
+ * self._count = 0
+ * self._root = NULL # <<<<<<<<<<<<<<
+ *
+ * def get_value(self, key):
+ */
+ __pyx_v_self->_root = NULL;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("get_value (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_12get_value(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":44
+ * self._root = NULL
+ *
+ * def get_value(self, key): # <<<<<<<<<<<<<<
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None:
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_12get_value(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_v_result = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_value", 0);
+
+ /* "bintrees\qrbtree.pyx":45
+ *
+ * def get_value(self, key):
+ * result = <object> ct_get_item(self._root, key) # <<<<<<<<<<<<<<
+ * if result is None:
+ * raise KeyError(key)
+ */
+ __pyx_t_1 = ct_get_item(__pyx_v_self->_root, __pyx_v_key);
+ __Pyx_INCREF(((PyObject *)__pyx_t_1));
+ __pyx_v_result = ((PyObject *)__pyx_t_1);
+
+ /* "bintrees\qrbtree.pyx":46
+ * def get_value(self, key):
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None: # <<<<<<<<<<<<<<
+ * raise KeyError(key)
+ * else:
+ */
+ __pyx_t_2 = (__pyx_v_result == Py_None);
+ if (__pyx_t_2) {
+
+ /* "bintrees\qrbtree.pyx":47
+ * result = <object> ct_get_item(self._root, key)
+ * if result is None:
+ * raise KeyError(key) # <<<<<<<<<<<<<<
+ * else:
+ * return result[1]
+ */
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qrbtree.pyx":49
+ * raise KeyError(key)
+ * else:
+ * return result[1] # <<<<<<<<<<<<<<
+ *
+ * def get_walker(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_result, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_r = __pyx_t_4;
+ __pyx_t_4 = 0;
+ goto __pyx_L0;
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_result);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("get_walker (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_14get_walker(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":51
+ * return result[1]
+ *
+ * def get_walker(self): # <<<<<<<<<<<<<<
+ * cdef cWalker walker
+ * walker = cWalker()
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_14get_walker(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_walker = 0;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_walker", 0);
+
+ /* "bintrees\qrbtree.pyx":53
+ * def get_walker(self):
+ * cdef cWalker walker
+ * walker = cWalker() # <<<<<<<<<<<<<<
+ * walker.set_tree(self._root)
+ * return walker
+ */
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8bintrees_7cwalker_cWalker)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_walker = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_t_1);
+ __pyx_t_1 = 0;
+
+ /* "bintrees\qrbtree.pyx":54
+ * cdef cWalker walker
+ * walker = cWalker()
+ * walker.set_tree(self._root) # <<<<<<<<<<<<<<
+ * return walker
+ *
+ */
+ ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_walker->__pyx_vtab)->set_tree(__pyx_v_walker, __pyx_v_self->_root);
+
+ /* "bintrees\qrbtree.pyx":55
+ * walker = cWalker()
+ * walker.set_tree(self._root)
+ * return walker # <<<<<<<<<<<<<<
+ *
+ * def insert(self, key, value):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_walker));
+ __pyx_r = ((PyObject *)__pyx_v_walker);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.get_walker", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_walker);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_key = 0;
+ PyObject *__pyx_v_value = 0;
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("insert (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__value,0};
+ PyObject* values[2] = {0,0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key)) != 0)) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ case 1:
+ if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ }
+ __pyx_v_key = values[0];
+ __pyx_v_value = values[1];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_16insert(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), __pyx_v_key, __pyx_v_value);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":57
+ * return walker
+ *
+ * def insert(self, key, value): # <<<<<<<<<<<<<<
+ * res = rb_insert(&self._root, key, value)
+ * if res < 0:
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_16insert(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) {
+ PyObject *__pyx_v_res = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_4;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("insert", 0);
+
+ /* "bintrees\qrbtree.pyx":58
+ *
+ * def insert(self, key, value):
+ * res = rb_insert(&self._root, key, value) # <<<<<<<<<<<<<<
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.')
+ */
+ __pyx_t_1 = PyInt_FromLong(rb_insert((&__pyx_v_self->_root), __pyx_v_key, __pyx_v_value)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_res = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "bintrees\qrbtree.pyx":59
+ * def insert(self, key, value):
+ * res = rb_insert(&self._root, key, value)
+ * if res < 0: # <<<<<<<<<<<<<<
+ * raise MemoryError('Can not allocate memory for node structure.')
+ * else:
+ */
+ __pyx_t_1 = PyObject_RichCompare(__pyx_v_res, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (__pyx_t_2) {
+
+ /* "bintrees\qrbtree.pyx":60
+ * res = rb_insert(&self._root, key, value)
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<<
+ * else:
+ * self._count += res
+ */
+ __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qrbtree.pyx":62
+ * raise MemoryError('Can not allocate memory for node structure.')
+ * else:
+ * self._count += res # <<<<<<<<<<<<<<
+ *
+ * def remove(self, key):
+ */
+ __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_res); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_self->_count = __pyx_t_4;
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_res);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("remove (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_18remove(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), ((PyObject *)__pyx_v_key));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":64
+ * self._count += res
+ *
+ * def remove(self, key): # <<<<<<<<<<<<<<
+ * cdef int result
+ * result = rb_remove(&self._root, key)
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_18remove(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key) {
+ int __pyx_v_result;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("remove", 0);
+
+ /* "bintrees\qrbtree.pyx":66
+ * def remove(self, key):
+ * cdef int result
+ * result = rb_remove(&self._root, key) # <<<<<<<<<<<<<<
+ * if result == 0:
+ * raise KeyError(str(key))
+ */
+ __pyx_v_result = rb_remove((&__pyx_v_self->_root), __pyx_v_key);
+
+ /* "bintrees\qrbtree.pyx":67
+ * cdef int result
+ * result = rb_remove(&self._root, key)
+ * if result == 0: # <<<<<<<<<<<<<<
+ * raise KeyError(str(key))
+ * else:
+ */
+ __pyx_t_1 = (__pyx_v_result == 0);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qrbtree.pyx":68
+ * result = rb_remove(&self._root, key)
+ * if result == 0:
+ * raise KeyError(str(key)) # <<<<<<<<<<<<<<
+ * else:
+ * self._count -= 1
+ */
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_key);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
+ __Pyx_GIVEREF(__pyx_v_key);
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ /*else*/ {
+
+ /* "bintrees\qrbtree.pyx":70
+ * raise KeyError(str(key))
+ * else:
+ * self._count -= 1 # <<<<<<<<<<<<<<
+ *
+ * def max_item(self):
+ */
+ __pyx_v_self->_count = (__pyx_v_self->_count - 1);
+ }
+ __pyx_L3:;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.remove", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_7qrbtree_7cRBTree_20max_item[] = " Get item with max key of tree, raises ValueError if tree is empty. ";
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("max_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_20max_item(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":72
+ * self._count -= 1
+ *
+ * def max_item(self): # <<<<<<<<<<<<<<
+ * """ Get item with max key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_20max_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ node_t *__pyx_v_node;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("max_item", 0);
+
+ /* "bintrees\qrbtree.pyx":75
+ * """ Get item with max key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ * node = ct_max_node(self._root) # <<<<<<<<<<<<<<
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ */
+ __pyx_v_node = ct_max_node(__pyx_v_self->_root);
+
+ /* "bintrees\qrbtree.pyx":76
+ * cdef node_t *node
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None # <<<<<<<<<<<<<<
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_1 = (__pyx_v_node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qrbtree.pyx":77
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qrbtree.pyx":78
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<<
+ *
+ * def min_item(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->key));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->value));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value));
+ __pyx_r = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.max_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8bintrees_7qrbtree_7cRBTree_22min_item[] = " Get item with min key of tree, raises ValueError if tree is empty. ";
+static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("min_item (wrapper)", 0);
+ __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_22min_item(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self));
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "bintrees\qrbtree.pyx":80
+ * return (<object>node.key, <object>node.value)
+ *
+ * def min_item(self): # <<<<<<<<<<<<<<
+ * """ Get item with min key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ */
+
+static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_22min_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) {
+ node_t *__pyx_v_node;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("min_item", 0);
+
+ /* "bintrees\qrbtree.pyx":83
+ * """ Get item with min key of tree, raises ValueError if tree is empty. """
+ * cdef node_t *node
+ * node = ct_min_node(self._root) # <<<<<<<<<<<<<<
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ */
+ __pyx_v_node = ct_min_node(__pyx_v_self->_root);
+
+ /* "bintrees\qrbtree.pyx":84
+ * cdef node_t *node
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None # <<<<<<<<<<<<<<
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_1 = (__pyx_v_node == NULL);
+ if (__pyx_t_1) {
+
+ /* "bintrees\qrbtree.pyx":85
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L3;
+ }
+ __pyx_L3:;
+
+ /* "bintrees\qrbtree.pyx":86
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty")
+ * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<<
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->key));
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key));
+ __Pyx_INCREF(((PyObject *)__pyx_v_node->value));
+ PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value));
+ __pyx_r = ((PyObject *)__pyx_t_2);
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.min_item", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_tp_new_8bintrees_7qrbtree_cRBTree(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ if (__pyx_pw_8bintrees_7qrbtree_7cRBTree_1__cinit__(o, a, k) < 0) {
+ Py_DECREF(o); o = 0;
+ }
+ return o;
+}
+
+static void __pyx_tp_dealloc_8bintrees_7qrbtree_cRBTree(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pw_8bintrees_7qrbtree_7cRBTree_3__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_8bintrees_7qrbtree_cRBTree[] = {
+ {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_5count, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_7__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_9__setstate__, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_11clear, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("get_value"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_13get_value, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("get_walker"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_15get_walker, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_17insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("remove"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_19remove, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("max_item"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_21max_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_7qrbtree_7cRBTree_20max_item)},
+ {__Pyx_NAMESTR("min_item"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_23min_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_7qrbtree_7cRBTree_22min_item)},
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_cRBTree = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_cRBTree = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_cRBTree = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_cRBTree = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_8bintrees_7qrbtree_cRBTree = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("bintrees.qrbtree.cRBTree"), /*tp_name*/
+ sizeof(struct __pyx_obj_8bintrees_7qrbtree_cRBTree), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_8bintrees_7qrbtree_cRBTree, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_cRBTree, /*tp_as_number*/
+ &__pyx_tp_as_sequence_cRBTree, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_cRBTree, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_cRBTree, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_8bintrees_7qrbtree_cRBTree, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_8bintrees_7qrbtree_cRBTree, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+ {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef __pyx_moduledef = {
+ PyModuleDef_HEAD_INIT,
+ __Pyx_NAMESTR("qrbtree"),
+ 0, /* m_doc */
+ -1, /* m_size */
+ __pyx_methods /* m_methods */,
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
+};
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+ {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
+ {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
+ {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
+ {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1},
+ {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
+ {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
+ {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
+ {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
+ {&__pyx_n_s__cRBTree, __pyx_k__cRBTree, sizeof(__pyx_k__cRBTree), 0, 0, 1, 1},
+ {&__pyx_n_s__cWalker, __pyx_k__cWalker, sizeof(__pyx_k__cWalker), 0, 0, 1, 1},
+ {&__pyx_n_s__count, __pyx_k__count, sizeof(__pyx_k__count), 0, 0, 1, 1},
+ {&__pyx_n_s__cwalker, __pyx_k__cwalker, sizeof(__pyx_k__cwalker), 0, 0, 1, 1},
+ {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1},
+ {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1},
+ {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1},
+ {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1},
+ {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0}
+};
+static int __Pyx_InitCachedBuiltins(void) {
+ __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+static int __Pyx_InitCachedConstants(void) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
+
+ /* "bintrees\qrbtree.pyx":60
+ * res = rb_insert(&self._root, key, value)
+ * if res < 0:
+ * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<<
+ * else:
+ * self._count += res
+ */
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_2);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
+
+ /* "bintrees\qrbtree.pyx":77
+ * node = ct_max_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ *
+ */
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_4);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
+
+ /* "bintrees\qrbtree.pyx":85
+ * node = ct_min_node(self._root)
+ * if node == NULL: # root is None
+ * raise ValueError("Tree is empty") # <<<<<<<<<<<<<<
+ * return (<object>node.key, <object>node.value)
+ */
+ __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_k_tuple_5);
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
+ __Pyx_RefNannyFinishContext();
+ return 0;
+ __pyx_L1_error:;
+ __Pyx_RefNannyFinishContext();
+ return -1;
+}
+
+static int __Pyx_InitGlobals(void) {
+ if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC initqrbtree(void); /*proto*/
+PyMODINIT_FUNC initqrbtree(void)
+#else
+PyMODINIT_FUNC PyInit_qrbtree(void); /*proto*/
+PyMODINIT_FUNC PyInit_qrbtree(void)
+#endif
+{
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ __Pyx_RefNannyDeclarations
+ #if CYTHON_REFNANNY
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+ if (!__Pyx_RefNanny) {
+ PyErr_Clear();
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+ if (!__Pyx_RefNanny)
+ Py_FatalError("failed to import 'refnanny' module");
+ }
+ #endif
+ __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_qrbtree(void)", 0);
+ if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #ifdef __Pyx_CyFunction_USED
+ if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_FusedFunction_USED
+ if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ #ifdef __Pyx_Generator_USED
+ if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ /*--- Library function declarations ---*/
+ /*--- Threads initialization code ---*/
+ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+ #ifdef WITH_THREAD /* Python build with threading support? */
+ PyEval_InitThreads();
+ #endif
+ #endif
+ /*--- Module creation code ---*/
+ #if PY_MAJOR_VERSION < 3
+ __pyx_m = Py_InitModule4(__Pyx_NAMESTR("qrbtree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+ #else
+ __pyx_m = PyModule_Create(&__pyx_moduledef);
+ #endif
+ if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if PY_MAJOR_VERSION >= 3
+ {
+ PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!PyDict_GetItemString(modules, "bintrees.qrbtree")) {
+ if (unlikely(PyDict_SetItemString(modules, "bintrees.qrbtree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ }
+ #endif
+ __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #if CYTHON_COMPILING_IN_PYPY
+ Py_INCREF(__pyx_b);
+ #endif
+ if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ /*--- Initialize various global constants etc. ---*/
+ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_module_is_main_bintrees__qrbtree) {
+ if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ }
+ /*--- Builtin init code ---*/
+ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Constants init code ---*/
+ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Global init code ---*/
+ /*--- Variable export code ---*/
+ /*--- Function export code ---*/
+ /*--- Type init code ---*/
+ if (PyType_Ready(&__pyx_type_8bintrees_7qrbtree_cRBTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "cRBTree", (PyObject *)&__pyx_type_8bintrees_7qrbtree_cRBTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_8bintrees_7qrbtree_cRBTree = &__pyx_type_8bintrees_7qrbtree_cRBTree;
+ /*--- Type import code ---*/
+ __pyx_ptype_8bintrees_7cwalker_cWalker = __Pyx_ImportType("bintrees.cwalker", "cWalker", sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), 1); if (unlikely(!__pyx_ptype_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_vtabptr_8bintrees_7cwalker_cWalker = (struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker*)__Pyx_GetVtable(__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict); if (unlikely(!__pyx_vtabptr_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Variable import code ---*/
+ /*--- Function import code ---*/
+ /*--- Execution code ---*/
+
+ /* "bintrees\qrbtree.pyx":9
+ * # License: MIT License
+ *
+ * __all__ = ['cRBTree'] # <<<<<<<<<<<<<<
+ *
+ * from cwalker import cWalker
+ */
+ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__cRBTree));
+ PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cRBTree));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cRBTree));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+
+ /* "bintrees\qrbtree.pyx":11
+ * __all__ = ['cRBTree']
+ *
+ * from cwalker import cWalker # <<<<<<<<<<<<<<
+ *
+ * from cwalker cimport *
+ */
+ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__cWalker));
+ PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cWalker));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cWalker));
+ __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__cwalker), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+ /* "bintrees\qrbtree.pyx":30
+ *
+ * @property
+ * def count(self): # <<<<<<<<<<<<<<
+ * return self._count
+ *
+ */
+ __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7qrbtree_cRBTree, __pyx_n_s__count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7qrbtree_cRBTree->tp_dict, __pyx_n_s__count, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ PyType_Modified(__pyx_ptype_8bintrees_7qrbtree_cRBTree);
+
+ /* "bintrees\qrbtree.pyx":1
+ * #!/usr/bin/env python # <<<<<<<<<<<<<<
+ * #coding:utf-8
+ * # Author: mozman
+ */
+ __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ if (__pyx_m) {
+ __Pyx_AddTraceback("init bintrees.qrbtree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ Py_DECREF(__pyx_m); __pyx_m = 0;
+ } else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "init bintrees.qrbtree");
+ }
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ #if PY_MAJOR_VERSION < 3
+ return;
+ #else
+ return __pyx_m;
+ #endif
+}
+
+/* Runtime support code */
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+ PyObject *m = NULL, *p = NULL;
+ void *r = NULL;
+ m = PyImport_ImportModule((char *)modname);
+ if (!m) goto end;
+ p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
+ if (!p) goto end;
+ r = PyLong_AsVoidPtr(p);
+end:
+ Py_XDECREF(p);
+ Py_XDECREF(m);
+ return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif /* CYTHON_REFNANNY */
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result) {
+ if (dict != __pyx_b) {
+ PyErr_Clear();
+ result = PyObject_GetAttr(__pyx_b, name);
+ }
+ if (!result) {
+ PyErr_SetObject(PyExc_NameError, name);
+ }
+ }
+ return result;
+}
+
+static void __Pyx_RaiseDoubleKeywordsError(
+ const char* func_name,
+ PyObject* kw_name)
+{
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION >= 3
+ "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+ #else
+ "%s() got multiple values for keyword argument '%s'", func_name,
+ PyString_AsString(kw_name));
+ #endif
+}
+
+static int __Pyx_ParseOptionalKeywords(
+ PyObject *kwds,
+ PyObject **argnames[],
+ PyObject *kwds2,
+ PyObject *values[],
+ Py_ssize_t num_pos_args,
+ const char* function_name)
+{
+ PyObject *key = 0, *value = 0;
+ Py_ssize_t pos = 0;
+ PyObject*** name;
+ PyObject*** first_kw_arg = argnames + num_pos_args;
+ while (PyDict_Next(kwds, &pos, &key, &value)) {
+ name = first_kw_arg;
+ while (*name && (**name != key)) name++;
+ if (*name) {
+ values[name-argnames] = value;
+ continue;
+ }
+ name = first_kw_arg;
+ #if PY_MAJOR_VERSION < 3
+ if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
+ while (*name) {
+ if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
+ && _PyString_Eq(**name, key)) {
+ values[name-argnames] = value;
+ break;
+ }
+ name++;
+ }
+ if (*name) continue;
+ else {
+ PyObject*** argname = argnames;
+ while (argname != first_kw_arg) {
+ if ((**argname == key) || (
+ (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
+ && _PyString_Eq(**argname, key))) {
+ goto arg_passed_twice;
+ }
+ argname++;
+ }
+ }
+ } else
+ #endif
+ if (likely(PyUnicode_Check(key))) {
+ while (*name) {
+ int cmp = (**name == key) ? 0 :
+ #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+ (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
+ #endif
+ PyUnicode_Compare(**name, key);
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+ if (cmp == 0) {
+ values[name-argnames] = value;
+ break;
+ }
+ name++;
+ }
+ if (*name) continue;
+ else {
+ PyObject*** argname = argnames;
+ while (argname != first_kw_arg) {
+ int cmp = (**argname == key) ? 0 :
+ #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+ (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
+ #endif
+ PyUnicode_Compare(**argname, key);
+ if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+ if (cmp == 0) goto arg_passed_twice;
+ argname++;
+ }
+ }
+ } else
+ goto invalid_keyword_type;
+ if (kwds2) {
+ if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+ } else {
+ goto invalid_keyword;
+ }
+ }
+ return 0;
+arg_passed_twice:
+ __Pyx_RaiseDoubleKeywordsError(function_name, key);
+ goto bad;
+invalid_keyword_type:
+ PyErr_Format(PyExc_TypeError,
+ "%s() keywords must be strings", function_name);
+ goto bad;
+invalid_keyword:
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION < 3
+ "%s() got an unexpected keyword argument '%s'",
+ function_name, PyString_AsString(key));
+ #else
+ "%s() got an unexpected keyword argument '%U'",
+ function_name, key);
+ #endif
+bad:
+ return -1;
+}
+
+static void __Pyx_RaiseArgtupleInvalid(
+ const char* func_name,
+ int exact,
+ Py_ssize_t num_min,
+ Py_ssize_t num_max,
+ Py_ssize_t num_found)
+{
+ Py_ssize_t num_expected;
+ const char *more_or_less;
+ if (num_found < num_min) {
+ num_expected = num_min;
+ more_or_less = "at least";
+ } else {
+ num_expected = num_max;
+ more_or_less = "at most";
+ }
+ if (exact) {
+ more_or_less = "exactly";
+ }
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
+ func_name, more_or_less, num_expected,
+ (num_expected == 1) ? "" : "s", num_found);
+}
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+ tmp_type = tstate->curexc_type;
+ tmp_value = tstate->curexc_value;
+ tmp_tb = tstate->curexc_traceback;
+ tstate->curexc_type = type;
+ tstate->curexc_value = value;
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+#else
+ PyErr_Restore(type, value, tb);
+#endif
+}
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->curexc_type;
+ *value = tstate->curexc_value;
+ *tb = tstate->curexc_traceback;
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+#else
+ PyErr_Fetch(type, value, tb);
+#endif
+}
+
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
+ CYTHON_UNUSED PyObject *cause) {
+ Py_XINCREF(type);
+ if (!value || value == Py_None)
+ value = NULL;
+ else
+ Py_INCREF(value);
+ if (!tb || tb == Py_None)
+ tb = NULL;
+ else {
+ Py_INCREF(tb);
+ if (!PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto raise_error;
+ }
+ }
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyClass_Check(type)) {
+ #else
+ if (PyType_Check(type)) {
+ #endif
+#if CYTHON_COMPILING_IN_PYPY
+ if (!value) {
+ Py_INCREF(Py_None);
+ value = Py_None;
+ }
+#endif
+ PyErr_NormalizeException(&type, &value, &tb);
+ } else {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto raise_error;
+ }
+ value = type;
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyInstance_Check(type)) {
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
+ }
+ else {
+ type = 0;
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception must be an old-style class or instance");
+ goto raise_error;
+ }
+ #else
+ type = (PyObject*) Py_TYPE(type);
+ Py_INCREF(type);
+ if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto raise_error;
+ }
+ #endif
+ }
+ __Pyx_ErrRestore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ return;
+}
+#else /* Python 3+ */
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+ PyObject* owned_instance = NULL;
+ if (tb == Py_None) {
+ tb = 0;
+ } else if (tb && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto bad;
+ }
+ if (value == Py_None)
+ value = 0;
+ if (PyExceptionInstance_Check(type)) {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto bad;
+ }
+ value = type;
+ type = (PyObject*) Py_TYPE(value);
+ } else if (PyExceptionClass_Check(type)) {
+ PyObject *args;
+ if (!value)
+ args = PyTuple_New(0);
+ else if (PyTuple_Check(value)) {
+ Py_INCREF(value);
+ args = value;
+ }
+ else
+ args = PyTuple_Pack(1, value);
+ if (!args)
+ goto bad;
+ owned_instance = PyEval_CallObject(type, args);
+ Py_DECREF(args);
+ if (!owned_instance)
+ goto bad;
+ value = owned_instance;
+ if (!PyExceptionInstance_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "calling %R should have returned an instance of "
+ "BaseException, not %R",
+ type, Py_TYPE(value));
+ goto bad;
+ }
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto bad;
+ }
+ if (cause && cause != Py_None) {
+ PyObject *fixed_cause;
+ if (PyExceptionClass_Check(cause)) {
+ fixed_cause = PyObject_CallObject(cause, NULL);
+ if (fixed_cause == NULL)
+ goto bad;
+ }
+ else if (PyExceptionInstance_Check(cause)) {
+ fixed_cause = cause;
+ Py_INCREF(fixed_cause);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
+ goto bad;
+ }
+ PyException_SetCause(value, fixed_cause);
+ }
+ PyErr_SetObject(type, value);
+ if (tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ PyObject* tmp_tb = tstate->curexc_traceback;
+ if (tb != tmp_tb) {
+ Py_INCREF(tb);
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_tb);
+ }
+ }
+bad:
+ Py_XDECREF(owned_instance);
+ return;
+}
+#endif
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
+ PyObject *py_import = 0;
+ PyObject *empty_list = 0;
+ PyObject *module = 0;
+ PyObject *global_dict = 0;
+ PyObject *empty_dict = 0;
+ PyObject *list;
+ py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
+ if (!py_import)
+ goto bad;
+ if (from_list)
+ list = from_list;
+ else {
+ empty_list = PyList_New(0);
+ if (!empty_list)
+ goto bad;
+ list = empty_list;
+ }
+ global_dict = PyModule_GetDict(__pyx_m);
+ if (!global_dict)
+ goto bad;
+ empty_dict = PyDict_New();
+ if (!empty_dict)
+ goto bad;
+ #if PY_VERSION_HEX >= 0x02050000
+ {
+ #if PY_MAJOR_VERSION >= 3
+ if (level == -1) {
+ if (strchr(__Pyx_MODULE_NAME, '.')) {
+ /* try package relative import first */
+ PyObject *py_level = PyInt_FromLong(1);
+ if (!py_level)
+ goto bad;
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, py_level, NULL);
+ Py_DECREF(py_level);
+ if (!module) {
+ if (!PyErr_ExceptionMatches(PyExc_ImportError))
+ goto bad;
+ PyErr_Clear();
+ }
+ }
+ level = 0; /* try absolute import on failure */
+ }
+ #endif
+ if (!module) {
+ PyObject *py_level = PyInt_FromLong(level);
+ if (!py_level)
+ goto bad;
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, py_level, NULL);
+ Py_DECREF(py_level);
+ }
+ }
+ #else
+ if (level>0) {
+ PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
+ goto bad;
+ }
+ module = PyObject_CallFunctionObjArgs(py_import,
+ name, global_dict, empty_dict, list, NULL);
+ #endif
+bad:
+ Py_XDECREF(empty_list);
+ Py_XDECREF(py_import);
+ Py_XDECREF(empty_dict);
+ return module;
+}
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
+ const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned char" :
+ "value too large to convert to unsigned char");
+ }
+ return (unsigned char)-1;
+ }
+ return (unsigned char)val;
+ }
+ return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
+ const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned short" :
+ "value too large to convert to unsigned short");
+ }
+ return (unsigned short)-1;
+ }
+ return (unsigned short)val;
+ }
+ return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
+ const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned int" :
+ "value too large to convert to unsigned int");
+ }
+ return (unsigned int)-1;
+ }
+ return (unsigned int)val;
+ }
+ return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
+ const char neg_one = (char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to char" :
+ "value too large to convert to char");
+ }
+ return (char)-1;
+ }
+ return (char)val;
+ }
+ return (char)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
+ const short neg_one = (short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to short" :
+ "value too large to convert to short");
+ }
+ return (short)-1;
+ }
+ return (short)val;
+ }
+ return (short)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
+ const signed char neg_one = (signed char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed char" :
+ "value too large to convert to signed char");
+ }
+ return (signed char)-1;
+ }
+ return (signed char)val;
+ }
+ return (signed char)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
+ const signed short neg_one = (signed short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed short" :
+ "value too large to convert to signed short");
+ }
+ return (signed short)-1;
+ }
+ return (signed short)val;
+ }
+ return (signed short)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
+ const signed int neg_one = (signed int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed int" :
+ "value too large to convert to signed int");
+ }
+ return (signed int)-1;
+ }
+ return (signed int)val;
+ }
+ return (signed int)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
+ const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (unsigned long)PyLong_AsLong(x);
+ }
+ } else {
+ unsigned long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned long)-1;
+ val = __Pyx_PyInt_AsUnsignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
+ const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ unsigned PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
+ const long neg_one = (long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (long)PyLong_AsLong(x);
+ }
+ } else {
+ long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (long)-1;
+ val = __Pyx_PyInt_AsLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
+ const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
+ const signed long neg_one = (signed long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (signed long)PyLong_AsLong(x);
+ }
+ } else {
+ signed long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed long)-1;
+ val = __Pyx_PyInt_AsSignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
+ const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ signed PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsSignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static int __Pyx_check_binary_version(void) {
+ char ctversion[4], rtversion[4];
+ PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+ PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+ if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+ char message[200];
+ PyOS_snprintf(message, sizeof(message),
+ "compiletime version %s of module '%.100s' "
+ "does not match runtime version %s",
+ ctversion, __Pyx_MODULE_NAME, rtversion);
+ #if PY_VERSION_HEX < 0x02050000
+ return PyErr_Warn(NULL, message);
+ #else
+ return PyErr_WarnEx(NULL, message, 1);
+ #endif
+ }
+ return 0;
+}
+
+#ifndef __PYX_HAVE_RT_ImportModule
+#define __PYX_HAVE_RT_ImportModule
+static PyObject *__Pyx_ImportModule(const char *name) {
+ PyObject *py_name = 0;
+ PyObject *py_module = 0;
+ py_name = __Pyx_PyIdentifier_FromString(name);
+ if (!py_name)
+ goto bad;
+ py_module = PyImport_Import(py_name);
+ Py_DECREF(py_name);
+ return py_module;
+bad:
+ Py_XDECREF(py_name);
+ return 0;
+}
+#endif
+
+#ifndef __PYX_HAVE_RT_ImportType
+#define __PYX_HAVE_RT_ImportType
+static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
+ size_t size, int strict)
+{
+ PyObject *py_module = 0;
+ PyObject *result = 0;
+ PyObject *py_name = 0;
+ char warning[200];
+ py_module = __Pyx_ImportModule(module_name);
+ if (!py_module)
+ goto bad;
+ py_name = __Pyx_PyIdentifier_FromString(class_name);
+ if (!py_name)
+ goto bad;
+ result = PyObject_GetAttr(py_module, py_name);
+ Py_DECREF(py_name);
+ py_name = 0;
+ Py_DECREF(py_module);
+ py_module = 0;
+ if (!result)
+ goto bad;
+ if (!PyType_Check(result)) {
+ PyErr_Format(PyExc_TypeError,
+ "%s.%s is not a type object",
+ module_name, class_name);
+ goto bad;
+ }
+ if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) {
+ PyOS_snprintf(warning, sizeof(warning),
+ "%s.%s size changed, may indicate binary incompatibility",
+ module_name, class_name);
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyErr_Warn(NULL, warning) < 0) goto bad;
+ #else
+ if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
+ #endif
+ }
+ else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) {
+ PyErr_Format(PyExc_ValueError,
+ "%s.%s has the wrong size, try recompiling",
+ module_name, class_name);
+ goto bad;
+ }
+ return (PyTypeObject *)result;
+bad:
+ Py_XDECREF(py_module);
+ Py_XDECREF(result);
+ return NULL;
+}
+#endif
+
+static void* __Pyx_GetVtable(PyObject *dict) {
+ void* ptr;
+ PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
+ if (!ob)
+ goto bad;
+#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
+ ptr = PyCapsule_GetPointer(ob, 0);
+#else
+ ptr = PyCObject_AsVoidPtr(ob);
+#endif
+ if (!ptr && !PyErr_Occurred())
+ PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
+ Py_DECREF(ob);
+ return ptr;
+bad:
+ Py_XDECREF(ob);
+ return NULL;
+}
+
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+ int start = 0, mid = 0, end = count - 1;
+ if (end >= 0 && code_line > entries[end].code_line) {
+ return count;
+ }
+ while (start < end) {
+ mid = (start + end) / 2;
+ if (code_line < entries[mid].code_line) {
+ end = mid;
+ } else if (code_line > entries[mid].code_line) {
+ start = mid + 1;
+ } else {
+ return mid;
+ }
+ }
+ if (code_line <= entries[mid].code_line) {
+ return mid;
+ } else {
+ return mid + 1;
+ }
+}
+static PyCodeObject *__pyx_find_code_object(int code_line) {
+ PyCodeObject* code_object;
+ int pos;
+ if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
+ return NULL;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
+ return NULL;
+ }
+ code_object = __pyx_code_cache.entries[pos].code_object;
+ Py_INCREF(code_object);
+ return code_object;
+}
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
+ int pos, i;
+ __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
+ if (unlikely(!code_line)) {
+ return;
+ }
+ if (unlikely(!entries)) {
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (likely(entries)) {
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = 64;
+ __pyx_code_cache.count = 1;
+ entries[0].code_line = code_line;
+ entries[0].code_object = code_object;
+ Py_INCREF(code_object);
+ }
+ return;
+ }
+ pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+ if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
+ PyCodeObject* tmp = entries[pos].code_object;
+ entries[pos].code_object = code_object;
+ Py_DECREF(tmp);
+ return;
+ }
+ if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
+ int new_max = __pyx_code_cache.max_count + 64;
+ entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
+ __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
+ if (unlikely(!entries)) {
+ return;
+ }
+ __pyx_code_cache.entries = entries;
+ __pyx_code_cache.max_count = new_max;
+ }
+ for (i=__pyx_code_cache.count; i>pos; i--) {
+ entries[i] = entries[i-1];
+ }
+ entries[pos].code_line = code_line;
+ entries[pos].code_object = code_object;
+ __pyx_code_cache.count++;
+ Py_INCREF(code_object);
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
+ const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ #if PY_MAJOR_VERSION < 3
+ py_srcfile = PyString_FromString(filename);
+ #else
+ py_srcfile = PyUnicode_FromString(filename);
+ #endif
+ if (!py_srcfile) goto bad;
+ if (c_line) {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #else
+ py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+ #endif
+ }
+ else {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromString(funcname);
+ #else
+ py_funcname = PyUnicode_FromString(funcname);
+ #endif
+ }
+ if (!py_funcname) goto bad;
+ py_code = __Pyx_PyCode_New(
+ 0, /*int argcount,*/
+ 0, /*int kwonlyargcount,*/
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ __pyx_empty_bytes, /*PyObject *code,*/
+ __pyx_empty_tuple, /*PyObject *consts,*/
+ __pyx_empty_tuple, /*PyObject *names,*/
+ __pyx_empty_tuple, /*PyObject *varnames,*/
+ __pyx_empty_tuple, /*PyObject *freevars,*/
+ __pyx_empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ py_line, /*int firstlineno,*/
+ __pyx_empty_bytes /*PyObject *lnotab*/
+ );
+ Py_DECREF(py_srcfile);
+ Py_DECREF(py_funcname);
+ return py_code;
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ return NULL;
+}
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+ int py_line, const char *filename) {
+ PyCodeObject *py_code = 0;
+ PyObject *py_globals = 0;
+ PyFrameObject *py_frame = 0;
+ py_code = __pyx_find_code_object(c_line ? c_line : py_line);
+ if (!py_code) {
+ py_code = __Pyx_CreateCodeObjectForTraceback(
+ funcname, c_line, py_line, filename);
+ if (!py_code) goto bad;
+ __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
+ }
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_GET(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = py_line;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+ while (t->p) {
+ #if PY_MAJOR_VERSION < 3
+ if (t->is_unicode) {
+ *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+ } else if (t->intern) {
+ *t->p = PyString_InternFromString(t->s);
+ } else {
+ *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+ }
+ #else /* Python 3+ has unicode identifiers */
+ if (t->is_unicode | t->is_str) {
+ if (t->intern) {
+ *t->p = PyUnicode_InternFromString(t->s);
+ } else if (t->encoding) {
+ *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+ } else {
+ *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+ }
+ } else {
+ *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+ }
+ #endif
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+
+/* Type Conversion Functions */
+
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+ int is_true = x == Py_True;
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+ else return PyObject_IsTrue(x);
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
+ PyNumberMethods *m;
+ const char *name = NULL;
+ PyObject *res = NULL;
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_Check(x) || PyLong_Check(x))
+#else
+ if (PyLong_Check(x))
+#endif
+ return Py_INCREF(x), x;
+ m = Py_TYPE(x)->tp_as_number;
+#if PY_VERSION_HEX < 0x03000000
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Int(x);
+ }
+ else if (m && m->nb_long) {
+ name = "long";
+ res = PyNumber_Long(x);
+ }
+#else
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Long(x);
+ }
+#endif
+ if (res) {
+#if PY_VERSION_HEX < 0x03000000
+ if (!PyInt_Check(res) && !PyLong_Check(res)) {
+#else
+ if (!PyLong_Check(res)) {
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "__%s__ returned non-%s (type %.200s)",
+ name, name, Py_TYPE(res)->tp_name);
+ Py_DECREF(res);
+ return NULL;
+ }
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "an integer is required");
+ }
+ return res;
+}
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+ Py_ssize_t ival;
+ PyObject* x = PyNumber_Index(b);
+ if (!x) return -1;
+ ival = PyInt_AsSsize_t(x);
+ Py_DECREF(x);
+ return ival;
+}
+
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+#if PY_VERSION_HEX < 0x02050000
+ if (ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ else {
+ unsigned char *bytes = (unsigned char *) &ival;
+ int one = 1; int little = (int)*(unsigned char*)&one;
+ return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
+ }
+#else
+ return PyInt_FromSize_t(ival);
+#endif
+}
+
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
+ unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
+ if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
+ return (size_t)-1;
+ } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "value too large to convert to size_t");
+ return (size_t)-1;
+ }
+ return (size_t)val;
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/chromium/third_party/bintrees/bintrees/qrbtree.pyx b/chromium/third_party/bintrees/bintrees/qrbtree.pyx
new file mode 100644
index 00000000000..f7f1dcfdf59
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/qrbtree.pyx
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: cython unbalanced binary tree module
+# Created: 28.04.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+__all__ = ['cRBTree']
+
+from cwalker import cWalker
+
+from cwalker cimport *
+from ctrees cimport *
+
+cdef class cRBTree:
+ cdef node_t *_root
+ cdef int _count
+
+ def __cinit__(self, items=None):
+ self._root = NULL
+ self._count = 0
+ if items:
+ self.update(items)
+
+ def __dealloc__(self):
+ ct_delete_tree(self._root)
+
+ @property
+ def count(self):
+ return self._count
+
+ def __getstate__(self):
+ return dict(self.items())
+
+ def __setstate__(self, state):
+ self.update(state)
+
+ def clear(self):
+ ct_delete_tree(self._root)
+ self._count = 0
+ self._root = NULL
+
+ def get_value(self, key):
+ result = <object> ct_get_item(self._root, key)
+ if result is None:
+ raise KeyError(key)
+ else:
+ return result[1]
+
+ def get_walker(self):
+ cdef cWalker walker
+ walker = cWalker()
+ walker.set_tree(self._root)
+ return walker
+
+ def insert(self, key, value):
+ res = rb_insert(&self._root, key, value)
+ if res < 0:
+ raise MemoryError('Can not allocate memory for node structure.')
+ else:
+ self._count += res
+
+ def remove(self, key):
+ cdef int result
+ result = rb_remove(&self._root, key)
+ if result == 0:
+ raise KeyError(str(key))
+ else:
+ self._count -= 1
+
+ def max_item(self):
+ """ Get item with max key of tree, raises ValueError if tree is empty. """
+ cdef node_t *node
+ node = ct_max_node(self._root)
+ if node == NULL: # root is None
+ raise ValueError("Tree is empty")
+ return (<object>node.key, <object>node.value)
+
+ def min_item(self):
+ """ Get item with min key of tree, raises ValueError if tree is empty. """
+ cdef node_t *node
+ node = ct_min_node(self._root)
+ if node == NULL: # root is None
+ raise ValueError("Tree is empty")
+ return (<object>node.key, <object>node.value)
diff --git a/chromium/third_party/bintrees/bintrees/rbtree.py b/chromium/third_party/bintrees/bintrees/rbtree.py
new file mode 100644
index 00000000000..dedd2bce403
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/rbtree.py
@@ -0,0 +1,268 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman (python version)
+# Purpose: red-black tree module (Julienne Walker's none recursive algorithm)
+# source: http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx
+# Created: 01.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+# Conclusion of Julian Walker
+
+# Red black trees are interesting beasts. They're believed to be simpler than
+# AVL trees (their direct competitor), and at first glance this seems to be the
+# case because insertion is a breeze. However, when one begins to play with the
+# deletion algorithm, red black trees become very tricky. However, the
+# counterweight to this added complexity is that both insertion and deletion
+# can be implemented using a single pass, top-down algorithm. Such is not the
+# case with AVL trees, where only the insertion algorithm can be written top-down.
+# Deletion from an AVL tree requires a bottom-up algorithm.
+
+# So when do you use a red black tree? That's really your decision, but I've
+# found that red black trees are best suited to largely random data that has
+# occasional degenerate runs, and searches have no locality of reference. This
+# takes full advantage of the minimal work that red black trees perform to
+# maintain balance compared to AVL trees and still allows for speedy searches.
+
+# Red black trees are popular, as most data structures with a whimsical name.
+# For example, in Java and C++, the library map structures are typically
+# implemented with a red black tree. Red black trees are also comparable in
+# speed to AVL trees. While the balance is not quite as good, the work it takes
+# to maintain balance is usually better in a red black tree. There are a few
+# misconceptions floating around, but for the most part the hype about red black
+# trees is accurate.
+
+from __future__ import absolute_import
+
+from .treemixin import TreeMixin
+
+__all__ = ['RBTree']
+
+
+class Node(object):
+ """ Internal object, represents a treenode """
+ __slots__ = ['key', 'value', 'red', 'left', 'right']
+
+ def __init__(self, key=None, value=None):
+ self.key = key
+ self.value = value
+ self.red = True
+ self.left = None
+ self.right = None
+
+ def free(self):
+ self.left = None
+ self.right = None
+ self.key = None
+ self.value = None
+
+ def __getitem__(self, key):
+ """ x.__getitem__(key) <==> x[key], where key is 0 (left) or 1 (right) """
+ return self.left if key == 0 else self.right
+
+ def __setitem__(self, key, value):
+ """ x.__setitem__(key, value) <==> x[key]=value, where key is 0 (left) or 1 (right) """
+ if key == 0:
+ self.left = value
+ else:
+ self.right = value
+
+
+def is_red(node):
+ if (node is not None) and node.red:
+ return True
+ else:
+ return False
+
+
+def jsw_single(root, direction):
+ other_side = 1 - direction
+ save = root[other_side]
+ root[other_side] = save[direction]
+ save[direction] = root
+ root.red = True
+ save.red = False
+ return save
+
+
+def jsw_double(root, direction):
+ other_side = 1 - direction
+ root[other_side] = jsw_single(root[other_side], other_side)
+ return jsw_single(root, direction)
+
+
+class RBTree(TreeMixin):
+ """
+ RBTree implements a balanced binary tree with a dict-like interface.
+
+ see: http://en.wikipedia.org/wiki/Red_black_tree
+
+ A red-black tree is a type of self-balancing binary search tree, a data
+ structure used in computing science, typically used to implement associative
+ arrays. The original structure was invented in 1972 by Rudolf Bayer, who
+ called them "symmetric binary B-trees", but acquired its modern name in a
+ paper in 1978 by Leonidas J. Guibas and Robert Sedgewick. It is complex,
+ but has good worst-case running time for its operations and is efficient in
+ practice: it can search, insert, and delete in O(log n) time, where n is
+ total number of elements in the tree. Put very simply, a red-black tree is a
+ binary search tree which inserts and removes intelligently, to ensure the
+ tree is reasonably balanced.
+
+ RBTree() -> new empty tree.
+ RBTree(mapping) -> new tree initialized from a mapping
+ RBTree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)]
+
+ see also TreeMixin() class.
+
+ """
+ def __init__(self, items=None):
+ """ x.__init__(...) initializes x; see x.__class__.__doc__ for signature """
+ self._root = None
+ self._count = 0
+ if items is not None:
+ self.update(items)
+
+ def clear(self):
+ """ T.clear() -> None. Remove all items from T. """
+ def _clear(node):
+ if node is not None:
+ _clear(node.left)
+ _clear(node.right)
+ node.free()
+ _clear(self._root)
+ self._count = 0
+ self._root = None
+
+ @property
+ def count(self):
+ """ count of items """
+ return self._count
+
+ @property
+ def root(self):
+ """ root node of T """
+ return self._root
+
+ def _new_node(self, key, value):
+ """ Create a new treenode """
+ self._count += 1
+ return Node(key, value)
+
+ def insert(self, key, value):
+ """ T.insert(key, value) <==> T[key] = value, insert key, value into Tree """
+ if self._root is None: # Empty tree case
+ self._root = self._new_node(key, value)
+ self._root.red = False # make root black
+ return
+
+ head = Node() # False tree root
+ grand_parent = None
+ grand_grand_parent = head
+ parent = None # parent
+ direction = 0
+ last = 0
+
+ # Set up helpers
+ grand_grand_parent.right = self._root
+ node = grand_grand_parent.right
+ # Search down the tree
+ while True:
+ if node is None: # Insert new node at the bottom
+ node = self._new_node(key, value)
+ parent[direction] = node
+ elif is_red(node.left) and is_red(node.right): # Color flip
+ node.red = True
+ node.left.red = False
+ node.right.red = False
+
+ # Fix red violation
+ if is_red(node) and is_red(parent):
+ direction2 = 1 if grand_grand_parent.right is grand_parent else 0
+ if node is parent[last]:
+ grand_grand_parent[direction2] = jsw_single(grand_parent, 1 - last)
+ else:
+ grand_grand_parent[direction2] = jsw_double(grand_parent, 1 - last)
+
+ # Stop if found
+ if key == node.key:
+ node.value = value # set new value for key
+ break
+
+ last = direction
+ direction = 0 if key < node.key else 1
+ # Update helpers
+ if grand_parent is not None:
+ grand_grand_parent = grand_parent
+ grand_parent = parent
+ parent = node
+ node = node[direction]
+
+ self._root = head.right # Update root
+ self._root.red = False # make root black
+
+ def remove(self, key):
+ """ T.remove(key) <==> del T[key], remove item <key> from tree """
+ if self._root is None:
+ raise KeyError(str(key))
+ head = Node() # False tree root
+ node = head
+ node.right = self._root
+ parent = None
+ grand_parent = None
+ found = None # Found item
+ direction = 1
+
+ # Search and push a red down
+ while node[direction] is not None:
+ last = direction
+
+ # Update helpers
+ grand_parent = parent
+ parent = node
+ node = node[direction]
+
+ direction = 1 if key > node.key else 0
+
+ # Save found node
+ if key == node.key:
+ found = node
+
+ # Push the red node down
+ if not is_red(node) and not is_red(node[direction]):
+ if is_red(node[1 - direction]):
+ parent[last] = jsw_single(node, direction)
+ parent = parent[last]
+ elif not is_red(node[1 - direction]):
+ sibling = parent[1 - last]
+ if sibling is not None:
+ if (not is_red(sibling[1 - last])) and (not is_red(sibling[last])):
+ # Color flip
+ parent.red = False
+ sibling.red = True
+ node.red = True
+ else:
+ direction2 = 1 if grand_parent.right is parent else 0
+ if is_red(sibling[last]):
+ grand_parent[direction2] = jsw_double(parent, last)
+ elif is_red(sibling[1-last]):
+ grand_parent[direction2] = jsw_single(parent, last)
+ # Ensure correct coloring
+ grand_parent[direction2].red = True
+ node.red = True
+ grand_parent[direction2].left.red = False
+ grand_parent[direction2].right.red = False
+
+ # Replace and remove if found
+ if found is not None:
+ found.key = node.key
+ found.value = node.value
+ parent[int(parent.right is node)] = node[int(node.left is None)]
+ node.free()
+ self._count -= 1
+
+ # Update root and make it black
+ self._root = head.right
+ if self._root is not None:
+ self._root.red = False
+ if not found:
+ raise KeyError(str(key)) \ No newline at end of file
diff --git a/chromium/third_party/bintrees/bintrees/stack.c b/chromium/third_party/bintrees/bintrees/stack.c
new file mode 100644
index 00000000000..cb308f8c51d
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/stack.c
@@ -0,0 +1,58 @@
+/*
+ * stack.c
+ *
+ * Author: mozman
+ * Copyright (c) 2010-2013 by Manfred Moitzi
+ * License: MIT-License
+ */
+
+#include "ctrees.h"
+#include "stack.h"
+
+extern node_stack_t *
+stack_init(int size)
+{
+ node_stack_t *stack;
+
+ stack = PyMem_Malloc(sizeof(node_stack_t));
+ stack->stack = PyMem_Malloc(sizeof(node_t *) * size);
+ stack->size = size;
+ stack->stackptr = 0;
+ return stack;
+}
+
+extern void
+stack_delete(node_stack_t *stack)
+{
+ PyMem_Free(stack->stack);
+ PyMem_Free(stack);
+}
+
+extern void
+stack_push(node_stack_t *stack, node_t *node)
+{
+ stack->stack[stack->stackptr++] = node;
+ if (stack->stackptr >= stack->size) {
+ stack->size *= 2;
+ stack->stack = PyMem_Realloc(stack->stack,
+ sizeof(node_t *) * stack->size);
+ }
+}
+
+extern node_t *
+stack_pop(node_stack_t *stack)
+{
+ return (stack->stackptr > 0) ? stack->stack[--stack->stackptr] : NULL;
+}
+
+extern int
+stack_is_empty(node_stack_t *stack)
+{
+ return (stack->stackptr == 0);
+}
+
+extern void
+stack_reset(node_stack_t *stack)
+{
+ stack->stackptr = 0;
+}
diff --git a/chromium/third_party/bintrees/bintrees/stack.h b/chromium/third_party/bintrees/bintrees/stack.h
new file mode 100644
index 00000000000..138f5ed0363
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/stack.h
@@ -0,0 +1,28 @@
+/*
+ * stack.h
+ *
+ * Author: mozman
+ * Copyright (c) 2010-2013 by Manfred Moitzi
+ * License: MIT-License
+ */
+
+#ifndef STACK_H_
+#define STACK_H_
+
+#include "ctrees.h"
+
+typedef struct node_stack node_stack_t;
+struct node_stack {
+ int stackptr;
+ int size;
+ node_t **stack;
+};
+
+node_stack_t *stack_init(int size);
+void stack_delete(node_stack_t *stack);
+void stack_push(node_stack_t *stack, node_t *node);
+node_t *stack_pop(node_stack_t *stack);
+int stack_is_empty(node_stack_t *stack);
+void stack_reset(node_stack_t *stack);
+
+#endif /* STACK_H_ */
diff --git a/chromium/third_party/bintrees/bintrees/stack.pxd b/chromium/third_party/bintrees/bintrees/stack.pxd
new file mode 100644
index 00000000000..7b4efd73f05
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/stack.pxd
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Created: 08.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT-License
+
+from ctrees cimport node_t
+
+cdef extern from "stack.h":
+ ctypedef struct node_stack_t:
+ pass
+ node_stack_t *stack_init(int size)
+ void stack_delete(node_stack_t *stack)
+ void stack_push(node_stack_t *stack, node_t *node)
+ node_t *stack_pop(node_stack_t *stack)
+ int stack_is_empty(node_stack_t *stack)
+ void stack_reset(node_stack_t *stack)
diff --git a/chromium/third_party/bintrees/bintrees/treemixin.py b/chromium/third_party/bintrees/bintrees/treemixin.py
new file mode 100644
index 00000000000..805ad95b361
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/treemixin.py
@@ -0,0 +1,642 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: Mozman
+# Purpose: treemixin provides top level functions for binary trees
+# Created: 03.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+from __future__ import absolute_import
+
+from .walker import Walker
+from .treeslice import TreeSlice
+
+class TreeMixin(object):
+ """
+ Abstract-Base-Class for the pure Python Trees: BinaryTree, AVLTree and RBTree
+ Mixin-Class for the Cython based Trees: FastBinaryTree, FastAVLTree, FastRBTree
+
+ The TreeMixin Class
+ ===================
+
+ T has to implement following properties
+ ---------------------------------------
+
+ count -- get node count
+
+ T has to implement following methods
+ ------------------------------------
+
+ get_walker(...)
+ get a tree walker object, provides methods to traverse the tree see walker.py
+
+ insert(...)
+ insert(key, value) <==> T[key] = value, insert key into T
+
+ remove(...)
+ remove(key) <==> del T[key], remove key from T
+
+ clear(...)
+ T.clear() -> None. Remove all items from T.
+
+ Methods defined here
+ --------------------
+
+ * __contains__(k) -> True if T has a key k, else False, O(log(n))
+ * __delitem__(y) <==> del T[y], del T[s:e], O(log(n))
+ * __getitem__(y) <==> T[y], T[s:e], O(log(n))
+ * __iter__() <==> iter(T)
+ * __len__() <==> len(T), O(1)
+ * __max__() <==> max(T), get max item (k,v) of T, O(log(n))
+ * __min__() <==> min(T), get min item (k,v) of T, O(log(n))
+ * __and__(other) <==> T & other, intersection
+ * __or__(other) <==> T | other, union
+ * __sub__(other) <==> T - other, difference
+ * __xor__(other) <==> T ^ other, symmetric_difference
+ * __repr__() <==> repr(T)
+ * __setitem__(k, v) <==> T[k] = v, O(log(n))
+ * clear() -> None, Remove all items from T, , O(n)
+ * copy() -> a shallow copy of T, O(n*log(n))
+ * discard(k) -> None, remove k from T, if k is present, O(log(n))
+ * get(k[,d]) -> T[k] if k in T, else d, O(log(n))
+ * is_empty() -> True if len(T) == 0, O(1)
+ * items([reverse]) -> generator for (k, v) items of T, O(n)
+ * keys([reverse]) -> generator for keys of T, O(n)
+ * values([reverse]) -> generator for values of T, O(n)
+ * pop(k[,d]) -> v, remove specified key and return the corresponding value, O(log(n))
+ * popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple, O(log(n))
+ * setdefault(k[,d]) -> T.get(k, d), also set T[k]=d if k not in T, O(log(n))
+ * update(E) -> None. Update T from dict/iterable E, O(E*log(n))
+ * foreach(f, [order]) -> visit all nodes of tree and call f(k, v) for each node, O(n)
+
+ slicing by keys
+
+ * itemslice(s, e) -> generator for (k, v) items of T for s <= key < e, O(n)
+ * keyslice(s, e) -> generator for keys of T for s <= key < e, O(n)
+ * valueslice(s, e) -> generator for values of T for s <= key < e, O(n)
+ * T[s:e] -> TreeSlice object, with keys in range s <= key < e, O(n)
+ * del T[s:e] -> remove items by key slicing, for s <= key < e, O(n)
+
+ if 's' is None or T[:e] TreeSlice/iterator starts with value of min_key()
+ if 'e' is None or T[s:] TreeSlice/iterator ends with value of max_key()
+ T[:] is a TreeSlice which represents the whole tree.
+
+ TreeSlice is a tree wrapper with range check, and contains no references
+ to objects, deleting objects in the associated tree also deletes the object
+ in the TreeSlice.
+
+ * TreeSlice[k] -> get value for key k, raises KeyError if k not exists in range s:e
+ * TreeSlice[s1:e1] -> TreeSlice object, with keys in range s1 <= key < e1
+
+ * new lower bound is max(s, s1)
+ * new upper bound is min(e, e1)
+
+ TreeSlice methods:
+
+ * items() -> generator for (k, v) items of T, O(n)
+ * keys() -> generator for keys of T, O(n)
+ * values() -> generator for values of T, O(n)
+ * __iter__ <==> keys()
+ * __repr__ <==> repr(T)
+ * __contains__(key)-> True if TreeSlice has a key k, else False, O(log(n))
+
+ prev/succ operations
+
+ * prev_item(key) -> get (k, v) pair, where k is predecessor to key, O(log(n))
+ * prev_key(key) -> k, get the predecessor of key, O(log(n))
+ * succ_item(key) -> get (k,v) pair as a 2-tuple, where k is successor to key, O(log(n))
+ * succ_key(key) -> k, get the successor of key, O(log(n))
+ * floor_item(key) -> get (k, v) pair, where k is the greatest key less than or equal to key, O(log(n))
+ * floor_key(key) -> k, get the greatest key less than or equal to key, O(log(n))
+ * ceiling_item(key) -> get (k, v) pair, where k is the smallest key greater than or equal to key, O(log(n))
+ * ceiling_key(key) -> k, get the smallest key greater than or equal to key, O(log(n))
+
+ Heap methods
+
+ * max_item() -> get largest (key, value) pair of T, O(log(n))
+ * max_key() -> get largest key of T, O(log(n))
+ * min_item() -> get smallest (key, value) pair of T, O(log(n))
+ * min_key() -> get smallest key of T, O(log(n))
+ * pop_min() -> (k, v), remove item with minimum key, O(log(n))
+ * pop_max() -> (k, v), remove item with maximum key, O(log(n))
+ * nlargest(i[,pop]) -> get list of i largest items (k, v), O(i*log(n))
+ * nsmallest(i[,pop]) -> get list of i smallest items (k, v), O(i*log(n))
+
+ Set methods (using frozenset)
+
+ * intersection(t1, t2, ...) -> Tree with keys *common* to all trees
+ * union(t1, t2, ...) -> Tree with keys from *either* trees
+ * difference(t1, t2, ...) -> Tree with keys in T but not any of t1, t2, ...
+ * symmetric_difference(t1) -> Tree with keys in either T and t1 but not both
+ * issubset(S) -> True if every element in T is in S
+ * issuperset(S) -> True if every element in S is in T
+ * isdisjoint(S) -> True if T has a null intersection with S
+
+ Classmethods
+
+ * fromkeys(S[,v]) -> New tree with keys from S and values equal to v.
+
+ """
+ def get_walker(self):
+ return Walker(self)
+
+ def __repr__(self):
+ """ x.__repr__(...) <==> repr(x) """
+ tpl = "%s({%s})" % (self.__class__.__name__, '%s')
+ return tpl % ", ".join( ("%r: %r" % item for item in self.items()) )
+
+ def copy(self):
+ """ T.copy() -> get a shallow copy of T. """
+ tree = self.__class__()
+ self.foreach(tree.insert, order=-1)
+ return tree
+ __copy__ = copy
+
+ def __contains__(self, key):
+ """ k in T -> True if T has a key k, else False """
+ try:
+ self.get_value(key)
+ return True
+ except KeyError:
+ return False
+
+ def __len__(self):
+ """ x.__len__() <==> len(x) """
+ return self.count
+
+ def __min__(self):
+ """ x.__min__() <==> min(x) """
+ return self.min_item()
+
+ def __max__(self):
+ """ x.__max__() <==> max(x) """
+ return self.max_item()
+
+ def __and__(self, other):
+ """ x.__and__(other) <==> self & other """
+ return self.intersection(other)
+
+ def __or__(self, other):
+ """ x.__or__(other) <==> self | other """
+ return self.union(other)
+
+ def __sub__(self, other):
+ """ x.__sub__(other) <==> self - other """
+ return self.difference(other)
+
+ def __xor__(self, other):
+ """ x.__xor__(other) <==> self ^ other """
+ return self.symmetric_difference(other)
+
+ def discard(self, key):
+ """ x.discard(k) -> None, remove k from T, if k is present """
+ try:
+ self.remove(key)
+ except KeyError:
+ pass
+
+ def __del__(self):
+ self.clear()
+
+ def is_empty(self):
+ """ x.is_empty() -> False if T contains any items else True"""
+ return self.count == 0
+
+ def keys(self, reverse=False):
+ """ T.iterkeys([reverse]) -> an iterator over the keys of T, in ascending
+ order if reverse is True, iterate in descending order, reverse defaults
+ to False
+ """
+ return ( item[0] for item in self.items(reverse) )
+ __iter__ = keys
+
+ def __reversed__(self):
+ return self.keys(reverse=True)
+
+ def values(self, reverse=False):
+ """ T.values([reverse]) -> an iterator over the values of T, in ascending order
+ if reverse is True, iterate in descending order, reverse defaults to False
+ """
+ return ( item[1] for item in self.items(reverse) )
+
+ def items(self, reverse=False):
+ """ T.items([reverse]) -> an iterator over the (key, value) items of T,
+ in ascending order if reverse is True, iterate in descending order,
+ reverse defaults to False
+ """
+ if self.is_empty():
+ return []
+
+ def default_iterator(node):
+ direction = 1 if reverse else 0
+ other = 1 - direction
+ go_down = True
+ while True:
+ if node.has_child(direction) and go_down:
+ node.push()
+ node.down(direction)
+ else:
+ yield node.item
+ if node.has_child(other):
+ node.down(other)
+ go_down = True
+ else:
+ if node.stack_is_empty():
+ return # all done
+ node.pop()
+ go_down = False
+
+ treewalker = self.get_walker()
+ try: # specialized iterators
+ if reverse:
+ return treewalker.iter_items_backward()
+ else:
+ return treewalker.iter_items_forward()
+ except AttributeError:
+ return default_iterator(treewalker)
+
+ def __getitem__(self, key):
+ """ x.__getitem__(y) <==> x[y] """
+ if isinstance(key, slice):
+ return TreeSlice(self, key.start, key.stop)
+ else:
+ return self.get_value(key)
+
+ def __setitem__(self, key, value):
+ """ x.__setitem__(i, y) <==> x[i]=y """
+ if isinstance(key, slice):
+ raise ValueError('setslice is not supported')
+ self.insert(key, value)
+
+ def __delitem__(self, key):
+ """ x.__delitem__(y) <==> del x[y] """
+ if isinstance(key, slice):
+ self.delitems(self.keyslice(key.start, key.stop))
+ else:
+ self.remove(key)
+
+ def delitems(self, keys):
+ """ T.delitems(keys) -> remove all items by keys
+ """
+ # convert generator to a set, because the content of the
+ # tree will be modified!
+ for key in frozenset(keys):
+ self.remove(key)
+
+ def keyslice(self, startkey, endkey):
+ """ T.keyslice(startkey, endkey) -> key iterator:
+ startkey <= key < endkey.
+ """
+ return ( item[0] for item in self.itemslice(startkey, endkey) )
+
+ def itemslice(self, startkey, endkey):
+ """ T.itemslice(s, e) -> item iterator: s <= key < e.
+
+ if s is None: start with min element -> T[:e]
+ if e is None: end with max element -> T[s:]
+ T[:] -> all items
+
+ """
+ if self.is_empty():
+ return
+
+ if startkey is None:
+ # no lower bound
+ can_go_left = lambda: node.has_left() and visit_left
+ else:
+ # don't visit subtrees without keys in search range
+ can_go_left = lambda: node.key > startkey and node.has_left() and visit_left
+
+ if endkey is None:
+ # no upper bound
+ can_go_right = lambda: node.has_right()
+ else:
+ # don't visit subtrees without keys in search range
+ can_go_right = lambda: node.key < endkey and node.has_right()
+
+ if (startkey, endkey) == (None, None):
+ key_in_range = lambda: True
+ elif startkey is None:
+ key_in_range = lambda: node.key < endkey
+ elif endkey is None:
+ key_in_range = lambda: node.key >= startkey
+ else:
+ key_in_range = lambda: startkey <= node.key < endkey
+
+ node = self.get_walker()
+ visit_left = True
+ while True:
+ if can_go_left():
+ node.push()
+ node.go_left()
+ else:
+ if key_in_range():
+ yield node.item
+ if can_go_right():
+ node.go_right()
+ visit_left = True
+ else:
+ if node.stack_is_empty():
+ return
+ node.pop()
+ # left side is already done
+ visit_left = False
+
+ def valueslice(self, startkey, endkey):
+ """ T.valueslice(startkey, endkey) -> value iterator:
+ startkey <= key < endkey.
+ """
+ return ( item[1] for item in self.itemslice(startkey, endkey) )
+
+ def get_value(self, key):
+ node = self.root
+ while node is not None:
+ if key == node.key:
+ return node.value
+ elif key < node.key:
+ node = node.left
+ else:
+ node = node.right
+ raise KeyError(str(key))
+
+ def __getstate__(self):
+ return dict(self.items())
+
+ def __setstate__(self, state):
+ # note for myself: this is called like __init__, so don't use clear()
+ # to remove existing data!
+ self._root = None
+ self._count = 0
+ self.update(state)
+
+ def setdefault(self, key, default=None):
+ """ T.setdefault(k[,d]) -> T.get(k,d), also set T[k]=d if k not in T """
+ try:
+ return self.get_value(key)
+ except KeyError:
+ self.insert(key, default)
+ return default
+
+ def update(self, *args):
+ """ T.update(E) -> None. Update T from E : for (k, v) in E: T[k] = v """
+ for items in args:
+ try:
+ generator = items.items()
+ except AttributeError:
+ generator = iter(items)
+
+ for key, value in generator:
+ self.insert(key, value)
+
+ @classmethod
+ def fromkeys(cls, iterable, value=None):
+ """ T.fromkeys(S[,v]) -> New tree with keys from S and values equal to v.
+
+ v defaults to None.
+ """
+ tree = cls()
+ for key in iterable:
+ tree.insert(key, value)
+ return tree
+
+ def get(self, key, default=None):
+ """ T.get(k[,d]) -> T[k] if k in T, else d. d defaults to None. """
+ try:
+ return self.get_value(key)
+ except KeyError:
+ return default
+
+ def pop(self, key, *args):
+ """ T.pop(k[,d]) -> v, remove specified key and return the corresponding value
+ If key is not found, d is returned if given, otherwise KeyError is raised
+ """
+ if len(args) > 1:
+ raise TypeError("pop expected at most 2 arguments, got %d" % (1 + len(args)))
+ try:
+ value = self.get_value(key)
+ self.remove(key)
+ return value
+ except KeyError:
+ if len(args) == 0:
+ raise
+ else:
+ return args[0]
+
+ def popitem(self):
+ """ T.popitem() -> (k, v), remove and return some (key, value) pair as a
+ 2-tuple; but raise KeyError if T is empty
+ """
+ if self.is_empty():
+ raise KeyError("popitem(): tree is empty")
+ walker = self.get_walker()
+ walker.goto_leaf()
+ result = walker.item
+ self.remove(walker.key)
+ return result
+
+ def foreach(self, func, order=0):
+ """ Visit all tree nodes and process key, value.
+
+ parm func: function(key, value)
+ param int order: inorder = 0, preorder = -1, postorder = +1
+
+ """
+ def _traverse():
+ if order == -1:
+ func(node.key, node.value)
+ if node.has_left():
+ node.push()
+ node.go_left()
+ _traverse()
+ node.pop()
+ if order == 0:
+ func(node.key, node.value)
+ if node.has_right():
+ node.push()
+ node.go_right()
+ _traverse()
+ node.pop()
+ if order == +1:
+ func(node.key, node.value)
+
+ node = self.get_walker()
+ _traverse()
+
+ def min_item(self):
+ """ Get item with min key of tree, raises ValueError if tree is empty. """
+ if self.count == 0:
+ raise ValueError("Tree is empty")
+ node = self._root
+ while node.left is not None:
+ node = node.left
+ return (node.key, node.value)
+
+ def pop_min(self):
+ """ T.pop_min() -> (k, v), remove item with minimum key, raise ValueError
+ if T is empty.
+ """
+ item = self.min_item()
+ self.remove(item[0])
+ return item
+
+ def min_key(self):
+ """ Get min key of tree, raises ValueError if tree is empty. """
+ key, value = self.min_item()
+ return key
+
+ def prev_item(self, key):
+ """ Get predecessor (k,v) pair of key, raises KeyError if key is min key
+ or key does not exist.
+ """
+ if self.count == 0:
+ raise KeyError("Tree is empty")
+ walker = self.get_walker()
+ return walker.prev_item(key)
+
+ def succ_item(self, key):
+ """ Get successor (k,v) pair of key, raises KeyError if key is max key
+ or key does not exist.
+ """
+ if self.count == 0:
+ raise KeyError("Tree is empty")
+ walker = self.get_walker()
+ return walker.succ_item(key)
+
+ def prev_key(self, key):
+ """ Get predecessor to key, raises KeyError if key is min key
+ or key does not exist.
+ """
+ key, value = self.prev_item(key)
+ return key
+
+ def succ_key(self, key):
+ """ Get successor to key, raises KeyError if key is max key
+ or key does not exist.
+ """
+ key, value = self.succ_item(key)
+ return key
+
+ def floor_item(self, key):
+ """ Get the element (k,v) pair associated with the greatest key less
+ than or equal to the given key, raises KeyError if there is no such key.
+ """
+ if self.count == 0:
+ raise KeyError("Tree is empty")
+ walker = self.get_walker()
+ return walker.floor_item(key)
+
+ def floor_key(self, key):
+ """ Get the greatest key less than or equal to the given key, raises
+ KeyError if there is no such key.
+ """
+ key, value = self.floor_item(key)
+ return key
+
+ def ceiling_item(self, key):
+ """ Get the element (k,v) pair associated with the smallest key greater
+ than or equal to the given key, raises KeyError if there is no such key.
+ """
+ if self.count == 0:
+ raise KeyError("Tree is empty")
+ walker = self.get_walker()
+ return walker.ceiling_item(key)
+
+ def ceiling_key(self, key):
+ """ Get the smallest key greater than or equal to the given key, raises
+ KeyError if there is no such key.
+ """
+ key, value = self.ceiling_item(key)
+ return key
+
+ def max_item(self):
+ """ Get item with max key of tree, raises ValueError if tree is empty. """
+ if self.count == 0:
+ raise ValueError("Tree is empty")
+ node = self._root
+ while node.right is not None:
+ node = node.right
+ return (node.key, node.value)
+
+ def pop_max(self):
+ """ T.pop_max() -> (k, v), remove item with maximum key, raise ValueError
+ if T is empty.
+ """
+ item = self.max_item()
+ self.remove(item[0])
+ return item
+
+ def max_key(self):
+ """ Get max key of tree, raises ValueError if tree is empty. """
+ key, value = self.max_item()
+ return key
+
+ def nsmallest(self, n, pop=False):
+ """ T.nsmallest(n) -> get list of n smallest items (k, v).
+ If pop is True, remove items from T.
+ """
+ if pop:
+ return [self.pop_min() for _ in range(min(len(self), n))]
+ else:
+ items = self.items()
+ return [ next(items) for _ in range(min(len(self), n)) ]
+
+ def nlargest(self, n, pop=False):
+ """ T.nlargest(n) -> get list of n largest items (k, v).
+ If pop is True remove items from T.
+ """
+ if pop:
+ return [self.pop_max() for _ in range(min(len(self), n))]
+ else:
+ items = self.items(reverse=True)
+ return [ next(items) for _ in range(min(len(self), n)) ]
+
+ def intersection(self, *trees):
+ """ x.intersection(t1, t2, ...) -> Tree, with keys *common* to all trees
+ """
+ thiskeys = frozenset(self.keys())
+ sets = _build_sets(trees)
+ rkeys = thiskeys.intersection(*sets)
+ return self.__class__( ((key, self.get(key)) for key in rkeys) )
+
+ def union(self, *trees):
+ """ x.union(t1, t2, ...) -> Tree with keys from *either* trees
+ """
+ thiskeys = frozenset(self.keys())
+ rkeys = thiskeys.union(*_build_sets(trees))
+ return self.__class__( ((key, self.get(key)) for key in rkeys) )
+
+ def difference(self, *trees):
+ """ x.difference(t1, t2, ...) -> Tree with keys in T but not any of t1,
+ t2, ...
+ """
+ thiskeys = frozenset(self.keys())
+ rkeys = thiskeys.difference(*_build_sets(trees))
+ return self.__class__( ((key, self.get(key)) for key in rkeys) )
+
+ def symmetric_difference(self, tree):
+ """ x.symmetric_difference(t1) -> Tree with keys in either T and t1 but
+ not both
+ """
+ thiskeys = frozenset(self.keys())
+ rkeys = thiskeys.symmetric_difference(frozenset(tree.keys()))
+ return self.__class__( ((key, self.get(key)) for key in rkeys) )
+
+ def issubset(self, tree):
+ """ x.issubset(tree) -> True if every element in x is in tree """
+ thiskeys = frozenset(self.keys())
+ return thiskeys.issubset(frozenset(tree.keys()))
+
+ def issuperset(self, tree):
+ """ x.issubset(tree) -> True if every element in tree is in x """
+ thiskeys = frozenset(self.keys())
+ return thiskeys.issuperset(frozenset(tree.keys()))
+
+ def isdisjoint(self, tree):
+ """ x.isdisjoint(S) -> True if x has a null intersection with tree """
+ thiskeys = frozenset(self.keys())
+ return thiskeys.isdisjoint(frozenset(tree.keys()))
+
+
+def _build_sets(trees):
+ return [ frozenset(tree.keys()) for tree in trees ]
+
diff --git a/chromium/third_party/bintrees/bintrees/treeslice.py b/chromium/third_party/bintrees/bintrees/treeslice.py
new file mode 100644
index 00000000000..80fb6804fac
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/treeslice.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman -- <mozman@gmx.at>
+# Purpose: TreeSlice
+# Created: 11.04.2011
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+
+class TreeSlice(object):
+ __slots__ = ['_tree', '_start', '_stop']
+
+ def __init__(self, tree, start, stop):
+ self._tree = tree
+ self._start = start
+ self._stop = stop
+
+ def __repr__(self):
+ tpl = "%s({%s})" % (self._tree.__class__.__name__, '%s')
+ return tpl % ", ".join( ("%r: %r" % item for item in self.items()) )
+
+ def __contains__(self, key):
+ if self._inrange(key):
+ return key in self._tree
+ else:
+ return False
+
+ def _inrange(self, key):
+ if self._start is not None and key < self._start:
+ return False
+ if self._stop is not None and key >= self._stop:
+ return False
+ return True
+
+ def __getitem__(self, key):
+ if isinstance(key, slice):
+ return self._subslice(key.start, key.stop)
+ if self._inrange(key):
+ return self._tree[key]
+ else:
+ raise KeyError(key)
+
+ def _subslice(self, start, stop):
+ def newstart():
+ if start is None:
+ return self._start
+ elif self._start is None:
+ return start
+ else:
+ return max(start, self._start)
+
+ def newstop():
+ if stop is None:
+ return self._stop
+ elif self._stop is None:
+ return stop
+ else:
+ return min(stop, self._stop)
+
+ return TreeSlice(self._tree, newstart(), newstop())
+
+ def keys(self):
+ return self._tree.keyslice(self._start, self._stop)
+ __iter__ = keys
+
+ def values(self):
+ return self._tree.valueslice(self._start, self._stop)
+
+ def items(self):
+ return self._tree.itemslice(self._start, self._stop)
diff --git a/chromium/third_party/bintrees/bintrees/walker.py b/chromium/third_party/bintrees/bintrees/walker.py
new file mode 100644
index 00000000000..3041d3dba2c
--- /dev/null
+++ b/chromium/third_party/bintrees/bintrees/walker.py
@@ -0,0 +1,220 @@
+#!/usr/bin/env python
+#coding:utf-8
+# Author: mozman
+# Purpose: tree walker
+# Created: 07.05.2010
+# Copyright (c) 2010-2013 by Manfred Moitzi
+# License: MIT License
+
+from operator import attrgetter, lt, gt
+
+
+class Walker(object):
+ __slots__ = ['_node', '_stack', '_tree']
+
+ def __init__(self, tree):
+ self._tree = tree
+ self._node = tree.root
+ self._stack = []
+
+ def reset(self):
+ self._stack = []
+ self._node = self._tree.root
+
+ @property
+ def key(self):
+ return self._node.key
+
+ @property
+ def value(self):
+ return self._node.value
+
+ @property
+ def item(self):
+ return (self._node.key, self._node.value)
+
+ @property
+ def is_valid(self):
+ return self._node is not None
+
+ def goto(self, key):
+ self._node = self._tree.root
+ while self._node is not None:
+ if key == self._node.key:
+ return True
+ elif key < self._node.key:
+ self.go_left()
+ else:
+ self.go_right()
+ return False
+
+ def push(self):
+ self._stack.append(self._node)
+
+ def pop(self):
+ self._node = self._stack.pop()
+
+ def stack_is_empty(self):
+ return len(self._stack) == 0
+
+ def goto_leaf(self):
+ """ get a leaf node """
+ while self._node is not None:
+ if self.has_left():
+ self.go_left()
+ elif self.has_right():
+ self.go_right()
+ else:
+ return
+
+ def has_child(self, direction):
+ if direction == 0:
+ return self._node.left is not None
+ else:
+ return self._node.right is not None
+
+ def down(self, direction):
+ if direction == 0:
+ self._node = self._node.left
+ else:
+ self._node = self._node.right
+
+ def go_left(self):
+ self._node = self._node.left
+
+ def go_right(self):
+ self._node = self._node.right
+
+ def has_left(self):
+ return self._node.left is not None
+
+ def has_right(self):
+ return self._node.right is not None
+
+ def _next_item(self, key, left, right, less_than):
+ node = self._tree.root
+ succ = None
+ while node is not None:
+ if key == node.key:
+ break
+ elif less_than(key, node.key):
+ if (succ is None) or less_than(node.key, succ.key):
+ succ = node
+ node = left(node)
+ else:
+ node = right(node)
+
+ if node is None: # stay at dead end
+ raise KeyError(str(key))
+ # found node of key
+ if right(node) is not None:
+ # find smallest node of right subtree
+ node = right(node)
+ while left(node) is not None:
+ node = left(node)
+ if succ is None:
+ succ = node
+ elif less_than(node.key, succ.key):
+ succ = node
+ elif succ is None: # given key is biggest in tree
+ raise KeyError(str(key))
+ return (succ.key, succ.value)
+
+ def succ_item(self, key):
+ """ Get successor (k,v) pair of key, raises KeyError if key is max key
+ or key does not exist.
+ """
+ return self._next_item(
+ key,
+ left=attrgetter("left"),
+ right=attrgetter("right"),
+ less_than=lt,
+ )
+
+ def prev_item(self, key):
+ """ Get predecessor (k,v) pair of key, raises KeyError if key is min key
+ or key does not exist.
+ """
+ return self._next_item(
+ key,
+ left=attrgetter("right"),
+ right=attrgetter("left"),
+ less_than=gt,
+ )
+
+ def _iteritems(self, left=attrgetter("left"), right=attrgetter("right")):
+ """ optimized forward iterator (reduced method calls) """
+ if self._tree.is_empty():
+ return
+ node = self._tree.root
+ stack = self._stack
+ go_left = True
+ while True:
+ if left(node) is not None and go_left:
+ stack.append(node)
+ node = left(node)
+ else:
+ yield (node.key, node.value)
+ if right(node) is not None:
+ node = right(node)
+ go_left = True
+ else:
+ if len(stack) == 0:
+ return # all done
+ node = stack.pop()
+ go_left = False
+
+ def iter_items_forward(self):
+ for item in self._iteritems(
+ left=attrgetter("left"),
+ right=attrgetter("right"),
+ ):
+ yield item
+
+ def iter_items_backward(self):
+ for item in self._iteritems(
+ left=attrgetter("right"),
+ right=attrgetter("left"),
+ ):
+ yield item
+
+ def floor_item(self, key):
+ """ Get the element (k,v) pair associated with the greatest key less
+ than or equal to the given key, raises KeyError if there is no such key.
+ """
+ node = self._tree.root
+ prev = None
+ while node is not None:
+ if key == node.key:
+ return node.key, node.value
+ elif key < node.key:
+ node = node.left
+ else:
+ if (prev is None) or (node.key > prev.key):
+ prev = node
+ node = node.right
+ # node must be None here
+ if prev:
+ return prev.key, prev.value
+ raise KeyError(str(key))
+
+ def ceiling_item(self, key):
+ """ Get the element (k,v) pair associated with the smallest key greater
+ than or equal to the given key, raises KeyError if there is no such key.
+ """
+ node = self._tree.root
+ succ = None
+ while node is not None:
+ if key == node.key:
+ return node.key, node.value
+ elif key > node.key:
+ node = node.right
+ else:
+ if (succ is None) or (node.key < succ.key):
+ succ = node
+ node = node.left
+ # node must be None here
+ if succ:
+ return succ.key, succ.value
+ raise KeyError(str(key))
+