LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
prime_pool.h 文件参考
#include "support/perf.h"
#include "lmmp/lmmpn.h"
#include "lmmp/numth.h"
prime_pool.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

枚举

enum  { POOL = 512 }
enum  PrimePool { PRIME_POOL_ODD , PRIME_POOL_PRIME , PRIME_POOL_COPRIME }
 Copyright (C) 2026 HJimmyK (Jericho Knox) 更多...

函数

static int pool_cnt (mp_size_t n)
static mp_ptr pool_n (mp_size_t n, int cnt, mp_limb_t seed, PrimePool kind)
static bool small_factor_q (mp_srcptr x, mp_size_t n)
 COPRIME 输入池的预筛

枚举类型说明

◆ anonymous enum

anonymous enum
枚举值
POOL 512 

在文件 prime_pool.h 第 43 行定义.

43{ POOL = 512 };
@ POOL

◆ PrimePool

enum PrimePool

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

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, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

枚举值
PRIME_POOL_ODD 
PRIME_POOL_PRIME 
PRIME_POOL_COPRIME 

在文件 prime_pool.h 第 41 行定义.

PrimePool
Copyright (C) 2026 HJimmyK (Jericho Knox)
@ PRIME_POOL_PRIME
@ PRIME_POOL_ODD
@ PRIME_POOL_COPRIME

函数说明

◆ pool_cnt()

int pool_cnt ( mp_size_t n)
inlinestatic

在文件 prime_pool.h 第 45 行定义.

45{ return n <= 64 ? 32 : 8; }
#define n

引用了 n.

◆ pool_n()

mp_ptr pool_n ( mp_size_t n,
int cnt,
mp_limb_t seed,
PrimePool kind )
inlinestatic

在文件 prime_pool.h 第 68 行定义.

68 {
69 mp_ptr a = alloc_limbs((size_t)n * cnt);
70 for (int i = 0; i < cnt; i++) {
71 mp_ptr cur = a + n * i;
72 lmmp_seed_random_(cur, n, seed + i * 131, 1);
73 cur[n - 1] |= (mp_limb_t)1 << 63;
74 cur[0] |= 1;
75 if (kind == PRIME_POOL_COPRIME) {
76 while (small_factor_q(cur, n)) cur[0] += 2;
77 } else if (kind == PRIME_POOL_PRIME) {
78 while (lmmp_is_prime_n_(cur, n, 4) == 0) cur[0] += 2;
79 }
80 }
81 return a;
82}
mp_limb_t * mp_ptr
定义 lmmp.h:96
uint64_t mp_limb_t
定义 lmmp.h:92
mp_size_t lmmp_seed_random_(mp_ptr dst, mp_size_t n, mp_limb_t seed, unsigned seed_type)
生成随机大整数(0 - B^n-1 均匀分布)
int lmmp_is_prime_n_(mp_srcptr np, mp_size_t nn, int strength)
大整数素性检验(强度分档,大于 128 位)
static bool small_factor_q(mp_srcptr x, mp_size_t n)
COPRIME 输入池的预筛

引用了 lmmp_is_prime_n_(), lmmp_seed_random_(), n, PRIME_POOL_COPRIME, PRIME_POOL_PRIME , 以及 small_factor_q().

函数调用图:

◆ small_factor_q()

bool small_factor_q ( mp_srcptr x,
mp_size_t n )
inlinestatic

COPRIME 输入池的预筛

注解
与 <=1000 素数之积取 gcd,gcd!=1 等价于存在 <=1000 素因子(池元素 恒奇,素数 2 无关)

在文件 prime_pool.h 第 52 行定义.

52 {
53 static mp_ptr pr = NULL;
54 static mp_size_t prn = 0;
55 if (pr == NULL) {
56 mp_size_t need = lmmp_primefac_size_(1000);
57 pr = alloc_limbs(need);
58 prn = lmmp_primefac_(pr, need, 1000);
59 }
60 mp_ptr g = alloc_limbs(prn);
61 mp_size_t gn = (n >= prn) ? lmmp_gcd_(g, x, n, pr, prn) : lmmp_gcd_(g, pr, prn, x, n);
62 bool has = !(gn == 1 && g[0] == 1);
63 lmmp_free(g);
64 return has;
65}
uint64_t mp_size_t
定义 lmmp.h:93
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
mp_size_t lmmp_primefac_size_(uint n)
计算质数阶乘的 limb 缓冲区长度
mp_size_t lmmp_gcd_(mp_ptr dst, mp_srcptr up, mp_size_t un, mp_srcptr vp, mp_size_t vn)
计算两个无符号整数的最大公约数(通用分发入口)
定义 gcd.c:27
mp_size_t lmmp_primefac_(mp_ptr dst, mp_size_t rn, uint n)
计算质数阶乘(不超过n的质数累乘)

引用了 lmmp_free(), lmmp_gcd_(), lmmp_primefac_(), lmmp_primefac_size_() , 以及 n.

被这些函数引用 pool_n().

函数调用图:
这是这个函数的调用关系图: