项目作者: alesanfra

项目描述 :
Multidimensional binary search tree for associative searching
高级语言: Python
项目地址: git://github.com/alesanfra/kdtree.git
创建时间: 2020-11-05T20:15:49Z
项目社区:https://github.com/alesanfra/kdtree

开源协议:GNU General Public License v3.0

下载


Build
Quality Gate Status
codecov

KDTree

Implementation of a multidimensional binary search tree for associative searching

References

Jon Louis Bentley. Multidimensional binary search tree used for associative searching. September 1975.

Usage

  1. from kdtree import BinSearchTree, Bound, Node, Region
  2. # Create a new tree
  3. tree = BinSearchTree(dimension=2)
  4. # Insert some nodes into the tree
  5. tree.insert(Node((50, 50)))
  6. tree.insert(Node((10, 70)))
  7. tree.insert(Node((80, 85)))
  8. tree.insert(Node((25, 20)))
  9. tree.insert(Node((40, 85)))
  10. tree.insert(Node((70, 85)))
  11. tree.insert(Node((10, 60)))
  12. # Create rectangle from a bound array as described in the article
  13. # Element 2*j is lower bound and element (2*j)+1 is upper bound of dimension j
  14. rectangle_1 = Region.from_bounds_array(69, 71, 84, 86)
  15. # Create rectangles as a list of Bound object
  16. rectangle_2 = Region(Bound(69, 71), Bound(84, 86))
  17. # Search
  18. nodes = tree.regional_search(rectangle_1)
  19. print("Nodes within region:", nodes)