-
Notifications
You must be signed in to change notification settings - Fork 30
/
prime.h
53 lines (46 loc) · 1.17 KB
/
prime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file prime.h
*
* @author hutusi ([email protected])
*
* @brief Prime number calculation.
*
* @date 2019-07-21
*
* @copyright Copyright (c) 2019, hutusi.com
*
*/
#ifndef RETHINK_C_PRIME_H
#define RETHINK_C_PRIME_H
#include "bitmap.h"
/**
* @brief Sieve the prime numbers less than or equal to specific max number.
*
* @param max_number The max number.
* @return BitMap* The sieve bitmap.
*/
BitMap *prime_number_sieve(unsigned int max_number);
/**
* @brief Check if a number is prime number.
*
* Need call prime_number_sieve to get the sieve bitmap first.
*
* @param sieve The prime sieve bitmap.
* @param number The number.
* @return int 1 if prime, otherwise 0.
*/
int prime_number_sieve_check(const BitMap *sieve, unsigned int number);
/**
* @brief Count the amount of all prime numbers in a prime sieve.
*
* @param sieve The sieve.
* @return unsigned int The amount.
*/
unsigned int prime_number_sieve_count(const BitMap *sieve);
/**
* @brief Delete a prime sieve and free back memory.
*
* @param sieve The prime sieve.
*/
void prime_number_sieve_free(BitMap *sieve);
#endif /* #ifndef RETHINK_C_PRIME_H */