Skip to content

Commit

Permalink
Merge branch 'loadlib'
Browse files Browse the repository at this point in the history
  • Loading branch information
JulStrat committed Jul 6, 2020
2 parents 8e6ebf8 + ccad89a commit 9c7fefc
Show file tree
Hide file tree
Showing 23 changed files with 2,858 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
# *.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
#*.out
*.app
*.i*86
*.x86_64
Expand Down
18 changes: 10 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ before_install:
export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH:/usr/local/lib;
echo $DYLD_LIBRARY_PATH;
sudo update_dyld_shared_cache;
else
choco install lazarus;
export PATH="$PATH":"/C/lazarus/fpc/3.0.4/bin/x86_64-win64";
fi

install:
- fpc -B -vh primesieve_info.pas
- fpc -B -vh examples/count_primes.pas
- fpc -B -vh examples/nth_prime.pas
- fpc -B -vh examples/store_primes_in_array.pas

script:
- fpc -B -O3 -CX -XX primesieve_info.pas
- ./primesieve_info
- cd examples
- fpc -B -Fu../ -O3 -CX -XX count_primes.pas
- fpc -B -Fu../ -O3 -CX -XX nth_prime.pas
- fpc -B -Fu../ -O3 -CX -XX store_primes_in_array.pas
- ./count_primes
- ./nth_prime
- ./store_primes_in_array
- examples/count_primes
- examples/nth_prime
- examples/store_primes_in_array
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,53 @@
# primesieve-pas

Pascal bindings for [PrimeSieve](https://github.com/kimwalisch/primesieve) library.

# 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).
- Or [build](https://github.com/kimwalisch/primesieve/blob/master/BUILD.md) library from source.

# Usage
```
(** @example store_primes_in_array.pas
* Store primes in a array. *)
program store_primes_in_array;
{$ifdef FPC}
{$mode Delphi}
{$endif}
uses primesieve;
var
start, stop, n: UInt64;
i, size: NativeUInt;
primes: PInteger;
begin
start := 0;
stop := 1000;
load_libprimesieve();
(* store the primes below 1000 *)
primes := primesieve_generate_primes(start, stop, size, INT_PRIMES);
for i := 0 to size-1 do
WriteLn(primes[i]);
primesieve_free(primes);
n := 1000;
(* store the first 1000 primes *)
primes := primesieve_generate_n_primes(n, start, INT_PRIMES);
for i := 0 to n-1 do
WriteLn(primes[i]);
primesieve_free(primes);
unload_libprimesieve();
end.
```
1 change: 1 addition & 0 deletions examples/count_primes.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Primes below 1000 = 168
2 changes: 2 additions & 0 deletions examples/count_primes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
count: UInt64;

begin
load_libprimesieve();
count := primesieve_count_primes(0, 1000);
WriteLn(Format('Primes below 1000 = %d', [count]));
unload_libprimesieve();
end.
1 change: 1 addition & 0 deletions examples/count_primes_c.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Primes below 1000 = 168
1 change: 1 addition & 0 deletions examples/nth_prime.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000th prime = 7919
2 changes: 2 additions & 0 deletions examples/nth_prime.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

begin
n := 1000;
load_libprimesieve();
if ParamCount > 0 then
TryStrToInt64(ParamStr(1), n);
prime := primesieve_nth_prime(n, 0);
WriteLn(Format('%dth prime = %d', [n, prime]));
unload_libprimesieve();
end.
1 change: 1 addition & 0 deletions examples/nth_prime_c.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000th prime = 7919
135 changes: 135 additions & 0 deletions examples/prev_prime.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
1999
1997
1993
1987
1979
1973
1951
1949
1933
1931
1913
1907
1901
1889
1879
1877
1873
1871
1867
1861
1847
1831
1823
1811
1801
1789
1787
1783
1777
1759
1753
1747
1741
1733
1723
1721
1709
1699
1697
1693
1669
1667
1663
1657
1637
1627
1621
1619
1613
1609
1607
1601
1597
1583
1579
1571
1567
1559
1553
1549
1543
1531
1523
1511
1499
1493
1489
1487
1483
1481
1471
1459
1453
1451
1447
1439
1433
1429
1427
1423
1409
1399
1381
1373
1367
1361
1327
1321
1319
1307
1303
1301
1297
1291
1289
1283
1279
1277
1259
1249
1237
1231
1229
1223
1217
1213
1201
1193
1187
1181
1171
1163
1153
1151
1129
1123
1117
1109
1103
1097
1093
1091
1087
1069
1063
1061
1051
1049
1039
1033
1031
1021
1019
1013
1009
2 changes: 2 additions & 0 deletions examples/prev_prime.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
prime: UInt64;

begin
load_libprimesieve();
primesieve_init(it);

(* primesieve_skipto(it, start_number, stop_hint) *)
Expand All @@ -36,4 +37,5 @@
end;

primesieve_free_iterator(it);
unload_libprimesieve();
end.
Loading

0 comments on commit 9c7fefc

Please sign in to comment.