Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cppbktree/cppbktree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ cdef extern from "cppbktree.hpp":

cdef class _BKTree:
cdef CppBKTree[vector[uint8_t], size_t]* tree
cdef int max_element_count
cdef bool _needs_rebalance
Copy link
Copy Markdown
Owner

@mxmlnkn mxmlnkn Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? It worked fine without it. Honest question because I am not too well-versed with Cython.


def __cinit__(self, list_of_hashes_or_file_name, max_element_count = 32 * 1024):
self.tree = new CppBKTree[vector[uint8_t], size_t](<vector[vector[uint8_t]]>list_of_hashes_or_file_name)
Expand Down Expand Up @@ -129,6 +131,8 @@ cdef class _BKTree:

cdef class _BKTree64:
cdef CppBKTree[uint64_t, size_t]* tree
cdef int max_element_count
cdef bool _needs_rebalance

def __cinit__(self, list_of_hashes_or_file_name, max_element_count = 32 * 1024):
self.tree = new CppBKTree[uint64_t, size_t](list_of_hashes_or_file_name)
Expand Down Expand Up @@ -170,14 +174,14 @@ cdef class _BKTree64:
}
return stats

def rebalance(self, max_element_count):
return self.tree.rebalance(<size_t>max_element_count)
def rebalance(self, max_element_count = None):
return self.tree.rebalance(self.max_element_count if max_element_count is None else <size_t>max_element_count)


# Extra class because cdefs are not visible from outside
class BKTree:
def __init__(self, list_of_hashes):
self.tree = _BKTree(list_of_hashes)
def __init__(self, list_of_hashes, max_element_count = 32 * 1024):
self.tree = _BKTree(list_of_hashes, max_element_count)

def add(self, list_of_hashes_or_file_name):
self.tree.add(list_of_hashes_or_file_name)
Expand All @@ -191,7 +195,7 @@ class BKTree:
def statistics(self):
return self.tree.statistics()

def rebalance(self, max_element_count):
def rebalance(self, max_element_count = None):
return self.tree.rebalance(max_element_count)


Expand All @@ -211,7 +215,7 @@ class BKTree64:
def statistics(self):
return self.tree.statistics()

def rebalance(self, max_element_count):
def rebalance(self, max_element_count = None):
return self.tree.rebalance(max_element_count)


Expand Down
Loading