<commit_before>/*
 * This file is part of ELKI:
 * Environment for Developing KDD-Applications Supported by Index-Structures
 * 
 * Copyright (C) 2020
 * ELKI Development Team
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package elki.index.tree.betula;

import elki.index.tree.betula.features.AsClusterFeature;
import elki.index.tree.betula.features.ClusterFeature;

/**
 * Interface for TreeNode
 * 
 * @author <NAME>
 * 
 * @param <L> Cluster feature type
 */
public class CFNode<L extends ClusterFeature> implements AsClusterFeature {
  /**
   * Cluster feature
   */
  private L cf;

  /**
   * Children of the TreeNode
   */
  private Object[] children;

  /**
   * Constructor
   * 
   * @param capacity Fanout of the Tree
   */
  public CFNode(L cf, int capacity) {
    super();
    this.cf = cf;
    this.children = new Object[capacity];
  }

  @Override
  public L getCF() {
    return cf;
  }

  /**
   * Set child with index i to CF cf
   * 
   * @param i Index
   * @param cf Clustering Feature
   */
  public void setChild(int i, AsClusterFeature cf) {
    children[i] = cf;
  }

  /**
   * Add a child without statistics
   * 
   * @param cf Clustering Feature
   * 
   * @return success
   */
  public boolean setChild(AsClusterFeature node) {
    for(int i = 0; i < children.length; i++) {
      if(children[i] == null) {
        children[i] = node;
        return true;
      }
    }
    return false;
  }

  /**
   * Get CF from Index i
   * 
   * @param i Index
   * @return CF
   */
  public AsClusterFeature getChild(int i) {
    return (AsClusterFeature) children[i];
  }<commit_msg>fix array out of bounds exeption<commit_after>/*
 * This file is part of ELKI:
 * Environment for Developing KDD-Applications Supported by Index-Structures
 * 
 * Copyright (C) 2020
 * ELKI Development Team
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package elki.index.tree.betula;

import elki.index.tree.betula.features.AsClusterFeature;
import elki.index.tree.betula.features.ClusterFeature;

/**
 * Interface for TreeNode
 * 
 * @author <NAME>
 * 
 * @param <L> Cluster feature type
 */
public class CFNode<L extends ClusterFeature> implements AsClusterFeature {
  /**
   * Cluster feature
   */
  private L cf;

  /**
   * Children of the TreeNode
   */
  private Object[] children;

  /**
   * Constructor
   * 
   * @param capacity Fanout of the Tree
   */
  public CFNode(L cf, int capacity) {
    super();
    this.cf = cf;
    this.children = new Object[capacity];
  }

  @Override
  public L getCF() {
    return cf;
  }

  /**
   * Set child with index i to CF cf
   * 
   * @param i Index
   * @param cf Clustering Feature
   */
  public void setChild(int i, AsClusterFeature cf) {
    children[i] = cf;
  }

  /**
   * Add a child without statistics
   * 
   * @param cf Clustering Feature
   * 
   * @return success
   */
  public boolean setChild(AsClusterFeature node) {
    for(int i = 0; i < children.length; i++) {
      if(children[i] == null) {
        children[i] = node;
        return true;
      }
    }
    return false;
  }

  /**
   * Get CF from Index i
   * 
   * @param i Index
   * @return CF
   */
  public AsClusterFeature getChild(int i) {
    if(i < children.length) {
    return (AsClusterFeature) children[i];
  }
  else {
    return null;
  }
  }
{'fraction_non_alphanumeric': 0.09685921370524929, 'fraction_numerical': 0.002635624862727872, 'mean_word_length': 2.754328112118714, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7487057', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1340, 'n_words': 510}