<commit_before>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
// and <NAME>
//
// Licensed 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.

#pragma once
#ifndef UTIL_FIXEDVEC_HPP
#define UTIL_FIXEDVEC_HPP

/**
 * High performance no-heap fixed vector
 * All data is reserved uninitialized
 **/

#include <cstdint>
#include <cstring>

enum class Fixedvector_Init {
  UNINIT
};

template <typename T, int N>
struct fixedvector {
  fixedvector() : count(0) {}
  fixedvector(Fixedvector_Init) {}

  // add existing
  T& add(const T& e) noexcept {
    (*this)[count] = e;
    return (*this)[count++];
  }
  // construct into
  template <typename... Args>
  T& emplace(Args&&... args) noexcept {
    new (&element[count]) T(args...);
    return (*this)[count++];
  }

  // pop back and return last element
  T pop() {
    return (*this)[--count];
  }<commit_msg>util: Add assertions to add/emplace for fixed_vector<commit_after>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
// and <NAME>
//
// Licensed 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.

#pragma once
#ifndef UTIL_FIXEDVEC_HPP
#define UTIL_FIXEDVEC_HPP

/**
 * High performance no-heap fixed vector
 * All data is reserved uninitialized
 **/

#include <cstdint>
#include <cstring>
#include <cassert>

enum class Fixedvector_Init {
  UNINIT
};

template <typename T, int N>
struct fixedvector {
  fixedvector() : count(0) {}
  fixedvector(Fixedvector_Init) {}

  // add existing
  T& add(const T& e) noexcept {
    assert(count < N);
    (*this)[count] = e;
    return (*this)[count++];
  }
  // construct into
  template <typename... Args>
  T& emplace(Args&&... args) noexcept {
    assert(count < N);
    new (&element[count]) T(args...);
    return (*this)[count++];
  }

  // pop back and return last element
  T pop() {
    return (*this)[--count];
  }
{'fraction_non_alphanumeric': 0.11934840425531915, 'fraction_numerical': 0.005984042553191489, 'mean_word_length': 3.373546511627907, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3059668', 'n_tokens_mistral': 911, 'n_tokens_neox': 882, 'n_words': 352}