<commit_before>package org.basex.gui.view.map;

import java.util.Arrays;

import org.basex.data.Data;
import org.basex.gui.GUIProp;
import org.basex.util.IntList;
import org.basex.util.Performance;
import org.basex.util.Token;
import org.basex.util.TokenList;

/**
 * stores an integer array of pre values and their corresponding weights, sizes 
 * and number of children.
 *
 * @author Workgroup DBIS, University of Konstanz 2005-08, ISC License
 * @author <NAME>
 */
public class MapList extends IntList {
  /** Weights array. */
  public double[] weights;

  /**
   * Constructor, specifying an initial list size.
   */
  public MapList() {
  }
  
  /**
   * Constructor, specifying an initial list size.
   * @param is initial size of the list
   */
  public MapList(final int is) {
    super(is);
  }

  /**
   * Constructor, specifying an initial array.
   * @param v initial list values
   */
  public MapList(final int[] v) {
    super(v);
  }
  
  @Override
  public void sort() {
    if(weights == null) return;
    
    final TokenList tl = new TokenList();
    for(int c = 0; c < size; c++) tl.add(Token.token(weights[c]));
    sort(tl.finish(), true, false);
    Arrays.sort(weights);
    for (int l = 0, r = weights.length - 1; l < r; l++, r--) {
      // exchange the first and last
      double temp = weights[l]; weights[l]  = weights[r]; weights[r] = temp;
    }
    
    // simple bubble sort, obsolete
//    boolean switched = true;
//    int n = size;
//    do {
//      switched = false;
//      for(int i = 0; i < size - 1; i++) {
//        if(weights[i] < weights[i + 1]) {
//          // switch entries
//          int tmpint = list[i];
//          list[i] = list[i + 1];
//          list[i + 1] = tmpint;
//          // switch weights
//          double wtmp = weights[i];
//          weights[i] = weights[i + 1];
//          weights[i + 1] = wtmp;
//          
//          switched = true;
//        }
//      }
//      n--;
//    } while (n >= 0 && switched);
  }
  
  /**
   * Initializes the weights of each list entry and stores it in an extra list.
   * @param parsize reference size
   * @param parchildren reference number of nodes
   * @param data reference
   * [JH] modify to take textnode sizes into account
   */
  public void initWeights(final long parsize, final int parchildren,
      final Data data) {
    weights = new double[list.length];
    int[] nrchildren = new int[list.length];
    long[] sizes = new long[list.length];
    int sizeP = GUIProp.sizep;
    
    // use #children and size for weight
    if (0 < GUIProp.sizep && GUIProp.sizep < 100 && data.fs != null) {
      for(int i = 0; i < size - 1; i++) {
        sizes[i] = data.fs != null ? 
            Token.toLong(data.attValue(data.sizeID, list[i])) : 0;
        nrchildren[i] = list[i + 1] - list[i];
        weights[i] = sizeP / 100d * sizes[i] / parsize + 
            (1 - sizeP / 100d) * nrchildren[i] / parchildren;
      }
    // only sizes
    } else if (GUIProp.sizep == 100 && data.fs != null) {
      for(int i = 0; i < size - 1; i++) {
        sizes[i] = data.fs != null ? 
            Token.toLong(data.attValue(data.sizeID, list[i])) : 0;
        weights[i] = sizes[i] * 1d / parsize;
      }    
    //only #children
    } else if (GUIProp.sizep == 0 || data.fs == null) {
      for(int i = 0; i < size - 1; i++) {
        nrchildren[i] = list[i + 1] - list[i];
        weights[i] = nrchildren[i] * 1d / parchildren;
      }
    }
    for (int i = 0; i < size; i++) if(Double.isNaN(weights[i])) weights[i] = 0;
  }
}<commit_msg>minor<commit_after>package org.basex.gui.view.map;

import java.util.Arrays;

import org.basex.data.Data;
import org.basex.gui.GUIProp;
import org.basex.util.IntList;
import org.basex.util.Token;
import org.basex.util.TokenList;

/**
 * stores an integer array of pre values and their corresponding weights, sizes 
 * and number of children.
 *
 * @author Workgroup DBIS, University of Konstanz 2005-08, ISC License
 * @author <NAME>
 */
public class MapList extends IntList {
  /** Weights array. */
  public double[] weights;

  /**
   * Constructor, specifying an initial list size.
   */
  public MapList() {
  }
  
  /**
   * Constructor, specifying an initial list size.
   * @param is initial size of the list
   */
  public MapList(final int is) {
    super(is);
  }

  /**
   * Constructor, specifying an initial array.
   * @param v initial list values
   */
  public MapList(final int[] v) {
    super(v);
  }
  
  @Override
  public void sort() {
    if(weights == null) return;
    
    final TokenList tl = new TokenList();
    for(int c = 0; c < size; c++) tl.add(Token.token(weights[c]));
    sort(tl.finish(), true, false);
    Arrays.sort(weights);
    for (int l = 0, r = weights.length - 1; l < r; l++, r--) {
      // exchange the first and last
      double temp = weights[l]; weights[l]  = weights[r]; weights[r] = temp;
    }
    
    // simple bubble sort, obsolete
//    boolean switched = true;
//    int n = size;
//    do {
//      switched = false;
//      for(int i = 0; i < size - 1; i++) {
//        if(weights[i] < weights[i + 1]) {
//          // switch entries
//          int tmpint = list[i];
//          list[i] = list[i + 1];
//          list[i + 1] = tmpint;
//          // switch weights
//          double wtmp = weights[i];
//          weights[i] = weights[i + 1];
//          weights[i + 1] = wtmp;
//          
//          switched = true;
//        }
//      }
//      n--;
//    } while (n >= 0 && switched);
  }
  
  /**
   * Initializes the weights of each list entry and stores it in an extra list.
   * @param parsize reference size
   * @param parchildren reference number of nodes
   * @param data reference
   * [JH] modify to take textnode sizes into account
   */
  public void initWeights(final long parsize, final int parchildren,
      final Data data) {
    weights = new double[list.length];
    int[] nrchildren = new int[list.length];
    long[] sizes = new long[list.length];
    int sizeP = GUIProp.sizep;
    
    // use #children and size for weight
    if (0 < GUIProp.sizep && GUIProp.sizep < 100 && data.fs != null) {
      for(int i = 0; i < size - 1; i++) {
        sizes[i] = data.fs != null ? 
            Token.toLong(data.attValue(data.sizeID, list[i])) : 0;
        nrchildren[i] = list[i + 1] - list[i];
        weights[i] = sizeP / 100d * sizes[i] / parsize + 
            (1 - sizeP / 100d) * nrchildren[i] / parchildren;
      }
    // only sizes
    } else if (GUIProp.sizep == 100 && data.fs != null) {
      for(int i = 0; i < size - 1; i++) {
        sizes[i] = data.fs != null ? 
            Token.toLong(data.attValue(data.sizeID, list[i])) : 0;
        weights[i] = sizes[i] * 1d / parsize;
      }    
    //only #children
    } else if (GUIProp.sizep == 0 || data.fs == null) {
      for(int i = 0; i < size - 1; i++) {
        nrchildren[i] = list[i + 1] - list[i];
        weights[i] = nrchildren[i] * 1d / parchildren;
      }
    }
    for (int i = 0; i < size; i++) if(Double.isNaN(weights[i])) weights[i] = 0;
  }
}
{'fraction_non_alphanumeric': 0.15338899108532617, 'fraction_numerical': 0.013018253855950191, 'mean_word_length': 2.0703735881841876, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '918345', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2396, 'n_words': 698}