<commit_before>//
//  Copyright (C) 2004-2006 Rational Discovery LLC
//
//   @@ All Rights Reserved  @@
//

//! \file RankAtoms.h
/*!
    \brief Utility functionality used by atom rankers.
*/
#ifndef _RD_RANKATOMS_H_
#define _RD_RANKATOMS_H_

#include <queue>
#include <vector>
#include <list>
#include <algorithm>

namespace RankAtoms {
  typedef std::vector<int> INT_VECT;
  typedef std::list<int> INT_LIST;

  //! utility function for ranking atoms
  void updateInPlayIndices(const INT_VECT &ranks,INT_LIST &indicesInPlay);

  //! returns the count of unique items in an std::vector
  template <typename T>
  unsigned int countClasses(const std::vector<T> &vect){
    std::vector<T> sortedVect = vect;
    std::sort(sortedVect.begin(),sortedVect.end(),std::less<T>());
    typename std::vector<T>::iterator newEnd=std::unique(sortedVect.begin(),sortedVect.end());
    return newEnd-sortedVect.begin();
  }

  //! functor for implementing > on two std::pairs.  The first entries are compared.
  template <typename T>
  struct pairGTFunctor {
    bool operator() (const std::pair<T,int> &v1,const std::pair<T,int> &v2){
      return v1.first > v2.first;
    }
  };

  //! function for implementing < on two std::pairs.  The first entries are compared.
  template <typename T>
  bool pairLess(const std::pair<T,int> &v1,const std::pair<T,int> &v2){
    return v1.first < v2.first;
  }

  //! ranks the entries in a vector
  /*!
    \param vect the vector to rank
    \param res  is used to return the ranks of each entry
  */
  template <typename T>  
  void rankVect(const std::vector<T> &vect,INT_VECT &res){
    PRECONDITION(res.size()>=vect.size(),"vector size mismatch");
    int nEntries = vect.size();

#if 0
    std::priority_queue< std::pair<T,int>,
                         std::vector< std::pair<T, int> >,
                         pairGTFunctor<T> > sortedVect;
    for(unsigned int i=0;i<nEntries;++i){
      sortedVect.push(std::make_pair(vect[i],i));
    }

    int currRank=0;
    T lastV = sortedVect.top().first;
    for(unsigned int i=0;i<nEntries;++i){
      const std::pair<T,int> &p = sortedVect.top();
      if(p.first==lastV){
        res[p.second] = currRank;
      } else {
        res[p.second] = ++currRank;
        lastV = p.first;
      }
      sortedVect.pop();
    }
#else<commit_msg>remove a compile error<commit_after>//
//  Copyright (C) 2004-2006 Rational Discovery LLC
//
//   @@ All Rights Reserved  @@
//

//! \file RankAtoms.h
/*!
    \brief Utility functionality used by atom rankers.
*/
#ifndef _RD_RANKATOMS_H_
#define _RD_RANKATOMS_H_

#include <queue>
#include <vector>
#include <list>
#include <algorithm>

namespace RankAtoms {
  typedef std::vector<int> INT_VECT;
  typedef std::list<int> INT_LIST;

  //! utility function for ranking atoms
  void updateInPlayIndices(const INT_VECT &ranks,INT_LIST &indicesInPlay);

  //! returns the count of unique items in an std::vector
  template <typename T>
  unsigned int countClasses(const std::vector<T> &vect){
    std::vector<T> sortedVect = vect;
    std::sort(sortedVect.begin(),sortedVect.end(),std::less<T>());
    typename std::vector<T>::iterator newEnd=std::unique(sortedVect.begin(),sortedVect.end());
    return newEnd-sortedVect.begin();
  }

  //! functor for implementing > on two std::pairs.  The first entries are compared.
  template <typename T>
  struct pairGTFunctor {
    bool operator() (const std::pair<T,int> &v1,const std::pair<T,int> &v2){
      return v1.first > v2.first;
    }
  };

  //! function for implementing < on two std::pairs.  The first entries are compared.
  template <typename T>
  bool pairLess(const std::pair<T,int> &v1,const std::pair<T,int> &v2){
    return v1.first < v2.first;
  }

  //! ranks the entries in a vector
  /*!
    \param vect the vector to rank
    \param res  is used to return the ranks of each entry
  */
  template <typename T>  
  void rankVect(const std::vector<T> &vect,INT_VECT &res){
    PRECONDITION(res.size()>=vect.size(),"vector size mismatch");
    unsigned int nEntries = vect.size();

#if 0
    std::priority_queue< std::pair<T,int>,
                         std::vector< std::pair<T, int> >,
                         pairGTFunctor<T> > sortedVect;
    for(unsigned int i=0;i<nEntries;++i){
      sortedVect.push(std::make_pair(vect[i],i));
    }

    int currRank=0;
    T lastV = sortedVect.top().first;
    for(unsigned int i=0;i<nEntries;++i){
      const std::pair<T,int> &p = sortedVect.top();
      if(p.first==lastV){
        res[p.second] = currRank;
      } else {
        res[p.second] = ++currRank;
        lastV = p.first;
      }
      sortedVect.pop();
    }
#else
{'fraction_non_alphanumeric': 0.14709677419354839, 'fraction_numerical': 0.008602150537634409, 'mean_word_length': 3.2320291173794358, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, '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': '2850758', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1610, 'n_words': 395}