code: def _hdbscan_boruvka_kdtree(
      X,
      min_samples=5,
      alpha=1.0,
      metric="minkowski",
      p=2,
      leaf_size=40,
      approx_min_span_tree=True,
      gen_min_span_tree=False,
      core_dist_n_jobs=4,
      **kwargs,
  ):
      if leaf_size < 3:
          leaf_size = 3
  
      if core_dist_n_jobs < 1:
          core_dist_n_jobs = max(cpu_count() + 1 + core_dist_n_jobs, 1)
  
      if X.dtype != np.float64:
          X = X.astype(np.float64)
  
      tree = KDTree(X, metric=metric, leaf_size=leaf_size, **kwargs)
      alg = KDTreeBoruvkaAlgorithm(
          tree,
          min_samples,
          metric=metric,
          leaf_size=leaf_size // 3,
          approx_min_span_tree=approx_min_span_tree,
          n_jobs=core_dist_n_jobs,
          **kwargs,
      )
      min_spanning_tree = alg.spanning_tree()
      # Sort edges of the min_spanning_tree by weight
      row_order = np.argsort(min_spanning_tree.T[2])
      min_spanning_tree = min_spanning_tree[row_order, :]
      # Convert edge list into standard hierarchical clustering format
      single_linkage_tree = label(min_spanning_tree)
  
      if gen_min_span_tree:
          return single_linkage_tree, min_spanning_tree
      else:
          return single_linkage_tree, None
  
imports: import numpy
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.metrics import pairwise_distances
  from scipy.sparse import issparse
  from sklearn.neighbors import KDTree, BallTree
  from joblib import Memory
  from warnings import warn
  from sklearn.utils import check_array
  from joblib.parallel import cpu_count
  from scipy.sparse import csgraph
  from ._hdbscan_linkage import single_linkage, mst_linkage_core, mst_linkage_core_vector, label
  from ._hdbscan_tree import condense_tree, compute_stability, get_clusters, outlier_scores
  from ._hdbscan_reachability import mutual_reachability, sparse_mutual_reachability
  from ._hdbscan_boruvka import KDTreeBoruvkaAlgorithm, BallTreeBoruvkaAlgorithm
  from .dist_metrics import DistanceMetric
  from .plots import CondensedTree, SingleLinkageTree, MinimumSpanningTree
  from .prediction import PredictionData
  from numpy import isclose
label_desc: Use image node_id 6 for calling a global function with example usage: _hdbscan_boruvka_kdtree(X, min_samples, alpha, metric, p, leaf_size, approx_min_span_tree, gen_min_span_tree, core_dist_n_jobs) and returns: single_linkage_tree,  min_spanning_tree, single_linkage_tree,  None