<commit_before>// Copyright (c) 2010-2021, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#ifndef MFEM_ARRAY
#define MFEM_ARRAY

#include "../config/config.hpp"
#include "mem_manager.hpp"
#include "device.hpp"
#include "error.hpp"
#include "globals.hpp"

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <type_traits>

namespace mfem
{

template <class T>
class Array;

template <class T>
void Swap(Array<T> &, Array<T> &);

/**
   Abstract data type Array.

   Array<T> is an automatically increasing array containing elements of the
   generic type T, which must be a trivial type, see `std::is_trivial`. The
   allocated size may be larger then the logical size of the array. The elements
   can be accessed by the [] operator, the range is 0 to size-1.
*/
template <class T>
class Array
{
protected:
   /// Pointer to data
   Memory<T> data;
   /// Size of the array
   int size;

   inline void GrowSize(int minsize);

   static inline void TypeAssert()
   {
      static_assert(std::is_trivial<T>::value, "type T must be trivial");
   }

public:
   friend void Swap<T>(Array<T> &, Array<T> &);

   /// Creates an empty array
   inline Array() : size(0) { data.Reset(); }

   /// Creates an empty array with a given MemoryType
   inline Array(MemoryType mt) : size(0) { data.Reset(mt); }

   /// Creates array of @a asize elements
   explicit inline Array(int asize)
      : size(asize) { asize > 0 ? data.New(asize) : data.Reset(); }

   /** @brief Creates array using an existing c-array of asize elements;
       allocsize is set to -asize to indicate that the data will not
       be deleted. */
   inline Array(T *data_, int asize)
   { data.Wrap(data_, asize, false); size = asize; }

   /// Copy constructor: deep copy from @a src
   /** This method supports source arrays using any MemoryType. */<commit_msg>add new ctor to array that takes a size and a memorytype<commit_after>// Copyright (c) 2010-2021, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#ifndef MFEM_ARRAY
#define MFEM_ARRAY

#include "../config/config.hpp"
#include "mem_manager.hpp"
#include "device.hpp"
#include "error.hpp"
#include "globals.hpp"

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <type_traits>

namespace mfem
{

template <class T>
class Array;

template <class T>
void Swap(Array<T> &, Array<T> &);

/**
   Abstract data type Array.

   Array<T> is an automatically increasing array containing elements of the
   generic type T, which must be a trivial type, see `std::is_trivial`. The
   allocated size may be larger then the logical size of the array. The elements
   can be accessed by the [] operator, the range is 0 to size-1.
*/
template <class T>
class Array
{
protected:
   /// Pointer to data
   Memory<T> data;
   /// Size of the array
   int size;

   inline void GrowSize(int minsize);

   static inline void TypeAssert()
   {
      static_assert(std::is_trivial<T>::value, "type T must be trivial");
   }

public:
   friend void Swap<T>(Array<T> &, Array<T> &);

   /// Creates an empty array
   inline Array() : size(0) { data.Reset(); }

   /// Creates an empty array with a given MemoryType
   inline Array(MemoryType mt) : size(0) { data.Reset(mt); }

   /// Creates array of @a asize elements
   explicit inline Array(int asize)
      : size(asize) { asize > 0 ? data.New(asize) : data.Reset(); }

   /// Creates array of @a asize elements with a given MemoryType
   inline Array(int asize, MemoryType mt)
      : size(asize) { asize > 0 ? data.New(asize, mt) : data.Reset(mt); }

   /** @brief Creates array using an existing c-array of asize elements;
       allocsize is set to -asize to indicate that the data will not
       be deleted. */
   inline Array(T *data_, int asize)
   { data.Wrap(data_, asize, false); size = asize; }

   /// Copy constructor: deep copy from @a src
   /** This method supports source arrays using any MemoryType. */
{'fraction_non_alphanumeric': 0.11026380873866447, 'fraction_numerical': 0.008450123660346249, 'mean_word_length': 3.3563734290843805, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 38, 'https://': 2, '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': '718860', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1441, 'n_words': 596}