moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kbruch / src / primenumber.h
blob8f135b26296d14cf746d1a5f7a5402d7f19d3524
1 /***************************************************************************
2 primenumber.h - class primenumber
3 -------------------
4 begin : Tue Nov 27 16:40:42 CET 2001
5 copyright : (C) 2001 by Sebastian Stein
6 email : seb.kde@hpfsc.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef PRIMZAHL_H
19 #define PRIMZAHL_H
21 #include <qvaluevector.h>
23 typedef QValueVector<uint> UnsignedIntArray;
25 /** Class to handle prime numbers.
26 * The prime numbers are stored in a static vector, so that different instances
27 * can use them. Each time a higher prime number is needed, the new found prime
28 * number is stored in the vector. To check if a given number is a prime number
29 * this vector is scanned and if needed new prime numbers are generated. This
30 * algorithm should reduce calculation time and speed up every program using
31 * this prime number class.
32 * \author Sebastian Stein */
33 class primenumber
35 public:
36 /** constructor */
37 primenumber();
39 /** destructor */
40 ~primenumber();
42 /** returns wether the given number is a prime number */
43 short isPrimeNumber(uint number);
45 /** returns the next prime number */
46 unsigned int get_next();
48 /** returns the first prime number */
49 unsigned int get_first() const;
51 /** return the last known prime number */
52 unsigned int get_last() const;
54 /** returns the current prime number */
55 unsigned int get_current() const;
57 /** moves the internal pointer to the first prime number */
58 void move_first();
60 /** moves the internal pointer to the last prime number */
61 void move_last();
63 /** moves the internal pointer to the next prime number */
64 void move_forward();
66 /** moves the internal pointer to the previous prime number */
67 void move_back();
69 /** Displays all known prime numbers, mainly used for debugging. */
70 void display_all();
71 private:
72 /** a vector storing all known prime numbers, access for all objects;
73 * we are using the vector<T> template; so we do not have to think
74 * about dynamic mem manipulation */
75 static UnsignedIntArray prim_vector;
77 /** current selected prime number */
78 UnsignedIntArray::iterator current_pos;
80 /** finds next prime number and adds it to the vector */
81 void find_next();
83 #endif