Compare commits

..

5 commits

Author SHA1 Message Date
Bruno BELANYI 7799ec70ac Add k-d tree post
Some checks failed
ci/woodpecker/push/deploy/2 Pipeline failed
ci/woodpecker/cron/deploy/2 Pipeline was successful
2024-08-11 10:47:53 +01:00
Bruno BELANYI 8acb675b16 posts: kd-tree: add nearest neighbour 2024-08-11 10:47:53 +01:00
Bruno BELANYI 74d4aa87e6 posts: kd-tree: add search 2024-08-11 10:47:53 +01:00
Bruno BELANYI a12642a9bd posts: kd-tree: add insertion 2024-08-11 10:47:53 +01:00
Bruno BELANYI e3a3930ff3 posts: kd-tree: add construction 2024-08-11 10:47:53 +01:00

View file

@ -72,13 +72,6 @@ class KdLeafNode[T]:
def __init__(self):
self.points = {}
# Convenience constructor used when splitting a node
@classmethod
def from_items(cls, items: Iterable[tuple[Point, T]]) -> KdLeafNode[T]:
res = cls()
res.points.update(items)
return res
```
#### Split node
@ -117,6 +110,13 @@ class KdNode[T]:
def __init__(self):
self.inner = KdLeafNode()
# Convenience constructor used when splitting a node
@classmethod
def from_items(cls, items: Iterable[tuple[Point, T]]) -> KdNode[T]:
res = cls()
res.inner.points.update(items)
return res
class KdTree[T]:
_root: KdNode[T]
@ -165,7 +165,7 @@ def split_leaf[T](node: KdLeafNode[T], axis: Axis) -> KdSplitNode[T]:
return KdSplitNode(
split_axis,
mid,
(KdLeafNode.from_items(left), KdLeafNode.from_items(right)),
(KdNode.from_items(left), KdNode.from_items(right)),
)
class KdTree[T]: