Commit 85f51247 authored by Julien Jerphanion's avatar Julien Jerphanion

[WIP] KDTree implementation

parent 9a496aea
# distutils: language = c++
from libcythonplus.list cimport cyplist
from runtime.runtime cimport BatchMailBox, NullResult, Scheduler
from libc.stdio cimport (
fprintf, fopen, fclose, fread,
fwrite, FILE, stdout, printf, ferror
)
from stdlib.stat cimport Stat, dev_t
from stdlib.fmt cimport sprintf
from stdlib.string cimport string
from posix.unistd cimport readlink
cdef lock Scheduler scheduler
cdef cypclass Node activable:
"""A KDTree Node"""
cyplist[int] point
active Node left_child
active Node right_child
__init__(self):
self._active_result_class = NullResult
self._active_queue_class = consume BatchMailBox(scheduler)
self.left_child = NULL
self.right_child = NULL
void build_node(self, lock cyplist[cyplist[int]] points, int depth):
if (depth < 0):
return
printf("Depth %d\n", depth)
self.left_child = activate(consume Node())
self.right_child = activate(consume Node())
self.left_child.build_node(NULL, consume points, depth - 1)
self.right_child.build_node(NULL, consume points, depth - 1)
cdef int start(string path) nogil:
global scheduler
scheduler = Scheduler()
points = cyplist[cyplist[int]]()
# TODO: integrate here
# [7, 2],
# [5, 4],
# [9, 6],
# [4, 7],
# [8, 1],
# [2, 3]
node = consume Node()
if node is NULL:
return -1
root = activate(consume node)
root.build_node(NULL, consume points, 4)
scheduler.finish()
del scheduler
return 0
cdef public int main() nogil:
return start(<char*>'.')
def python_main():
start(<char*>'.')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment