docs: protected void addInstanceToTree(Instance inst, KDTreeNode node)
        throws Exception {
      if (node.isALeaf()) {
        int instList[] = new int[m_Instances.numInstances()];
        try {
          System.arraycopy(m_InstList, 0, instList, 0, node.m_End + 1); // m_InstList.squeezeIn(m_End,
                                                                        // index);
          if (node.m_End < m_InstList.length - 1)
            System.arraycopy(m_InstList, node.m_End + 1, instList,
                node.m_End + 2, m_InstList.length - node.m_End - 1);
          instList[node.m_End + 1] = m_Instances.numInstances() - 1;
        } catch (ArrayIndexOutOfBoundsException ex) {
          System.err.println("m_InstList.length: " + m_InstList.length
              + " instList.length: " + instList.length + "node.m_End+1: "
              + (node.m_End + 1) + "m_InstList.length-node.m_End+1: "
              + (m_InstList.length - node.m_End - 1));
          throw ex;
        }
        m_InstList = instList;
  
        node.m_End++;
        node.m_NodeRanges = m_EuclideanDistance.updateRanges(inst,
            node.m_NodeRanges);
  
        m_Splitter.setInstanceList(m_InstList);
  
        // split this leaf node if necessary
        double[][] universe = m_EuclideanDistance.getRanges();
        if (node.numInstances() > m_MaxInstInLeaf
            && getMaxRelativeNodeWidth(node.m_NodeRanges, universe) > m_MinBoxRelWidth) {
          m_Splitter.splitNode(node, m_NumNodes, node.m_NodeRanges, universe);
          m_NumNodes += 2;
        }
      }// end if node is a leaf
      else {
        if (m_EuclideanDistance.valueIsSmallerEqual(inst, node.m_SplitDim,
            node.m_SplitValue)) {
          addInstanceToTree(inst, node.m_Left);
          afterAddInstance(node.m_Right);
        } else
          addInstanceToTree(inst, node.m_Right);
  
        node.m_End++;
        node.m_NodeRanges = m_EuclideanDistance.updateRanges(inst,
            node.m_NodeRanges);
      }
    }