<commit_before>//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
// 
// MetaPhysicL - A metaprogramming library for physics calculations
//
// Copyright (C) 2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301  USA
//
//-----------------------------------------------------------------------el-
//
// $Id: core.h 37197 2013-02-21 05:49:09Z roystgnr $
//
//--------------------------------------------------------------------------


#ifndef METAPHYSICL_DYNAMICSPARSENUMBERBASE_H
#define METAPHYSICL_DYNAMICSPARSENUMBERBASE_H

#include "metaphysicl/dynamicsparsenumberbase_decl.h"

namespace MetaPhysicL {

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::size_t
DynamicSparseNumberBase<T,I,SubType>::size() const
{ metaphysicl_assert_equal_to(_data.size(), _indices.size());
  return _data.size(); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
void
DynamicSparseNumberBase<T,I,SubType>::resize(std::size_t s)
{ metaphysicl_assert_equal_to(_data.size(), _indices.size());
  _data.resize(s);
  _indices.resize(s); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
DynamicSparseNumberBase<T,I,SubType>::DynamicSparseNumberBase() {}

template <typename T, typename I, template <typename, typename> class SubType>
template <typename T2, typename I2>
inline
DynamicSparseNumberBase<T,I,SubType>::DynamicSparseNumberBase(const DynamicSparseNumberBase<T2, I2, SubType> & src)
{ this->resize(src.size());
  std::copy(src.nude_data().begin(), src.nude_data().end(), _data.begin());
  std::copy(src.nude_indices().begin(), src.nude_indices().end(), _indices.begin()); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
T*
DynamicSparseNumberBase<T,I,SubType>::raw_data()
{ return size()?&_data[0]:NULL; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const T*
DynamicSparseNumberBase<T,I,SubType>::raw_data() const
{ return size()?&_data[0]:NULL; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
typename std::vector<T>::reference
DynamicSparseNumberBase<T,I,SubType>::raw_at(unsigned int i)
{ return _data[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
typename std::vector<T>::const_reference
DynamicSparseNumberBase<T,I,SubType>::raw_at(unsigned int i) const
{ return _data[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
I&
DynamicSparseNumberBase<T,I,SubType>::raw_index(unsigned int i)
{ return _indices[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const I&
DynamicSparseNumberBase<T,I,SubType>::raw_index(unsigned int i) const
{ return _indices[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const std::vector<T>&
DynamicSparseNumberBase<T,I,SubType>::nude_data() const
{ return _data; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::vector<T>&
DynamicSparseNumberBase<T,I,SubType>::nude_data()
{ return _data; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const std::vector<I>&
DynamicSparseNumberBase<T,I,SubType>::nude_indices() const
{ return _indices; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::vector<I>&
DynamicSparseNumberBase<T,I,SubType>::nude_indices()
{ return _indices; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::size_t
DynamicSparseNumberBase<T,I,SubType>::runtime_index_query(index_value_type i) const
{
  typename std::vector<I>::const_iterator it =
    std::lower_bound(_indices.begin(), _indices.end(), i);
  if (it == _indices.end() || *it != i)
    return std::numeric_limits<std::size_t>::max();
  std::size_t offset = it - _indices.begin();
  metaphysicl_assert_equal_to(_indices[offset], i);
  return offset;
}

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::size_t
DynamicSparseNumberBase<T,I,SubType>::runtime_index_of(index_value_type i) const
{
  typename std::vector<I>::const_iterator it =
    std::lower_bound(_indices.begin(), _indices.end(), i);
  metaphysicl_assert(it != _indices.end());
  std::size_t offset = it - _indices.begin();
  metaphysicl_assert_equal_to(_indices[offset], i);
  return offset;
}

template <typename T, typename I, template <typename, typename> class SubType>
inline
T&
DynamicSparseNumberBase<T,I,SubType>::operator[](index_value_type i)
{ return _data[runtime_index_of(i)]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const T&
DynamicSparseNumberBase<T,I,SubType>::operator[](index_value_type i) const
{ return _data[runtime_index_of(i)]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline<commit_msg>Allow const operator[] of entries outside sparsity<commit_after>//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
// 
// MetaPhysicL - A metaprogramming library for physics calculations
//
// Copyright (C) 2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301  USA
//
//-----------------------------------------------------------------------el-
//
// $Id: core.h 37197 2013-02-21 05:49:09Z roystgnr $
//
//--------------------------------------------------------------------------


#ifndef METAPHYSICL_DYNAMICSPARSENUMBERBASE_H
#define METAPHYSICL_DYNAMICSPARSENUMBERBASE_H

#include "metaphysicl/dynamicsparsenumberbase_decl.h"

namespace MetaPhysicL {

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::size_t
DynamicSparseNumberBase<T,I,SubType>::size() const
{ metaphysicl_assert_equal_to(_data.size(), _indices.size());
  return _data.size(); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
void
DynamicSparseNumberBase<T,I,SubType>::resize(std::size_t s)
{ metaphysicl_assert_equal_to(_data.size(), _indices.size());
  _data.resize(s);
  _indices.resize(s); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
DynamicSparseNumberBase<T,I,SubType>::DynamicSparseNumberBase() {}

template <typename T, typename I, template <typename, typename> class SubType>
template <typename T2, typename I2>
inline
DynamicSparseNumberBase<T,I,SubType>::DynamicSparseNumberBase(const DynamicSparseNumberBase<T2, I2, SubType> & src)
{ this->resize(src.size());
  std::copy(src.nude_data().begin(), src.nude_data().end(), _data.begin());
  std::copy(src.nude_indices().begin(), src.nude_indices().end(), _indices.begin()); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
T*
DynamicSparseNumberBase<T,I,SubType>::raw_data()
{ return size()?&_data[0]:NULL; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const T*
DynamicSparseNumberBase<T,I,SubType>::raw_data() const
{ return size()?&_data[0]:NULL; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
typename std::vector<T>::reference
DynamicSparseNumberBase<T,I,SubType>::raw_at(unsigned int i)
{ return _data[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
typename std::vector<T>::const_reference
DynamicSparseNumberBase<T,I,SubType>::raw_at(unsigned int i) const
{ return _data[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
I&
DynamicSparseNumberBase<T,I,SubType>::raw_index(unsigned int i)
{ return _indices[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const I&
DynamicSparseNumberBase<T,I,SubType>::raw_index(unsigned int i) const
{ return _indices[i]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const std::vector<T>&
DynamicSparseNumberBase<T,I,SubType>::nude_data() const
{ return _data; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::vector<T>&
DynamicSparseNumberBase<T,I,SubType>::nude_data()
{ return _data; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const std::vector<I>&
DynamicSparseNumberBase<T,I,SubType>::nude_indices() const
{ return _indices; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::vector<I>&
DynamicSparseNumberBase<T,I,SubType>::nude_indices()
{ return _indices; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::size_t
DynamicSparseNumberBase<T,I,SubType>::runtime_index_query(index_value_type i) const
{
  typename std::vector<I>::const_iterator it =
    std::lower_bound(_indices.begin(), _indices.end(), i);
  if (it == _indices.end() || *it != i)
    return std::numeric_limits<std::size_t>::max();
  std::size_t offset = it - _indices.begin();
  metaphysicl_assert_equal_to(_indices[offset], i);
  return offset;
}

template <typename T, typename I, template <typename, typename> class SubType>
inline
std::size_t
DynamicSparseNumberBase<T,I,SubType>::runtime_index_of(index_value_type i) const
{
  typename std::vector<I>::const_iterator it =
    std::lower_bound(_indices.begin(), _indices.end(), i);
  metaphysicl_assert(it != _indices.end());
  std::size_t offset = it - _indices.begin();
  metaphysicl_assert_equal_to(_indices[offset], i);
  return offset;
}

template <typename T, typename I, template <typename, typename> class SubType>
inline
T&
DynamicSparseNumberBase<T,I,SubType>::operator[](index_value_type i)
{ return this->query(i); }

template <typename T, typename I, template <typename, typename> class SubType>
inline
const T&
DynamicSparseNumberBase<T,I,SubType>::operator[](index_value_type i) const
{ return _data[runtime_index_of(i)]; }

template <typename T, typename I, template <typename, typename> class SubType>
inline
{'fraction_non_alphanumeric': 0.16988483851415706, 'fraction_numerical': 0.0072733570006061135, 'mean_word_length': 4.6506849315068495, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6038394', 'n_tokens_mistral': 3588, 'n_tokens_neox': 3423, 'n_words': 989}