[Libprime-devel-cvs] CVS: libprime/src/libprime princ.cpp,1.5,1.6 prrange.cpp,1.5,1.6 prval.cpp,1.5,
Status: Inactive
Brought to you by:
simmo
|
From: Andrew S. <si...@us...> - 2001-12-08 13:55:02
|
Update of /cvsroot/libprime/libprime/src/libprime
In directory usw-pr-cvs1:/tmp/cvs-serv869/src/libprime
Modified Files:
princ.cpp prrange.cpp prval.cpp
Log Message:
working towards a 0.2 libprime release
Index: princ.cpp
===================================================================
RCS file: /cvsroot/libprime/libprime/src/libprime/princ.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- princ.cpp 2001/12/06 08:57:48 1.5
+++ princ.cpp 2001/12/08 13:54:57 1.6
@@ -1,21 +1,21 @@
/*
- libprime
- princ.cpp
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ * libprime
+ * Copyright (c) 2001 Andrew Simmonds <si...@ii...>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
#include "libprime.h"
using namespace std;
Index: prrange.cpp
===================================================================
RCS file: /cvsroot/libprime/libprime/src/libprime/prrange.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- prrange.cpp 2001/12/06 08:57:48 1.5
+++ prrange.cpp 2001/12/08 13:54:57 1.6
@@ -1,77 +1,84 @@
/*
- libprime
- prrange.cpp
+ * libprime
+ * Copyright (c) 2001 Andrew Simmonds <si...@ii...>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
#include "libprime.h"
using namespace std;
+
+PrimeRange::PrimeRange(culong culMaxPrimeNumber):culMaxPrime(culMaxPrimeNumber)
+{
+ ulHits = 1;
+ uchar *ucTest;
-PrimeRange::PrimeRange(culong culMaxPrimeNumber) : culMaxPrime(culMaxPrimeNumber) {
- ulHits = 1;
- uchar *ucTest;
-
- //Create PrimeStorage Space in Memory.
- culong culAllocatedMemorySize = (culMaxPrime>>4)+1;
- ucPrimeStorage = ucTest = new uchar [culAllocatedMemorySize];
+ culong culAllocatedMemorySize = (culMaxPrime >> 4) + 1;
+ ucPrimeStorage = ucTest = new uchar[culAllocatedMemorySize];
- for (ulCount = 0; ulCount<culAllocatedMemorySize; ulCount++)
+ for (ulCount = 0; ulCount < culAllocatedMemorySize; ulCount++)
*ucTest++ = 0x00;
}
-PrimeRange::~PrimeRange() {
- delete []ucPrimeStorage;
+PrimeRange::~PrimeRange()
+{
+ delete[]ucPrimeStorage;
}
-ulong PrimeRange::InitPrimeRange() { //Search for the individual primes and add them to 'feld'
- ulong BlehTest=1, BlehIndex=0;
-
- while ((BlehTest+=2) < culMaxPrime) {
- if (!TestOfPrimeness(ucPrimeStorage, BlehTest)) {
- ++ulHits;
-
- for (BlehIndex = 3*BlehTest; BlehIndex<culMaxPrime; BlehIndex += BlehTest<<1)
- SetPrimes(ucPrimeStorage, BlehIndex);
- }
- }
- return ulHits;
+ulong PrimeRange::init()
+{
+ ulong BlehTest = 1, BlehIndex = 0;
+
+ while ((BlehTest += 2) < culMaxPrime) {
+ if (!TestOfPrimeness(ucPrimeStorage, BlehTest)) {
+ ++ulHits;
+
+ for (BlehIndex = 3 * BlehTest; BlehIndex < culMaxPrime;
+ BlehIndex += BlehTest << 1)
+ SetPrimes(ucPrimeStorage, BlehIndex);
+ }
+ }
+ return ulHits;
}
-inline bool PrimeRange::TestOfPrimeness(uchar *PrimeStore, ulong PrimeCount) {
- return (*(PrimeStore+((PrimeCount)>>4))&(1<<(((PrimeCount)&15L)>>1)))?true:false;
+inline bool PrimeRange::TestOfPrimeness(uchar * PrimeStore, ulong PrimeCount)
+{
+ return (*(PrimeStore + ((PrimeCount) >> 4)) &
+ (1 << (((PrimeCount) & 15L) >> 1))) ? true : false;
}
-inline bool PrimeRange::SetPrimes(uchar *PrimeStore, ulong PrimeCount) {
- return (*(PrimeStore+((PrimeCount)>>4))|=1<<(((PrimeCount)&15L)>>1))?true:false;
+inline bool PrimeRange::SetPrimes(uchar * PrimeStore, ulong PrimeCount)
+{
+ return (*(PrimeStore + ((PrimeCount) >> 4)) |=
+ 1 << (((PrimeCount) & 15L) >> 1)) ? true : false;
}
-
-ulong PrimeRange::GetPrimeRange(ulong ulStartOfRange, ulong ulEndOfRange, aulong& PrimeList) {
- ulong ulLocalHits = 0;
- ulCount = ulStartOfRange-2;
- if (ulStartOfRange%2==0)
- ulCount++; //Make it an odd number.
-
- while ((ulCount+=2)<=ulEndOfRange)
- {
- if (!TestOfPrimeness(ucPrimeStorage, ulCount))
- {
- PrimeList[ ulLocalHits ] = ulCount;
- ulLocalHits++;
- }
- }
- return ulLocalHits;
+ulong PrimeRange::get(ulong ulStartOfRange, ulong ulEndOfRange,
+ aulong & PrimeList)
+{
+ ulong ulLocalHits = 0;
+
+ ulCount = ulStartOfRange - 2;
+ if (ulStartOfRange % 2 == 0)
+ ulCount++;
+
+ while ((ulCount += 2) <= ulEndOfRange) {
+ if (!TestOfPrimeness(ucPrimeStorage, ulCount)) {
+ PrimeList[ulLocalHits] = ulCount;
+ ulLocalHits++;
+ }
+ }
+ return ulLocalHits;
}
Index: prval.cpp
===================================================================
RCS file: /cvsroot/libprime/libprime/src/libprime/prval.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- prval.cpp 2001/12/06 08:57:48 1.5
+++ prval.cpp 2001/12/08 13:54:57 1.6
@@ -1,30 +1,31 @@
/*
- libprime
- prval.cpp
+ * libprime
+ * Copyright (c) 2001 Andrew Simmonds <si...@ii...>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
#include "libprime.h"
using namespace std;
-bool GetIsPrime(ulong TestPrimeNumber) {
- bool isPrime = true;
- for(ulong i=2;i<=(TestPrimeNumber / 2);i++)
- if((TestPrimeNumber%i) == 0)
- isPrime = false;
+bool GetIsPrime(ulong TestPrimeNumber)
+{
+ bool isPrime = true;
+ for (ulong i = 2; i <= (TestPrimeNumber / 2); i++)
+ if ((TestPrimeNumber % i) == 0)
+ isPrime = false;
- return isPrime;
+ return isPrime;
}
|