author | jacint |
Tue, 20 Jul 2004 14:29:16 +0000 | |
changeset 714 | 104069336039 |
child 718 | 75d36edc6bc4 |
permissions | -rw-r--r-- |
alpar@711 | 1 |
// -*- mode:C++ -*- |
alpar@711 | 2 |
#ifndef HUGO_BENCH_TEST_H |
alpar@711 | 3 |
#define HUGO_BENCH_TEST_H |
alpar@711 | 4 |
|
alpar@711 | 5 |
#include<vector> |
alpar@711 | 6 |
|
alpar@711 | 7 |
///An experimental typedef factory |
alpar@711 | 8 |
#define GRAPH_TYPEDEF_FACTORY(Graph) \ |
alpar@711 | 9 |
typedef typename Graph:: Node Node;\ |
alpar@711 | 10 |
typedef typename Graph:: NodeIt NodeIn;\ |
alpar@711 | 11 |
typedef typename Graph:: Edge Edge;\ |
alpar@711 | 12 |
typedef typename Graph:: EdgeIt EdgeIt;\ |
alpar@711 | 13 |
typedef typename Graph:: InEdgeIt InEdgeIt;\ |
alpar@711 | 14 |
typedef typename Graph::OutEdgeIt OutEdgeIt; |
alpar@711 | 15 |
|
alpar@711 | 16 |
#define GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph) \ |
alpar@711 | 17 |
typedef Graph:: Node Node;\ |
alpar@711 | 18 |
typedef Graph:: NodeIt NodeIn;\ |
alpar@711 | 19 |
typedef Graph:: Edge Edge;\ |
alpar@711 | 20 |
typedef Graph:: EdgeIt EdgeIt;\ |
alpar@711 | 21 |
typedef Graph:: InEdgeIt InEdgeIt;\ |
alpar@711 | 22 |
typedef Graph::OutEdgeIt OutEdgeIt; |
alpar@711 | 23 |
|
alpar@711 | 24 |
|
alpar@711 | 25 |
///A primitive primtest |
alpar@711 | 26 |
bool isPrim(int n) |
alpar@711 | 27 |
{ |
alpar@711 | 28 |
if(n%2) { |
alpar@711 | 29 |
for(int k=3;n/k>=k;k+=2) |
alpar@711 | 30 |
if(!(n%k)) return false; |
alpar@711 | 31 |
return true; |
alpar@711 | 32 |
} |
alpar@711 | 33 |
return false; |
alpar@711 | 34 |
} |
alpar@711 | 35 |
|
alpar@711 | 36 |
///Finds the smallest prime not less then \c n. |
alpar@711 | 37 |
int nextPrim(int n) |
alpar@711 | 38 |
{ |
alpar@711 | 39 |
for(n+=!(n%2);!isPrim(n);n+=2) ; |
alpar@711 | 40 |
return n; |
alpar@711 | 41 |
} |
alpar@711 | 42 |
|
alpar@711 | 43 |
|
alpar@711 | 44 |
/// Class to generate consecutive primes |
alpar@711 | 45 |
class Primes |
alpar@711 | 46 |
{ |
alpar@711 | 47 |
std::vector<int> primes; |
alpar@711 | 48 |
int n; |
alpar@711 | 49 |
|
alpar@711 | 50 |
bool isPrime(int m) |
alpar@711 | 51 |
{ |
alpar@711 | 52 |
for(int i=0;m<primes[i]*primes[i];i++) if(!(m%primes[i])) return false; |
alpar@711 | 53 |
return true; |
alpar@711 | 54 |
} |
alpar@711 | 55 |
public: |
alpar@711 | 56 |
Primes() : n(1) {} |
alpar@711 | 57 |
|
alpar@711 | 58 |
int operator() () |
alpar@711 | 59 |
{ |
alpar@711 | 60 |
if(primes.size()==0) { |
alpar@711 | 61 |
primes.push_back(2); |
alpar@711 | 62 |
return 2; |
alpar@711 | 63 |
} |
alpar@711 | 64 |
else { |
alpar@711 | 65 |
do n+=2; while(!isPrime(n)); |
alpar@711 | 66 |
primes.push_back(n); |
alpar@711 | 67 |
return n; |
alpar@711 | 68 |
} |
alpar@711 | 69 |
} |
alpar@711 | 70 |
}; |
alpar@711 | 71 |
|
alpar@711 | 72 |
|
alpar@711 | 73 |
#endif |