(git:374b731)
Loading...
Searching...
No Matches
qs_hash_table_functions.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Functions which are common to different hash tables
10!> Derived from qs_fb_hash_table_types and qs_fb_hash_table_types (Mark Tucker, Jun 2016)
11! **************************************************************************************************
13
14#include "./base/base_uses.f90"
15 IMPLICIT NONE
16
17 PRIVATE
18
19! public methods
21
22 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_hash_table_functions'
23
24CONTAINS
25
26! **************************************************************************************************
27!> \brief Find a prime number equal or larger than ii
28!> \param ii : input integer
29!> \return : the prime number
30! **************************************************************************************************
31 PURE FUNCTION hash_table_matching_prime(ii) RESULT(res)
32 INTEGER, INTENT(IN) :: ii
33 INTEGER :: res
34
35 ! even numbers are not prime, so no point testing them, so increment by 2 each time starting
36 ! from an odd number greater or equal to ii (as noted in \brief)
37 res = ii + 1 - mod(ii, 2)
38
39 DO WHILE (.NOT. is_positive_prime(res))
40 res = res + 2
41 END DO
42 END FUNCTION hash_table_matching_prime
43
44! **************************************************************************************************
45!> \brief Check if a number is a positive prime
46!> \param num : number to check
47!> \return : returns TRUE if num is a positive prime, FALSE otherwise
48!> \author Lianheng Tong (LT) lianheng.tong@kcl.ac.uk
49! **************************************************************************************************
50 PURE FUNCTION is_positive_prime(num) RESULT(res)
51 INTEGER, INTENT(IN) :: num
52 LOGICAL :: res
53
54 INTEGER :: ii
55
56 IF (num .LE. 3) THEN
57 res = .false.
58 RETURN
59 END IF
60 IF (mod(num, 2) == 0 .OR. mod(num, 3) == 0) THEN
61 res = .false.
62 RETURN
63 END IF
64
65 ! all primes > 3 are of the form 6*kk +/- 1, kk=1,2,3...
66 ! (although not all 6*kk +/- 1 is a prime);
67 ! and we only have to check factors less than and equal to SQRT(num)
68 ii = 5
69 DO WHILE (ii*ii .LE. num)
70 IF (mod(num, ii) == 0 .OR. mod(num, ii + 2) == 0) THEN
71 res = .false.
72 RETURN
73 END IF
74 ii = ii + 6
75 END DO
76 res = .true.
77 END FUNCTION is_positive_prime
78
80
Functions which are common to different hash tables Derived from qs_fb_hash_table_types and qs_fb_has...
pure integer function, public hash_table_matching_prime(ii)
Find a prime number equal or larger than ii.