/* Betrand's Postulate (or Chebyshev's theorem) states that if n > 3, *thereisalwaysatleastoneprimepbetweennand2n-2. *Equivalently,ifn>1,thenthereisalwaysatleastoneprimep *suchthatn<p<2n. * *http://mathworld.wolfram.com/BertrandsPostulate.html *https://en.wikipedia.org/wiki/Bertrand's_postulate
*/
sz = 2 * x; if (sz < x) returnfalse;
sz = round_up(sz, BITS_PER_LONG); new = kmalloc(sizeof(*new) + bitmap_size(sz),
GFP_KERNEL | __GFP_NOWARN); if (!new) returnfalse;
mutex_lock(&lock);
p = rcu_dereference_protected(primes, lockdep_is_held(&lock)); if (x < p->last) {
kfree(new); goto unlock;
}
/* Where memory permits, track the primes using the *SieveofEratosthenes.Thesieveistoremoveallmultiplesofknown *primesfromtheset,whatremainsinthesetisthereforeprime.
*/
bitmap_fill(new->primes, sz);
bitmap_copy(new->primes, p->primes, p->sz); for (y = 2UL; y < sz; y = find_next_bit(new->primes, sz, y + 1)) new->last = clear_multiples(y, new->primes, p->sz, sz); new->sz = sz;
BUG_ON(new->last <= x);
rcu_assign_pointer(primes, new); if (p != &small_primes)
kfree_rcu((struct primes *)p, rcu);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.