<commit_before>/* File: string_map.h
 * Author: <NAME> <<EMAIL>>
 * Copyright: 2015 Carnegie Mellon University
 * License: BSD
 */

namespace pr_bgl
{

inline void stringify_from_x(std::string & repr, const double & val)
{
   char buf[2048];
   int min = 0;
   int max = 2047;
   // invariant: min DOESNT WORK, max DOES WORK
   // validate invariants
   sprintf(buf, "%.*f", min, val);
   if (val == strtod(buf,0))
   {
      repr = std::string(buf);
      return;
   }
   sprintf(buf, "%.*f", max, val);
   if (val != strtod(buf,0))
   {
      repr = std::string(buf);
      return;
   }
   // binary search
   for (;;)
   {
      int diff = max - min;
      if (diff == 1)
         break;
      int test = min + diff/2;
      sprintf(buf, "%.*f", test, val);
      if (val == strtod(buf,0))
         max = test;
      else
         min = test;
   }
   sprintf(buf, "%.*f", max, val);
   repr = std::string(buf);
   return;
}
inline void stringify_to_x(const std::string & repr, double & val)
{
   val = atof(repr.c_str());
}


inline void stringify_from_x(std::string & repr, const int & val)
{<commit_msg>fixed out-of-bounds bug in string_map<commit_after>/* File: string_map.h
 * Author: <NAME> <<EMAIL>>
 * Copyright: 2015 Carnegie Mellon University
 * License: BSD
 */

namespace pr_bgl
{

inline void stringify_from_x(std::string & repr, const double & val)
{
   char buf[2048];
   // invariant: min DOESNT WORK, max DOES WORK
   // validate invariants
   int min = 0;
   sprintf(buf, "%.*f", min, val);
   if (val == strtod(buf,0))
   {
      repr = std::string(buf);
      return;
   }
   // what is it at 1?
   sprintf(buf, "%.*f", 1, val);
   int max = sizeof(buf)-strlen(buf);
   sprintf(buf, "%.*f", max, val);
   if (val != strtod(buf,0))
   {
      printf("stringify_from_x invariant failed!\n");
      abort();
   }
   // binary search
   for (;;)
   {
      int diff = max - min;
      if (diff == 1)
         break;
      int test = min + diff/2;
      sprintf(buf, "%.*f", test, val);
      if (val == strtod(buf,0))
         max = test;
      else
         min = test;
   }
   sprintf(buf, "%.*f", max, val);
   repr = std::string(buf);
   return;
}
inline void stringify_to_x(const std::string & repr, double & val)
{
   val = atof(repr.c_str());
}


inline void stringify_from_x(std::string & repr, const int & val)
{
{'fraction_non_alphanumeric': 0.1658828559213339, 'fraction_numerical': 0.01453612654980761, 'mean_word_length': 2.4615384615384617, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5144916', 'n_tokens_mistral': 891, 'n_tokens_neox': 858, 'n_words': 232}