From d6c23d791465a94b737460ccbe5098cc6772cd38 Mon Sep 17 00:00:00 2001 From: JulStrat Date: Tue, 7 Jul 2020 12:39:09 +0300 Subject: [PATCH] API docs --- README.md | 12 +- docs/AllClasses.html | 28 + docs/AllConstants.html | 118 ++++ docs/AllFunctions.html | 47 ++ docs/AllIdentifiers.html | 304 +++++++++++ docs/AllTypes.html | 18 + docs/AllUnits.html | 32 ++ docs/AllVariables.html | 180 +++++++ docs/ClassHierarchy.html | 18 + docs/automated.gif | Bin 0 -> 141 bytes docs/index.html | 32 ++ docs/legend.html | 54 ++ docs/pasdoc.css | 203 +++++++ docs/primesieve.html | 656 +++++++++++++++++++++++ docs/primesieve.primesieve_iterator.html | 25 + docs/private.gif | Bin 0 -> 141 bytes docs/protected.gif | Bin 0 -> 141 bytes docs/public.gif | Bin 0 -> 141 bytes docs/published.gif | Bin 0 -> 141 bytes primesieve.pas | 337 ++++++------ 20 files changed, 1910 insertions(+), 154 deletions(-) create mode 100644 docs/AllClasses.html create mode 100644 docs/AllConstants.html create mode 100644 docs/AllFunctions.html create mode 100644 docs/AllIdentifiers.html create mode 100644 docs/AllTypes.html create mode 100644 docs/AllUnits.html create mode 100644 docs/AllVariables.html create mode 100644 docs/ClassHierarchy.html create mode 100644 docs/automated.gif create mode 100644 docs/index.html create mode 100644 docs/legend.html create mode 100644 docs/pasdoc.css create mode 100644 docs/primesieve.html create mode 100644 docs/primesieve.primesieve_iterator.html create mode 100644 docs/private.gif create mode 100644 docs/protected.gif create mode 100644 docs/public.gif create mode 100644 docs/published.gif diff --git a/README.md b/README.md index 1b6375c..21bd4da 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,22 @@ Pascal bindings for [PrimeSieve](https://github.com/kimwalisch/primesieve) library. -# Requirements +## Pascal API documentation + +https://julstrat.github.io/primesieve-pas/ + +Documentation generated with [PasDoc](https://github.com/pasdoc/pasdoc). + +## Requirements Install ```primesieve``` library. - Ubuntu - ```sudo apt install libprimesieve-dev```. - MacOS - ```brew install primesieve```. -- Windows - you can use [libprimesieve.dll](https://github.com/JulStrat/primesieve-pas/tree/loadlib/libprimesieve). +- Windows - you can use [libprimesieve.dll](https://github.com/JulStrat/primesieve-pas/tree/loadlib/libprimesieve) built with MinGW. - Or [build](https://github.com/kimwalisch/primesieve/blob/master/BUILD.md) library from source. -# Usage +## Usage ``` (** @example store_primes_in_array.pas * Store primes in a array. *) diff --git a/docs/AllClasses.html b/docs/AllClasses.html new file mode 100644 index 0000000..c17ab90 --- /dev/null +++ b/docs/AllClasses.html @@ -0,0 +1,28 @@ + + + +primesieve-pas: All Classes, Interfaces, Objects and Records + + + + + + +
+

All Classes, Interfaces, Objects and Records

+ + + + + + + + + + + +
NameUnitDescription
primesieve_iteratorprimesieve

 

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/AllConstants.html b/docs/AllConstants.html new file mode 100644 index 0000000..2990a95 --- /dev/null +++ b/docs/AllConstants.html @@ -0,0 +1,118 @@ + + + +primesieve-pas: All Constants + + + + + + +
+

All Constants

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameUnitDescription
INT16_PRIMESprimesieve

Generate primes of int16_t type

INT32_PRIMESprimesieve

Generate primes of int32_t type

INT64_PRIMESprimesieve

Generate primes of int64_t type

INT_PRIMESprimesieve

Generate primes of int type

LONGLONG_PRIMESprimesieve

Generate primes of long long type

LONG_PRIMESprimesieve

Generate primes of long type

SHORT_PRIMESprimesieve

Generate primes of short type

UINT16_PRIMESprimesieve

Generate primes of uint16_t type

UINT32_PRIMESprimesieve

Generate primes of uint32_t type

UINT64_PRIMESprimesieve

Generate primes of uint64_t type

UINT_PRIMESprimesieve

Generate primes of unsigned int type

ULONGLONG_PRIMESprimesieve

Generate primes of unsigned long long type

ULONG_PRIMESprimesieve

Generate primes of unsigned long type

USHORT_PRIMESprimesieve

Generate primes of unsigned short type

_PRIMESIEVE_ERRORprimesieve

primesieve functions return PRIMESIEVE_ERROR (UINT64_MAX) if any error occurs.

_PRIMESIEVE_PAS_VERSIONprimesieve

 

_PRIMESIEVE_VERSIONprimesieve

 

_PRIMESIEVE_VERSION_MAJORprimesieve

 

_PRIMESIEVE_VERSION_MINORprimesieve

 

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/AllFunctions.html b/docs/AllFunctions.html new file mode 100644 index 0000000..837c4af --- /dev/null +++ b/docs/AllFunctions.html @@ -0,0 +1,47 @@ + + + +primesieve-pas: All Functions and Procedures + + + + + + +
+

All Functions and Procedures

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
NameUnitDescription
load_libprimesieveprimesieve

Loads primesieve library.

primesieve_next_primeprimesieve

Get the next prime. + +

Returns UINT64_MAX if next prime > 2ˆ64.

primesieve_prev_primeprimesieve

Get the previous prime. + +

primesieve_prev_prime(n) returns 0 for n <= 2. Note that primesieve_next_prime() runs up to 2x faster than primesieve_prev_prime(). Hence if the same algorithm can be written using either primesieve_prev_prime() or primesieve_next_prime() it is preferable to use primesieve_next_prime().

unload_libprimesieveprimesieve

Unoads primesieve library.

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/AllIdentifiers.html b/docs/AllIdentifiers.html new file mode 100644 index 0000000..14630d7 --- /dev/null +++ b/docs/AllIdentifiers.html @@ -0,0 +1,304 @@ + + + +primesieve-pas: All Identifiers + + + + + + +
+

All Identifiers

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameUnitDescription
INT16_PRIMESprimesieve

Generate primes of int16_t type

INT32_PRIMESprimesieve

Generate primes of int32_t type

INT64_PRIMESprimesieve

Generate primes of int64_t type

INT_PRIMESprimesieve

Generate primes of int type

load_libprimesieveprimesieve

Loads primesieve library.

LONGLONG_PRIMESprimesieve

Generate primes of long long type

LONG_PRIMESprimesieve

Generate primes of long type

primesieve_count_primesprimesieve

Count the primes within the interval [start, stop]. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads. + +

Note that each call to primesieve_count_primes() incurs an initialization overhead of O(sqrt(stop)) even if the interval [start, stop] is tiny. Hence if you have written an algorithm that makes many calls to primesieve_count_primes() it may be preferable to use a primesieve::iterator which needs to be initialized only once.

primesieve_count_quadrupletsprimesieve

Count the prime quadruplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_quintupletsprimesieve

Count the prime quintuplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_sextupletsprimesieve

Count the prime sextuplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_tripletsprimesieve

Count the prime triplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_twinsprimesieve

Count the twin primes within the interval [start, stop]. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_freeprimesieve

Deallocate a primes array created using the primesieve_generate_primes() or primesieve_generate_n_primes() functions.

primesieve_free_iteratorprimesieve

Free all memory

primesieve_generate_n_primesprimesieve

Get an array with the first n primes >= start. + +

ptype - The type of the primes to generate, e.g. INT_PRIMES.

primesieve_generate_primesprimesieve

Get an array with the primes inside the interval [start, stop]. + +

size - The size of the returned primes array.
ptype - The type of the primes to generate, e.g. INT_PRIMES.

primesieve_get_max_stopprimesieve

Returns the largest valid stop number for primesieve. + +

+ +
2ˆ64-1 (UINT64_MAX)
+ +

primesieve_get_num_threadsprimesieve

Get the current set number of threads

primesieve_get_sieve_sizeprimesieve

Get the current set sieve size in KiB

primesieve_initprimesieve

Initialize the primesieve iterator before first using it

primesieve_iteratorprimesieve

 

primesieve_next_primeprimesieve

Get the next prime. + +

Returns UINT64_MAX if next prime > 2ˆ64.

primesieve_nth_primeprimesieve

Find the nth prime. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads. + +

Note that each call to primesieve_nth_prime(n, start) incurs an initialization overhead of O(sqrt(start)) even if n is tiny. Hence it is not a good idea to use primesieve_nth_prime() repeatedly in a loop to get the next (or previous) prime. For this use case it is better to use a primesieve::iterator which needs to be initialized only once. + +

if n = 0 finds the 1st prime >= start,
if n > 0 finds the nth prime > start,
if n < 0 finds the nth prime < start (backwards).

primesieve_prev_primeprimesieve

Get the previous prime. + +

primesieve_prev_prime(n) returns 0 for n <= 2. Note that primesieve_next_prime() runs up to 2x faster than primesieve_prev_prime(). Hence if the same algorithm can be written using either primesieve_prev_prime() or primesieve_next_prime() it is preferable to use primesieve_next_prime().

primesieve_print_primesprimesieve

Print the primes within the interval [start, stop] to the standard output.

primesieve_print_quadrupletsprimesieve

Print the prime quadruplets within the interval [start, stop] to the standard output.

primesieve_print_quintupletsprimesieve

Print the prime quintuplets within the interval [start, stop] to the standard output.

primesieve_print_sextupletsprimesieve

Print the prime sextuplets within the interval [start, stop] to the standard output.

primesieve_print_tripletsprimesieve

Print the prime triplets within the interval [start, stop] to the standard output.

primesieve_print_twinsprimesieve

Print the twin primes within the interval [start, stop] to the standard output.

primesieve_set_num_threadsprimesieve

Set the number of threads for use in primesieve_count_*() and primesieve_nth_prime(). By default all CPU cores are used.

primesieve_set_sieve_sizeprimesieve

Set the sieve size in KiB (kibibyte). The best sieving performance is achieved with a sieve size of your CPU's L1 or L2 cache size (per core).

+ +
sieve_size >= 8 && <= 4096
+ +

primesieve_skiptoprimesieve

Reset the primesieve iterator to start. + +

start - Generate primes > start (or < start). + +

stop_hint - Stop number optimization hint. E.g. if you want to generate the primes below 1000 use stop_hint = 1000, if you don't know use primesieve_get_max_stop().

primesieve_versionprimesieve

Get the primesieve version number, in the form “i.j”

SHORT_PRIMESprimesieve

Generate primes of short type

UINT16_PRIMESprimesieve

Generate primes of uint16_t type

UINT32_PRIMESprimesieve

Generate primes of uint32_t type

UINT64_PRIMESprimesieve

Generate primes of uint64_t type

UINT_PRIMESprimesieve

Generate primes of unsigned int type

ULONGLONG_PRIMESprimesieve

Generate primes of unsigned long long type

ULONG_PRIMESprimesieve

Generate primes of unsigned long type

unload_libprimesieveprimesieve

Unoads primesieve library.

USHORT_PRIMESprimesieve

Generate primes of unsigned short type

_PRIMESIEVE_ERRORprimesieve

primesieve functions return PRIMESIEVE_ERROR (UINT64_MAX) if any error occurs.

_PRIMESIEVE_PAS_VERSIONprimesieve

 

_PRIMESIEVE_VERSIONprimesieve

 

_PRIMESIEVE_VERSION_MAJORprimesieve

 

_PRIMESIEVE_VERSION_MINORprimesieve

 

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/AllTypes.html b/docs/AllTypes.html new file mode 100644 index 0000000..533d664 --- /dev/null +++ b/docs/AllTypes.html @@ -0,0 +1,18 @@ + + + +primesieve-pas: All Types + + + + + + +
+

All Types

+

+The units do not contain any types.

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/AllUnits.html b/docs/AllUnits.html new file mode 100644 index 0000000..56106f4 --- /dev/null +++ b/docs/AllUnits.html @@ -0,0 +1,32 @@ + + + +primesieve-pas: All Units + + + + + + +
+

All Units

+ + + + + + + + + +
NameDescription
primesieve

Pascal bindings for primesieve library. + +

primesieve - library for fast prime number generation.
Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
https://github.com/kimwalisch/primesieve + +

primesieve-pas - FPC/Delphi API for primesieve library.
Copyright (C) 2020 I. Kakoulidis, <ioulianos.kakoulidis@hotmail.com>
https://github.com/JulStrat/primesieve-pas + +

This file is distributed under the BSD 2-Clause License.

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/AllVariables.html b/docs/AllVariables.html new file mode 100644 index 0000000..6d508d5 --- /dev/null +++ b/docs/AllVariables.html @@ -0,0 +1,180 @@ + + + +primesieve-pas: All Variables + + + + + + +
+

All Variables

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameUnitDescription
primesieve_count_primesprimesieve

Count the primes within the interval [start, stop]. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads. + +

Note that each call to primesieve_count_primes() incurs an initialization overhead of O(sqrt(stop)) even if the interval [start, stop] is tiny. Hence if you have written an algorithm that makes many calls to primesieve_count_primes() it may be preferable to use a primesieve::iterator which needs to be initialized only once.

primesieve_count_quadrupletsprimesieve

Count the prime quadruplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_quintupletsprimesieve

Count the prime quintuplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_sextupletsprimesieve

Count the prime sextuplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_tripletsprimesieve

Count the prime triplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_count_twinsprimesieve

Count the twin primes within the interval [start, stop]. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

primesieve_freeprimesieve

Deallocate a primes array created using the primesieve_generate_primes() or primesieve_generate_n_primes() functions.

primesieve_free_iteratorprimesieve

Free all memory

primesieve_generate_n_primesprimesieve

Get an array with the first n primes >= start. + +

ptype - The type of the primes to generate, e.g. INT_PRIMES.

primesieve_generate_primesprimesieve

Get an array with the primes inside the interval [start, stop]. + +

size - The size of the returned primes array.
ptype - The type of the primes to generate, e.g. INT_PRIMES.

primesieve_get_max_stopprimesieve

Returns the largest valid stop number for primesieve. + +

+ +
2ˆ64-1 (UINT64_MAX)
+ +

primesieve_get_num_threadsprimesieve

Get the current set number of threads

primesieve_get_sieve_sizeprimesieve

Get the current set sieve size in KiB

primesieve_initprimesieve

Initialize the primesieve iterator before first using it

primesieve_nth_primeprimesieve

Find the nth prime. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads. + +

Note that each call to primesieve_nth_prime(n, start) incurs an initialization overhead of O(sqrt(start)) even if n is tiny. Hence it is not a good idea to use primesieve_nth_prime() repeatedly in a loop to get the next (or previous) prime. For this use case it is better to use a primesieve::iterator which needs to be initialized only once. + +

if n = 0 finds the 1st prime >= start,
if n > 0 finds the nth prime > start,
if n < 0 finds the nth prime < start (backwards).

primesieve_print_primesprimesieve

Print the primes within the interval [start, stop] to the standard output.

primesieve_print_quadrupletsprimesieve

Print the prime quadruplets within the interval [start, stop] to the standard output.

primesieve_print_quintupletsprimesieve

Print the prime quintuplets within the interval [start, stop] to the standard output.

primesieve_print_sextupletsprimesieve

Print the prime sextuplets within the interval [start, stop] to the standard output.

primesieve_print_tripletsprimesieve

Print the prime triplets within the interval [start, stop] to the standard output.

primesieve_print_twinsprimesieve

Print the twin primes within the interval [start, stop] to the standard output.

primesieve_set_num_threadsprimesieve

Set the number of threads for use in primesieve_count_*() and primesieve_nth_prime(). By default all CPU cores are used.

primesieve_set_sieve_sizeprimesieve

Set the sieve size in KiB (kibibyte). The best sieving performance is achieved with a sieve size of your CPU's L1 or L2 cache size (per core).

+ +
sieve_size >= 8 && <= 4096
+ +

primesieve_skiptoprimesieve

Reset the primesieve iterator to start. + +

start - Generate primes > start (or < start). + +

stop_hint - Stop number optimization hint. E.g. if you want to generate the primes below 1000 use stop_hint = 1000, if you don't know use primesieve_get_max_stop().

primesieve_versionprimesieve

Get the primesieve version number, in the form “i.j”

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/ClassHierarchy.html b/docs/ClassHierarchy.html new file mode 100644 index 0000000..1f22231 --- /dev/null +++ b/docs/ClassHierarchy.html @@ -0,0 +1,18 @@ + + + +primesieve-pas: Class Hierarchy + + + + + + +
+

Class Hierarchy

+

+The units do not contain any classes, interfaces or objects.

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/automated.gif b/docs/automated.gif new file mode 100644 index 0000000000000000000000000000000000000000..7c271d8f5afab8ace82db792952eeee12c6254de GIT binary patch literal 141 zcmZ?wbhEHbRgnXSdyBeP@Y+mp%9Xh zs^ISF8^E9gk_BmGU~*;Q5KwSvU{Lj%q7kTYq=i%1jb(*F;-MBMMKzxp21*XCoWg1% g9ELyphyo#z#^AUAyy`^b`b_^0C_wkqW}N^ literal 0 HcmV?d00001 diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..56106f4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,32 @@ + + + +primesieve-pas: All Units + + + + + + +
+

All Units

+ + + + + + + + + +
NameDescription
primesieve

Pascal bindings for primesieve library. + +

primesieve - library for fast prime number generation.
Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
https://github.com/kimwalisch/primesieve + +

primesieve-pas - FPC/Delphi API for primesieve library.
Copyright (C) 2020 I. Kakoulidis, <ioulianos.kakoulidis@hotmail.com>
https://github.com/JulStrat/primesieve-pas + +

This file is distributed under the BSD 2-Clause License.

+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/legend.html b/docs/legend.html new file mode 100644 index 0000000..33cae62 --- /dev/null +++ b/docs/legend.html @@ -0,0 +1,54 @@ + + + +primesieve-pas: Legend + + + + + + +
+

Legend

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MarkerVisibility
Strict PrivateStrict Private
PrivatePrivate
Strict ProtectedStrict Protected
ProtectedProtected
PublicPublic
PublishedPublished
AutomatedAutomated
ImplicitImplicit
+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/pasdoc.css b/docs/pasdoc.css new file mode 100644 index 0000000..47d10d6 --- /dev/null +++ b/docs/pasdoc.css @@ -0,0 +1,203 @@ +/* + Copyright 1998-2018 PasDoc developers. + + This file is part of "PasDoc". + + "PasDoc" is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + "PasDoc" 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with "PasDoc"; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + ---------------------------------------------------------------------------- +*/ + +body, html, table.container { + margin: 0; + padding: 0; +} + +body { + font-family: Verdana,Arial; + color: black; + background-color: white; +} + +table.container { + width: 100%; + border-spacing: 0; +} +table.container td { + vertical-align: top; +} + +td.navigation { + width: 200px; + color: white; + background-color: #787878; + margin: 0; + /* padding-bottom is a little larger, to make navigation column have some + nice height even when td.content column is very small. */ + padding: 1em 1em 100px 1em; +} +td.navigation p { padding: 0; } +td.navigation h2 { margin-top: 0; } + +td.content { padding: 1em; } +td.content h1 { margin-top: 0; } + +img { border:0px; } + +hr { + border-bottom: medium none; + border-top: thin solid #888; +} + +a:link {color:#C91E0C; text-decoration: none; } +a:visited {color:#7E5C31; text-decoration: none; } +a:hover {text-decoration: underline; } +a:active {text-decoration: underline; } + +a.navigation:link { color: white; text-decoration: none; } +a.navigation:visited { color: white; text-decoration: none; } +a.navigation:hover { color: white; font-weight: bold; text-decoration: none; } +a.navigation:active { color: white; text-decoration: none; } + +a.bold:link {color:#C91E0C; text-decoration: none; font-weight:bold; } +a.bold:visited {color:#7E5C31; text-decoration: none; font-weight:bold; } +a.bold:hover {text-decoration: underline; font-weight:bold; } +a.bold:active {text-decoration: underline; font-weight:bold; } + +a.section {color: green; text-decoration: none; font-weight: bold; } +a.section:hover {color: green; text-decoration: underline; font-weight: bold; } + +ul.useslist a:link {color:#C91E0C; text-decoration: none; font-weight:bold; } +ul.useslist a:visited {color:#7E5C31; text-decoration: none; font-weight:bold; } +ul.useslist a:hover {text-decoration: underline; font-weight:bold; } +ul.useslist a:active {text-decoration: underline; font-weight:bold; } + +ul.hierarchy { list-style-type:none; } +ul.hierarchylevel { list-style-type:none; } + +p.unitlink a:link {color:#C91E0C; text-decoration: none; font-weight:bold; } +p.unitlink a:visited {color:#7E5C31; text-decoration: none; font-weight:bold; } +p.unitlink a:hover {text-decoration: underline; font-weight:bold; } +p.unitlink a:active {text-decoration: underline; font-weight:bold; } + +tr.list { background: #FFBF44; } +tr.list2 { background: #FFC982; } +tr.listheader { background: #C91E0C; color: white; } + +table.wide_list { border-spacing:2px; width:100%; } +table.wide_list td { vertical-align:top; padding:4px; } + +table.markerlegend { width:auto; } +table.markerlegend td.legendmarker { text-align:center; } + +.sections { background:white; } +.sections .one_section { + background:lightgray; + display: inline-block; + margin: 0.2em; + padding: 0.5em 1em; +} + +table.summary td.itemcode { width:100%; } +table.detail td.itemcode { width:100%; } + +td.itemname {white-space:nowrap; } +td.itemunit {white-space:nowrap; } +td.itemdesc { width:100%; } + +div.nodescription { color:red; } +dl.parameters dt { color:blue; } + +/* Various browsers have various default styles for
, + sometimes ugly for our purposes, so it's best to set things + like font-size and font-weight in out pasdoc.css explicitly. */ +h6.description_section { + /* font-size 100% means that it has the same font size as the + parent element, i.e. normal description text */ + font-size: 100%; + font-weight: bold; + /* By default browsers usually have some large margin-bottom and + margin-top for tags. In our case, margin-bottom is + unnecessary, we want to visually show that description_section + is closely related to content below. In this situation + (where the font size is just as a normal text), smaller bottom + margin seems to look good. */ + margin-top: 1.4em; + margin-bottom: 0em; +} + +/* Style applied to Pascal code in documentation + (e.g. produced by @longcode tag) } */ +span.pascal_string { color: #000080; } +span.pascal_keyword { font-weight: bolder; } +span.pascal_comment { color: #000080; font-style: italic; } +span.pascal_compiler_comment { color: #008000; } +span.pascal_numeric { } +span.pascal_hex { } + +p.hint_directive { color: red; } + +input#search_text { } +input#search_submit_button { } + +acronym.mispelling { background-color: #ffa; } + +/* Actually this reduces vertical space between *every* paragraph + inside list with @itemSpacing(compact). + While we would like to reduce this space only for the + top of 1st and bottom of last paragraph within each list item. + But, well, user probably will not do any paragraph breaks + within a list with @itemSpacing(compact) anyway, so it's + acceptable solution. */ +ul.compact_spacing p { margin-top: 0em; margin-bottom: 0em; } +ol.compact_spacing p { margin-top: 0em; margin-bottom: 0em; } +dl.compact_spacing p { margin-top: 0em; margin-bottom: 0em; } + +/* Style for table created by @table tags: + just some thin border. + + This way we have some borders around the cells + (so cells are visibly separated), but the border + "blends with the background" so it doesn't look too ugly. + Hopefully it looks satisfactory in most cases and for most + people. + + We add padding for cells, otherwise they look too close. + This is normal thing to do when border-collapse is set to + collapse (because this eliminates spacing between cells). +*/ +table.table_tag { border-collapse: collapse; } +table.table_tag td { border: 1pt solid gray; padding: 0.3em; } +table.table_tag th { border: 1pt solid gray; padding: 0.3em; } + +table.detail { + border: 1pt solid gray; + margin-top: 0.3em; + margin-bottom: 0.3em; +} + +.search-form { white-space: nowrap; } +.search-input, .search-button { display: inline-block; vertical-align: middle; } + +/* Do not make extra vertical space at the beginning/end of table cells. + We need ">" selector, to not change paragraphs inside lists inside + table cells. */ +table.table_tag td > p:first-child, +table.table_tag th > p:first-child, + td.itemdesc > p:first-child { margin-top: 0em; } + +table.table_tag td > p:last-child, +table.table_tag th > p:last-child, + td.itemdesc > p:last-child { margin-bottom: 0em; } diff --git a/docs/primesieve.html b/docs/primesieve.html new file mode 100644 index 0000000..69b28e3 --- /dev/null +++ b/docs/primesieve.html @@ -0,0 +1,656 @@ + + + +primesieve-pas: primesieve + + + + + + +
+

Unit primesieve

+ +

Description

+

+Pascal bindings for primesieve library. + +

primesieve - library for fast prime number generation.
Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
https://github.com/kimwalisch/primesieve + +

primesieve-pas - FPC/Delphi API for primesieve library.
Copyright (C) 2020 I. Kakoulidis, <ioulianos.kakoulidis@hotmail.com>
https://github.com/JulStrat/primesieve-pas + +

This file is distributed under the BSD 2-Clause License.

+

Overview

+

Classes, Interfaces, Objects and Records

+ + + + + + + + + +
NameDescription
Record primesieve_iterator 
+

Functions and Procedures

+ + + + + + + + + + + + + +
function primesieve_next_prime(var it: primesieve_iterator): UInt64; inline;
function primesieve_prev_prime(var it: primesieve_iterator): UInt64; inline;
function load_libprimesieve: integer;
function unload_libprimesieve: integer;
+

Constants

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
_PRIMESIEVE_VERSION = '7.5';
_PRIMESIEVE_VERSION_MAJOR = 7;
_PRIMESIEVE_VERSION_MINOR = 5;
_PRIMESIEVE_PAS_VERSION = '0.2';
_PRIMESIEVE_ERROR = not UInt64(0);
SHORT_PRIMES = 0;
USHORT_PRIMES = 1;
INT_PRIMES = 2;
UINT_PRIMES = 3;
LONG_PRIMES = 4;
ULONG_PRIMES = 5;
LONGLONG_PRIMES = 6;
ULONGLONG_PRIMES = 7;
INT16_PRIMES = 8;
UINT16_PRIMES = 9;
INT32_PRIMES = 10;
UINT32_PRIMES = 11;
INT64_PRIMES = 12;
UINT64_PRIMES = 13;
+

Variables

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
primesieve_generate_primes: function(start: UInt64; stop: UInt64; var size: NativeUInt; ptype: Integer): Pointer; cdecl;
primesieve_generate_n_primes: function(n: UInt64; start: UInt64; ptype: Integer): Pointer; cdecl;
primesieve_nth_prime: function(n: Int64; start: UInt64): UInt64; cdecl;
primesieve_count_primes: function(start: UInt64; stop: UInt64): UInt64; cdecl;
primesieve_count_twins: function(start: UInt64; stop: UInt64): UInt64; cdecl;
primesieve_count_triplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
primesieve_count_quadruplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
primesieve_count_quintuplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
primesieve_count_sextuplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
primesieve_print_primes: procedure(start: UInt64; stop: UInt64); cdecl;
primesieve_print_twins: procedure(start: UInt64; stop: UInt64); cdecl;
primesieve_print_triplets: procedure(start: UInt64; stop: UInt64); cdecl;
primesieve_print_quadruplets: procedure(start: UInt64; stop: UInt64); cdecl;
primesieve_print_quintuplets: procedure(start: UInt64; stop: UInt64); cdecl;
primesieve_print_sextuplets: procedure(start: UInt64; stop: UInt64); cdecl;
primesieve_get_max_stop: function(): UInt64; cdecl;
primesieve_get_sieve_size: function(): Integer; cdecl;
primesieve_get_num_threads: function(): Integer; cdecl;
primesieve_set_sieve_size: procedure(sieve_size: Integer); cdecl;
primesieve_set_num_threads: procedure(num_threads: Integer); cdecl;
primesieve_free: procedure(primes: Pointer); cdecl;
primesieve_version: function(): PAnsiChar; cdecl;
primesieve_init: procedure(var it: primesieve_iterator); cdecl;
primesieve_free_iterator: procedure(var it: primesieve_iterator); cdecl;
primesieve_skipto: procedure(var it: primesieve_iterator; start: UInt64; stop_hint: UInt64); cdecl;
+

Description

+

Functions and Procedures

+ + + + + +
function primesieve_next_prime(var it: primesieve_iterator): UInt64; inline;
+

+Get the next prime. + +

Returns UINT64_MAX if next prime > 2ˆ64.

+
+ + + + + +
function primesieve_prev_prime(var it: primesieve_iterator): UInt64; inline;
+

+Get the previous prime. + +

primesieve_prev_prime(n) returns 0 for n <= 2. Note that primesieve_next_prime() runs up to 2x faster than primesieve_prev_prime(). Hence if the same algorithm can be written using either primesieve_prev_prime() or primesieve_next_prime() it is preferable to use primesieve_next_prime().

+
+ + + + + +
function load_libprimesieve: integer;
+

+Loads primesieve library.

+
+ + + + + +
function unload_libprimesieve: integer;
+

+Unoads primesieve library.

+
+

Constants

+ + + + + +
_PRIMESIEVE_VERSION = '7.5';
+ + + + + +
_PRIMESIEVE_VERSION_MAJOR = 7;
+ + + + + +
_PRIMESIEVE_VERSION_MINOR = 5;
+ + + + + +
_PRIMESIEVE_PAS_VERSION = '0.2';
+ + + + + +
_PRIMESIEVE_ERROR = not UInt64(0);
+

+primesieve functions return PRIMESIEVE_ERROR (UINT64_MAX) if any error occurs.

+
+ + + + + +
SHORT_PRIMES = 0;
+

+Generate primes of short type

+
+ + + + + +
USHORT_PRIMES = 1;
+

+Generate primes of unsigned short type

+
+ + + + + +
INT_PRIMES = 2;
+

+Generate primes of int type

+
+ + + + + +
UINT_PRIMES = 3;
+

+Generate primes of unsigned int type

+
+ + + + + +
LONG_PRIMES = 4;
+

+Generate primes of long type

+
+ + + + + +
ULONG_PRIMES = 5;
+

+Generate primes of unsigned long type

+
+ + + + + +
LONGLONG_PRIMES = 6;
+

+Generate primes of long long type

+
+ + + + + +
ULONGLONG_PRIMES = 7;
+

+Generate primes of unsigned long long type

+
+ + + + + +
INT16_PRIMES = 8;
+

+Generate primes of int16_t type

+
+ + + + + +
UINT16_PRIMES = 9;
+

+Generate primes of uint16_t type

+
+ + + + + +
INT32_PRIMES = 10;
+

+Generate primes of int32_t type

+
+ + + + + +
UINT32_PRIMES = 11;
+

+Generate primes of uint32_t type

+
+ + + + + +
INT64_PRIMES = 12;
+

+Generate primes of int64_t type

+
+ + + + + +
UINT64_PRIMES = 13;
+

+Generate primes of uint64_t type

+
+

Variables

+ + + + + +
primesieve_generate_primes: function(start: UInt64; stop: UInt64; var size: NativeUInt; ptype: Integer): Pointer; cdecl;
+

+Get an array with the primes inside the interval [start, stop]. + +

size - The size of the returned primes array.
ptype - The type of the primes to generate, e.g. INT_PRIMES.

+
+ + + + + +
primesieve_generate_n_primes: function(n: UInt64; start: UInt64; ptype: Integer): Pointer; cdecl;
+

+Get an array with the first n primes >= start. + +

ptype - The type of the primes to generate, e.g. INT_PRIMES.

+
+ + + + + +
primesieve_nth_prime: function(n: Int64; start: UInt64): UInt64; cdecl;
+

+Find the nth prime. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads. + +

Note that each call to primesieve_nth_prime(n, start) incurs an initialization overhead of O(sqrt(start)) even if n is tiny. Hence it is not a good idea to use primesieve_nth_prime() repeatedly in a loop to get the next (or previous) prime. For this use case it is better to use a primesieve::iterator which needs to be initialized only once. + +

if n = 0 finds the 1st prime >= start,
if n > 0 finds the nth prime > start,
if n < 0 finds the nth prime < start (backwards).

+
+ + + + + +
primesieve_count_primes: function(start: UInt64; stop: UInt64): UInt64; cdecl;
+

+Count the primes within the interval [start, stop]. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads. + +

Note that each call to primesieve_count_primes() incurs an initialization overhead of O(sqrt(stop)) even if the interval [start, stop] is tiny. Hence if you have written an algorithm that makes many calls to primesieve_count_primes() it may be preferable to use a primesieve::iterator which needs to be initialized only once.

+
+ + + + + +
primesieve_count_twins: function(start: UInt64; stop: UInt64): UInt64; cdecl;
+

+Count the twin primes within the interval [start, stop]. By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

+
+ + + + + +
primesieve_count_triplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
+

+Count the prime triplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

+
+ + + + + +
primesieve_count_quadruplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
+

+Count the prime quadruplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

+
+ + + + + +
primesieve_count_quintuplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
+

+Count the prime quintuplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

+
+ + + + + +
primesieve_count_sextuplets: function(start: UInt64; stop: UInt64): UInt64; cdecl;
+

+Count the prime sextuplets within the interval [start, stop]. + +

By default all CPU cores are used, use primesieve_set_num_threads(int threads) to change the number of threads.

+
+ + + + + +
primesieve_print_primes: procedure(start: UInt64; stop: UInt64); cdecl;
+

+Print the primes within the interval [start, stop] to the standard output.

+
+ + + + + +
primesieve_print_twins: procedure(start: UInt64; stop: UInt64); cdecl;
+

+Print the twin primes within the interval [start, stop] to the standard output.

+
+ + + + + +
primesieve_print_triplets: procedure(start: UInt64; stop: UInt64); cdecl;
+

+Print the prime triplets within the interval [start, stop] to the standard output.

+
+ + + + + +
primesieve_print_quadruplets: procedure(start: UInt64; stop: UInt64); cdecl;
+

+Print the prime quadruplets within the interval [start, stop] to the standard output.

+
+ + + + + +
primesieve_print_quintuplets: procedure(start: UInt64; stop: UInt64); cdecl;
+

+Print the prime quintuplets within the interval [start, stop] to the standard output.

+
+ + + + + +
primesieve_print_sextuplets: procedure(start: UInt64; stop: UInt64); cdecl;
+

+Print the prime sextuplets within the interval [start, stop] to the standard output.

+
+ + + + + +
primesieve_get_max_stop: function(): UInt64; cdecl;
+

+Returns the largest valid stop number for primesieve. + +

+ +
2ˆ64-1 (UINT64_MAX)
+ +

+
+ + + + + +
primesieve_get_sieve_size: function(): Integer; cdecl;
+

+Get the current set sieve size in KiB

+
+ + + + + +
primesieve_get_num_threads: function(): Integer; cdecl;
+

+Get the current set number of threads

+
+ + + + + +
primesieve_set_sieve_size: procedure(sieve_size: Integer); cdecl;
+

+Set the sieve size in KiB (kibibyte). The best sieving performance is achieved with a sieve size of your CPU's L1 or L2 cache size (per core).

+ +
sieve_size >= 8 && <= 4096
+ +

+
+ + + + + +
primesieve_set_num_threads: procedure(num_threads: Integer); cdecl;
+

+Set the number of threads for use in primesieve_count_*() and primesieve_nth_prime(). By default all CPU cores are used.

+
+ + + + + +
primesieve_free: procedure(primes: Pointer); cdecl;
+

+Deallocate a primes array created using the primesieve_generate_primes() or primesieve_generate_n_primes() functions.

+
+ + + + + +
primesieve_version: function(): PAnsiChar; cdecl;
+

+Get the primesieve version number, in the form “i.j”

+
+ + + + + +
primesieve_init: procedure(var it: primesieve_iterator); cdecl;
+

+Initialize the primesieve iterator before first using it

+
+ + + + + +
primesieve_free_iterator: procedure(var it: primesieve_iterator); cdecl;
+

+Free all memory

+
+ + + + + +
primesieve_skipto: procedure(var it: primesieve_iterator; start: UInt64; stop_hint: UInt64); cdecl;
+

+Reset the primesieve iterator to start. + +

start - Generate primes > start (or < start). + +

stop_hint - Stop number optimization hint. E.g. if you want to generate the primes below 1000 use stop_hint = 1000, if you don't know use primesieve_get_max_stop().

+
+
Generated by PasDoc 0.15.0. + +
diff --git a/docs/primesieve.primesieve_iterator.html b/docs/primesieve.primesieve_iterator.html new file mode 100644 index 0000000..482f713 --- /dev/null +++ b/docs/primesieve.primesieve_iterator.html @@ -0,0 +1,25 @@ + + + +primesieve-pas: primesieve: Record primesieve_iterator + + + + + + +
+

Record primesieve_iterator

+
+
Hierarchy
Fields
Methods
Properties
+

Unit

+ +

Declaration

+

+type primesieve_iterator = record

+

Description


Generated by PasDoc 0.15.0. + +
diff --git a/docs/private.gif b/docs/private.gif new file mode 100644 index 0000000000000000000000000000000000000000..dca4ce267765ccd8c5161c580651f2c5efd779bb GIT binary patch literal 141 zcmZ?wbhEHbRgnXSdyBeP@Y+mp%9Xh zs^ISF8^E9gk_BmGU~*;Q5KwSvU{Lj%q7kTYq=i%1jb(*F;-MBMMKzxp21*XCoWg1% g9ELyphyo#z#^AUAyy`^b`b_^01>Go%m4rY literal 0 HcmV?d00001 diff --git a/docs/protected.gif b/docs/protected.gif new file mode 100644 index 0000000000000000000000000000000000000000..96cc3822b7efa426b3d5c7e5dc5c2fa1d0ca51f3 GIT binary patch literal 141 zcmZ?wbhEHb!{|pQaia%L^B#{0m>RgnXSdyBeP@Y+mp%9Xh zs^ISF8^E9gk_BmGU~*;Q5KwSvU{Lj%q7kTYq=i%1jb(*F;-MBMMKzxp21*XCoWg1% g9ELyphyo#z#^AUAyy`^b`b_^03Pci=>Px# literal 0 HcmV?d00001 diff --git a/docs/published.gif b/docs/published.gif new file mode 100644 index 0000000000000000000000000000000000000000..6ed9af6cd3cd0203a73abe35d9216cd1b99531f9 GIT binary patch literal 141 zcmZ?wbhEHbRgnXSdyBeP@Y+mp%9Xh zs^ISF8^E9gk_BmGU~*;Q5KwSvU{Lj%q7kTYq=i%1jb(*F;-MBMMKzxp21*XCoWg1% g9ELyphyo#z#^AUAyy`^b`b_^048=K`Tzg` literal 0 HcmV?d00001 diff --git a/primesieve.pas b/primesieve.pas index 6aa13e9..e1cc4b8 100644 --- a/primesieve.pas +++ b/primesieve.pas @@ -1,10 +1,24 @@ +{ + Pascal bindings for primesieve library. + + primesieve - library for fast prime number generation.@br + Copyright (C) 2019 Kim Walisch, @br + https://github.com/kimwalisch/primesieve + + primesieve-pas - FPC/Delphi API for primesieve library.@br + Copyright (C) 2020 I. Kakoulidis, @br + https://github.com/JulStrat/primesieve-pas + + This file is distributed under the BSD 2-Clause License. +} + unit primesieve; -{$ifdef FPC} +{$IF Defined(FPC)} {$mode Delphi} -{$endif} +{$ENDIF} -{$IFDEF USE_ABI6} -{$MESSAGE Warn 'Using ABI6'} +{$IF Defined(USE_ABI6)} +{$MESSAGE Hint 'Using ABI6'} {$ENDIF} interface @@ -17,44 +31,44 @@ interface _PRIMESIEVE_PAS_VERSION = '0.2'; - (** - * primesieve functions return PRIMESIEVE_ERROR - * (UINT64_MAX) if any error occurs. + (* + primesieve functions return PRIMESIEVE_ERROR + (UINT64_MAX) if any error occurs. *) _PRIMESIEVE_ERROR = not UInt64(0); - (** Generate primes of short type *) + (* Generate primes of short type *) SHORT_PRIMES = 0; - (** Generate primes of unsigned short type *) + (* Generate primes of unsigned short type *) USHORT_PRIMES = 1; - (** Generate primes of int type *) + (* Generate primes of int type *) INT_PRIMES = 2; - (** Generate primes of unsigned int type *) + (* Generate primes of unsigned int type *) UINT_PRIMES = 3; - (** Generate primes of long type *) + (* Generate primes of long type *) LONG_PRIMES = 4; - (** Generate primes of unsigned long type *) + (* Generate primes of unsigned long type *) ULONG_PRIMES = 5; - (** Generate primes of long long type *) + (* Generate primes of long long type *) LONGLONG_PRIMES = 6; - (** Generate primes of unsigned long long type *) + (* Generate primes of unsigned long long type *) ULONGLONG_PRIMES = 7; - (** Generate primes of int16_t type *) + (* Generate primes of int16_t type *) INT16_PRIMES = 8; - (** Generate primes of uint16_t type *) + (* Generate primes of uint16_t type *) UINT16_PRIMES = 9; - (** Generate primes of int32_t type *) + (* Generate primes of int32_t type *) INT32_PRIMES = 10; - (** Generate primes of uint32_t type *) + (* Generate primes of uint32_t type *) UINT32_PRIMES = 11; - (** Generate primes of int64_t type *) + (* Generate primes of int64_t type *) INT64_PRIMES = 12; - (** Generate primes of uint64_t type *) + (* Generate primes of uint64_t type *) UINT64_PRIMES = 13; type - {$IFDEF USE_ABI6} + {$IF Defined(USE_ABI6)} primesieve_iterator = record i_: NativeUInt; last_idx_: NativeUInt; @@ -82,219 +96,236 @@ primesieve_iterator = record {$ENDIF} var -(** - * Get an array with the primes inside the interval [start, stop]. - * @param size The size of the returned primes array. - * @param type The type of the primes to generate, e.g. INT_PRIMES. +(* + Get an array with the primes inside the interval @italic([start, stop]). + + @code(size) - The size of the returned primes array.@br + @code(ptype) - The type of the primes to generate, e.g. INT_PRIMES. *) - primesieve_generate_primes: function(start: UInt64; stop: UInt64; var size: NativeUInt; &type: Integer): Pointer; cdecl; + primesieve_generate_primes: function(start: UInt64; stop: UInt64; var size: NativeUInt; ptype: Integer): Pointer; cdecl; -(** - * Get an array with the first n primes >= start. - * @param type The type of the primes to generate, e.g. INT_PRIMES. +(* + Get an array with the first n primes >= start. + + @code(ptype) - The type of the primes to generate, e.g. INT_PRIMES. *) - primesieve_generate_n_primes: function(n: UInt64; start: UInt64; &type: Integer): Pointer; cdecl; - -(** - * Find the nth prime. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. - * - * Note that each call to primesieve_nth_prime(n, start) incurs an - * initialization overhead of O(sqrt(start)) even if n is tiny. - * Hence it is not a good idea to use primesieve_nth_prime() - * repeatedly in a loop to get the next (or previous) prime. For - * this use case it is better to use a primesieve::iterator which - * needs to be initialized only once. - * - * @param n if n = 0 finds the 1st prime >= start,
- * if n > 0 finds the nth prime > start,
- * if n < 0 finds the nth prime < start (backwards). + primesieve_generate_n_primes: function(n: UInt64; start: UInt64; ptype: Integer): Pointer; cdecl; + +(* + Find the nth prime. + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. + + Note that each call to primesieve_nth_prime(n, start) incurs an + initialization overhead of O(sqrt(start)) even if n is tiny. + Hence it is not a good idea to use primesieve_nth_prime() + repeatedly in a loop to get the next (or previous) prime. For + this use case it is better to use a primesieve::iterator which + needs to be initialized only once. + + if n = 0 finds the 1st prime >= start,@br + if n > 0 finds the nth prime > start,@br + if n < 0 finds the nth prime < start (backwards). *) primesieve_nth_prime: function(n: Int64; start: UInt64): UInt64; cdecl; -(** - * Count the primes within the interval [start, stop]. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. - * - * Note that each call to primesieve_count_primes() incurs an - * initialization overhead of O(sqrt(stop)) even if the interval - * [start, stop] is tiny. Hence if you have written an algorithm - * that makes many calls to primesieve_count_primes() it may be - * preferable to use a primesieve::iterator which needs to be - * initialized only once. +(* + Count the primes within the interval @italic([start, stop]). + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. + + Note that each call to primesieve_count_primes() incurs an + initialization overhead of O(sqrt(stop)) even if the interval + @italic([start, stop]) is tiny. Hence if you have written an algorithm + that makes many calls to primesieve_count_primes() it may be + preferable to use a primesieve::iterator which needs to be + initialized only once. *) primesieve_count_primes: function(start: UInt64; stop: UInt64): UInt64; cdecl; -(** - * Count the twin primes within the interval [start, stop]. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. +(* + Count the twin primes within the interval @italic([start, stop]). + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. *) primesieve_count_twins: function(start: UInt64; stop: UInt64): UInt64; cdecl; -(** - * Count the prime triplets within the interval [start, stop]. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. +(* + Count the prime triplets within the interval @italic([start, stop]). + + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. *) primesieve_count_triplets: function(start: UInt64; stop: UInt64): UInt64; cdecl; -(** - * Count the prime quadruplets within the interval [start, stop]. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. +(* + Count the prime quadruplets within the interval @italic([start, stop]). + + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. *) primesieve_count_quadruplets: function(start: UInt64; stop: UInt64): UInt64; cdecl; -(** - * Count the prime quintuplets within the interval [start, stop]. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. +(* + Count the prime quintuplets within the interval @italic([start, stop]). + + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. *) primesieve_count_quintuplets: function(start: UInt64; stop: UInt64): UInt64; cdecl; -(** - * Count the prime sextuplets within the interval [start, stop]. - * By default all CPU cores are used, use - * primesieve_set_num_threads(int threads) to change the - * number of threads. +(* + Count the prime sextuplets within the interval @italic([start, stop]). + + By default all CPU cores are used, use + primesieve_set_num_threads(int threads) to change the + number of threads. *) primesieve_count_sextuplets: function(start: UInt64; stop: UInt64): UInt64; cdecl; -(** - * Print the primes within the interval [start, stop] - * to the standard output. +(* + Print the primes within the interval @italic([start, stop]) + to the standard output. *) primesieve_print_primes: procedure(start: UInt64; stop: UInt64); cdecl; -(** - * Print the twin primes within the interval [start, stop] - * to the standard output. +(* + Print the twin primes within the interval @italic([start, stop]) + to the standard output. *) primesieve_print_twins: procedure(start: UInt64; stop: UInt64); cdecl; -(** - * Print the prime triplets within the interval [start, stop] - * to the standard output. +(* + Print the prime triplets within the interval @italic([start, stop]) + to the standard output. *) primesieve_print_triplets: procedure(start: UInt64; stop: UInt64); cdecl; -(** - * Print the prime quadruplets within the interval [start, stop] - * to the standard output. +(* + Print the prime quadruplets within the interval @italic([start, stop]) + to the standard output. *) primesieve_print_quadruplets: procedure(start: UInt64; stop: UInt64); cdecl; -(** - * Print the prime quintuplets within the interval [start, stop] - * to the standard output. +(* + Print the prime quintuplets within the interval @italic([start, stop]) + to the standard output. *) primesieve_print_quintuplets: procedure(start: UInt64; stop: UInt64); cdecl; -(** - * Print the prime sextuplets within the interval [start, stop] - * to the standard output. +(* + Print the prime sextuplets within the interval @italic([start, stop]) + to the standard output. *) primesieve_print_sextuplets: procedure(start: UInt64; stop: UInt64); cdecl; -(** - * Returns the largest valid stop number for primesieve. - * @return 2^64-1 (UINT64_MAX). +(* + Returns the largest valid stop number for primesieve. + + @preformatted(2^64-1 (UINT64_MAX)) *) primesieve_get_max_stop: function(): UInt64; cdecl; -(** Get the current set sieve size in KiB *) +(* Get the current set sieve size in KiB *) primesieve_get_sieve_size: function(): Integer; cdecl; -(** Get the current set number of threads *) +(* Get the current set number of threads *) primesieve_get_num_threads: function(): Integer; cdecl; -(** - * Set the sieve size in KiB (kibibyte). - * The best sieving performance is achieved with a sieve size - * of your CPU's L1 or L2 cache size (per core). - * @pre sieve_size >= 8 && <= 4096. +(* + Set the sieve size in KiB (kibibyte). + The best sieving performance is achieved with a sieve size + of your CPU's L1 or L2 cache size (per core). + @preformatted(sieve_size >= 8 && <= 4096) *) primesieve_set_sieve_size: procedure(sieve_size: Integer); cdecl; -(** - * Set the number of threads for use in - * primesieve_count_*() and primesieve_nth_prime(). - * By default all CPU cores are used. +(* + Set the number of threads for use in + primesieve_count_*() and primesieve_nth_prime(). + By default all CPU cores are used. *) primesieve_set_num_threads: procedure(num_threads: Integer); cdecl; -(** - * Deallocate a primes array created using the - * primesieve_generate_primes() or primesieve_generate_n_primes() - * functions. +(* + Deallocate a primes array created using the + primesieve_generate_primes() or primesieve_generate_n_primes() + functions. *) primesieve_free: procedure(primes: Pointer); cdecl; -(** Get the primesieve version number, in the form “i.j” *) +(* Get the primesieve version number, in the form “i.j” *) primesieve_version: function(): PAnsiChar; cdecl; -(** Initialize the primesieve iterator before first using it *) +(* Initialize the primesieve iterator before first using it *) primesieve_init: procedure(var it: primesieve_iterator); cdecl; -(** Free all memory *) +(* Free all memory *) primesieve_free_iterator: procedure(var it: primesieve_iterator); cdecl; -(** - * Reset the primesieve iterator to start. - * @param start Generate primes > start (or < start). - * @param stop_hint Stop number optimization hint. E.g. if you want - * to generate the primes below 1000 use - * stop_hint = 1000, if you don't know use - * primesieve_get_max_stop(). +(* + Reset the primesieve iterator to start. + + @code(start) - Generate primes > start (or < start). + + @code(stop_hint) - Stop number optimization hint. E.g. if you want + to generate the primes below 1000 use + stop_hint = 1000, if you don't know use + primesieve_get_max_stop(). *) primesieve_skipto: procedure(var it: primesieve_iterator; start: UInt64; stop_hint: UInt64); cdecl; -(** - * Get the next prime. - * Returns UINT64_MAX if next prime > 2^64. +(* + Get the next prime. + + Returns UINT64_MAX if next prime > 2^64. *) function primesieve_next_prime(var it: primesieve_iterator): UInt64; inline; -(** - * Get the previous prime. - * primesieve_prev_prime(n) returns 0 for n <= 2. - * Note that primesieve_next_prime() runs up to 2x faster than - * primesieve_prev_prime(). Hence if the same algorithm can be written - * using either primesieve_prev_prime() or primesieve_next_prime() - * it is preferable to use primesieve_next_prime(). +(* + Get the previous prime. + + primesieve_prev_prime(n) returns 0 for n <= 2. + Note that primesieve_next_prime() runs up to 2x faster than + primesieve_prev_prime(). Hence if the same algorithm can be written + using either primesieve_prev_prime() or primesieve_next_prime() + it is preferable to use primesieve_next_prime(). *) function primesieve_prev_prime(var it: primesieve_iterator): UInt64; inline; +(* Loads primesieve library. *) function load_libprimesieve: integer; + +(* Unoads primesieve library. *) function unload_libprimesieve: integer; implementation -uses SysUtils{$ifdef FPC}, dynlibs{$endif}; +uses SysUtils + {$IF Defined(FPC)}, dynlibs{$ENDIF} + {$IF not Defined(FPC) and Defined(MSWindows)}, Windows{$ENDIF} + ; const {$IF Defined(Linux)} - {$MESSAGE HINT 'Linux platform'} + {$MESSAGE Hint 'Linux platform'} LIB_FNPFX = ''; LIB_PRIMESIEVE = 'libprimesieve.so'; {$ELSEIF Defined(Darwin)} - {$MESSAGE HINT 'Darwin platform'} + {$MESSAGE Hint 'Darwin platform'} LIB_FNPFX = ''; LIB_PRIMESIEVE = 'libprimesieve.dylib'; -{$ELSEIF Defined(Windows)} - {$MESSAGE HINT 'Windows platform'} +{$ELSEIF Defined(MSWindows)} + {$MESSAGE Hint 'MSWindows platform'} LIB_FNPFX = ''; LIB_PRIMESIEVE = 'libprimesieve.dll'; {$ELSE} @@ -302,15 +333,15 @@ implementation {$ENDIF} var - (** Internal use *) + (* Internal use *) primesieve_generate_next_primes: procedure(var it: primesieve_iterator); cdecl; - (** Internal use *) + (* Internal use *) primesieve_generate_prev_primes: procedure(var it: primesieve_iterator); cdecl; function primesieve_next_prime(var it: primesieve_iterator): UInt64; inline; begin - {$IFDEF USE_ABI6} + {$IF Defined(USE_ABI6)} if it.i_ = it.last_idx_ then primesieve_generate_next_primes(it) else @@ -327,7 +358,7 @@ function primesieve_next_prime(var it: primesieve_iterator): UInt64; inline; function primesieve_prev_prime(var it: primesieve_iterator): UInt64; inline; begin - {$IFDEF USE_ABI6} + {$IF Defined(USE_ABI6)} if it.i_ = 0 then primesieve_generate_prev_primes(it) else @@ -343,8 +374,12 @@ function primesieve_prev_prime(var it: primesieve_iterator): UInt64; inline; end; var + {$IF Defined(FPC)} libHandle: TLibHandle; - + {$ELSE} + libHandle: HMODULE; + {$ENDIF} + function load_libprimesieve(); procedure GetAddr(var procAddr: Pointer; procName: string);