<commit_before>///
/// @file  prime_iterator.cpp
///
/// Copyright (C) 2013 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include <primesieve.h>
#include <primesieve/soe/prime_iterator.h>

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <vector>

namespace {

enum {
  MEGABYTE = 1 << 20
};

/// Estimate interval size based on number of primes.
/// @param n       start or stop number.
/// @param primes  Number of primes to generate.
///
uint64_t get_interval_size(uint64_t n, std::size_t primes)
{
  const uint64_t MIN_INTERVAL = 1 << 16;
  n = std::max(n, static_cast<uint64_t>(primes * 20));
  double dn = static_cast<double>(n);
  double logn = std::log(dn);
  uint64_t interval_size = static_cast<uint64_t>(primes * logn);
  return std::max(MIN_INTERVAL, interval_size);
}

} // end namespace

namespace primesieve {

prime_iterator::prime_iterator(uint64_t start, std::size_t cache_size) :
  i_(0),
  cache_size_(cache_size),
  start_(start),
  first_(true)
{
  if (cache_size_ < 1)
    cache_size_ = 1;
  if (cache_size_ > 128)
    cache_size_ = 128;

  max_size_ = (cache_size_ * MEGABYTE) / sizeof(uint64_t);
  uint64_t interval_size = get_interval_size(start_, max_size_);
  uint64_t mid = interval_size / 2;
  uint64_t begin = (start_ > mid) ? start_ - mid : 0;
<commit_msg>Increased memory limit to 1 gigabyte.<commit_after>///
/// @file  prime_iterator.cpp
///
/// Copyright (C) 2013 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include <primesieve.h>
#include <primesieve/soe/prime_iterator.h>

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <vector>

namespace {

enum {
  MEGABYTE = 1 << 20
};

/// Estimate interval size based on number of primes.
/// @param n       start or stop number.
/// @param primes  Number of primes to generate.
///
uint64_t get_interval_size(uint64_t n, std::size_t primes)
{
  const uint64_t MIN_INTERVAL = 1 << 16;
  n = std::max(n, static_cast<uint64_t>(primes) * 20);
  double dn = static_cast<double>(n);
  double logn = std::log(dn);
  uint64_t interval_size = static_cast<uint64_t>(primes * logn);
  return std::max(MIN_INTERVAL, interval_size);
}

} // end namespace

namespace primesieve {

prime_iterator::prime_iterator(uint64_t start, std::size_t cache_size) :
  i_(0),
  cache_size_(cache_size),
  start_(start),
  first_(true)
{
  if (cache_size_ < 1)
    cache_size_ = 1;
  if (cache_size_ > 1024)
    cache_size_ = 1024;

  max_size_ = (cache_size_ * MEGABYTE) / sizeof(uint64_t);
  uint64_t interval_size = get_interval_size(start_, max_size_);
  uint64_t mid = interval_size / 2;
  uint64_t begin = (start_ > mid) ? start_ - mid : 0;

{'fraction_non_alphanumeric': 0.13728932584269662, 'fraction_numerical': 0.032654494382022475, 'mean_word_length': 3.87008547008547, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 33, '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': '5972038', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1037, 'n_words': 271}