<commit_before>//-------------------------------------------------------------------
//
// File:      delta-crdts.cc
//
// @author    <NAME> <<EMAIL>>
//
// @copyright 2014-2016 <NAME>
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License.  You may obtain
// a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// @doc  
//   Reference implementation in C++ of delta enabled CRDTs
// @end  
//
//
//-------------------------------------------------------------------

#include <set>
#include <unordered_set>
#include <map>
#include <list>
#include <tuple>
#include <vector>
#include <string>
#include <iostream>
#include <type_traits>

using namespace std;

template< bool b > 
struct join_selector { 
  template< typename T > 
  static T join( const T& l, const T& r ) 
  { 
    T res;
    res=l;
    res.join(r);
    return res;
  } 
};

template<> 
struct join_selector < true > { 
  template< typename T > 
  static T join( const T& l, const T& r ) 
  { 
    T res;
    res=max(l,r);
    return res;
  } 
};


// Join with C++ traits
template<typename T> // Join two objects, deriving a new one
T join(const T& l, const T& r) // assuming copy constructor
{
  return join_selector< is_arithmetic<T>::value >::join(l,r);
}

template<typename A, typename B> // Join two pairs of objects
pair<A,B> join(const pair<A,B>& l, const pair<A,B>& r)
{
  pair<A,B> res;
  res.first=join(r.first,l.first);
  res.second=join(r.second,l.second);
  return res;
}

template<typename A, typename B> // Join lexicographic of two pairs of objects
pair<A,B> lexjoin(const pair<A,B>& l, const pair<A,B>& r)
{
  pair<A,B> res;
  if (r==l) return res=r;
  if (l.first > r.first) return res=l;
  if (r.first > l.first) return res=r;
  // Left is equal, so join right
  if (r.first == l.first)
  {
    res.first=r.first;
    res.second=join(r.second,l.second);
    return res;
  }
  // Otherwise A is not a total order so keep res empty to signal error
  return res;
}

template<typename A, typename B> // Output a pair
ostream &operator<<( ostream &output, const pair<A,B>& o)
{
  output << "(" << o.first << "," << o.second << ")";
  return output;
}

template<typename T> // Output a set
ostream &operator<<( ostream &output, const set<T>& o)
{
  output << "( ";
  for (const auto& e : o) output << e << " ";
  output << ")";
  return output;
}

template<typename T> // get a point among two points
vector<T> among(const vector<T> & l, const vector<T> & r)
{
  // Overall strategy is to first try wide advances to the right, 
  // as compact as possible. If that fails, go with fine grain (less compact)
  // advances until eventually succeed. 
  assert (l < r);
  vector<T> res;
  // adjust res as forwardly compact as possible
  for (int is = 0; is <= l.size(); is++)
  {
    res.assign(l.begin(),l.begin()+is); // get initial segment
    if ( is < l.size() ) // if partial segment, try appending one
    {
      res.push_back(true);
      if ( res >= l && res < r ) break; // see if we are there 
    }
  }
  assert (res >= l && res < r);
  if (res > l) return res;
  //vector<T> res=l;
  // forward finer and finer
  res.push_back(true);    
  while (res >= r)
  {
    res.back()=false;
    res.push_back(true);    
  }
  assert (res > l && res < r);
  return res;
}

template<typename T> // Output a vector
ostream &operator<<( ostream &output, const vector<T>& o)
{
  output << "[";
  for (const auto & e : o) output << e;
  output << "]";
  return output;
}

// Autonomous causal context, for context sharing in maps
template<typename K><commit_msg>id optimisation 1.0<commit_after>//-------------------------------------------------------------------
//
// File:      delta-crdts.cc
//
// @author    <NAME> <<EMAIL>>
//
// @copyright 2014-2016 <NAME>
//
// This file is provided to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file
// except in compliance with the License.  You may obtain
// a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// @doc  
//   Reference implementation in C++ of delta enabled CRDTs
// @end  
//
//
//-------------------------------------------------------------------

#include <set>
#include <unordered_set>
#include <map>
#include <list>
#include <tuple>
#include <vector>
#include <string>
#include <iostream>
#include <type_traits>

using namespace std;

template< bool b > 
struct join_selector { 
  template< typename T > 
  static T join( const T& l, const T& r ) 
  { 
    T res;
    res=l;
    res.join(r);
    return res;
  } 
};

template<> 
struct join_selector < true > { 
  template< typename T > 
  static T join( const T& l, const T& r ) 
  { 
    T res;
    res=max(l,r);
    return res;
  } 
};


// Join with C++ traits
template<typename T> // Join two objects, deriving a new one
T join(const T& l, const T& r) // assuming copy constructor
{
  return join_selector< is_arithmetic<T>::value >::join(l,r);
}

template<typename A, typename B> // Join two pairs of objects
pair<A,B> join(const pair<A,B>& l, const pair<A,B>& r)
{
  pair<A,B> res;
  res.first=join(r.first,l.first);
  res.second=join(r.second,l.second);
  return res;
}

template<typename A, typename B> // Join lexicographic of two pairs of objects
pair<A,B> lexjoin(const pair<A,B>& l, const pair<A,B>& r)
{
  pair<A,B> res;
  if (r==l) return res=r;
  if (l.first > r.first) return res=l;
  if (r.first > l.first) return res=r;
  // Left is equal, so join right
  if (r.first == l.first)
  {
    res.first=r.first;
    res.second=join(r.second,l.second);
    return res;
  }
  // Otherwise A is not a total order so keep res empty to signal error
  return res;
}

template<typename A, typename B> // Output a pair
ostream &operator<<( ostream &output, const pair<A,B>& o)
{
  output << "(" << o.first << "," << o.second << ")";
  return output;
}

template<typename T> // Output a set
ostream &operator<<( ostream &output, const set<T>& o)
{
  output << "( ";
  for (const auto& e : o) output << e << " ";
  output << ")";
  return output;
}

template<typename T> // get a point among two points
vector<T> among(const vector<T> & l, const vector<T> & r, int j=0)
{
  // Overall strategy is to first try wide advances to the right, 
  // as compact as possible. If that fails, go with fine grain (less compact)
  // advances until eventually succeed. 
  assert (l < r);
  vector<T> res;
  // adjust res as forwardly compact as possible
  for (int is = 0; is <= l.size(); is++)
  {
    res.assign(l.begin(),l.begin()+is); // get initial segment
    if ( is < l.size() ) // if partial segment, try appending one
    {
      res.push_back(true);
      if ( res >= l && res < r ) break; // see if we are there 
    }
  }
  assert (res >= l && res < r);
  if (res > l) return res;
  //vector<T> res=l;
  // forward finer and finer
  for(int i = 0; i < j; i++){
    res.push_back(false);
  }
  res.push_back(true);    
  
  while (res >= r)
  {
    res.back()=false;
    for(int i = 0; i < j; i++){
      res.push_back(false);
    }
    res.push_back(true);    
  }
  assert (res > l && res < r);
  return res;
}

template<typename T> // Output a vector
ostream &operator<<( ostream &output, const vector<T>& o)
{
  output << "[";
  for (const auto & e : o) output << e;
  output << "]";
  return output;
}

// Autonomous causal context, for context sharing in maps
template<typename K>
{'fraction_non_alphanumeric': 0.17874692874692874, 'fraction_numerical': 0.0038083538083538084, 'mean_word_length': 2.5690486628671634, 'pattern_counts': {'":': 0, '<': 165, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1918120', 'n_tokens_mistral': 2753, 'n_tokens_neox': 2681, 'n_words': 957}