[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime
From: |
G. Branden Robinson |
Subject: |
Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n |
Date: |
Wed, 13 Mar 2024 05:45:10 -0500 |
Hi Alex,
At 2024-03-13T11:21:55+0100, Alejandro Colomar wrote:
> And use it where the same logic was being open-coded.
>
> While at it, fix the logic, which was incorrect in the open-coded call
> sites, since for an input of 1, it produced 3, but the first prime is 2.
Are you sure? That sounds like the bug I already fixed (but have not
yet pushed).
My working copy, complete with the following debugging output, is
attached.
$ ./build/indxbib -h 1
./build/indxbib: fatal error: argument to -h must not be less than 2
$ ./build/indxbib -h 2
./build/indxbib: debug: using hash table size of 2
./build/indxbib: fatal error: no files and no -f option
$ ./build/indxbib -h 3
./build/indxbib: debug: using hash table size of 3
./build/indxbib: fatal error: no files and no -f option
$ ./build/indxbib -h 4
./build/indxbib: warning: requested hash table size 4 is not prime: using 5
instead
./build/indxbib: debug: using hash table size of 5
./build/indxbib: fatal error: no files and no -f option
> Also, since this is a library function, let's behave well for an input
> of 0, and return also the first prime, 2.
I'm skeptical of adding a library function for this purpose (finding the
smallest prime number equal to or greater than the input integer) when
it _has_ no other call sites.
In fact, the only other caller of is_prime() itself is in libbib, where
it's not operating on a user-supplied parameter (as in a user of the
running process).
https://git.savannah.gnu.org/cgit/groff.git/tree/src/libs/libbib/index.cpp?h=1.23.0#n603
Wouldn't it be more idiomatic C++ to migrate libbib to an STL container?
(Not that I'm saying you should do that.)
Regards,
Branden
signature.asc
Description: PGP signature
- [PATCH] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, Alejandro Colomar, 2024/03/13
- [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, Alejandro Colomar, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n,
G. Branden Robinson <=
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, G. Branden Robinson, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, Alejandro Colomar, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, G. Branden Robinson, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, Alejandro Colomar, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, James K. Lowden, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, G. Branden Robinson, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, James K. Lowden, 2024/03/13
- Re: [PATCH v2] src/: ceil_prime(): Add function to get the lowest prime not smaller than n, Alejandro Colomar, 2024/03/13
[PATCH v3 2/9] [libgroff]: Remove dead code, Alejandro Colomar, 2024/03/15
[PATCH v3 3/9] src/: Remove redundant checks after strtol(3)., Alejandro Colomar, 2024/03/15