Use unsigned long longs
This commit is contained in:
parent
c4d48e982a
commit
767f706fea
2 changed files with 24 additions and 24 deletions
|
@ -8,11 +8,11 @@ FactorizationController::FactorizationController(QObject* parent) :
|
||||||
assert(connect(&m_timer, &QTimer::timeout, this, &FactorizationController::onTimerTick));
|
assert(connect(&m_timer, &QTimer::timeout, this, &FactorizationController::onTimerTick));
|
||||||
}
|
}
|
||||||
|
|
||||||
long long FactorizationController::number() const {
|
unsigned long long FactorizationController::number() const {
|
||||||
return m_originalNumber;
|
return m_originalNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long FactorizationController::curFactNumber() const {
|
unsigned long long FactorizationController::curFactNumber() const {
|
||||||
return m_currentFactNumber;
|
return m_currentFactNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,19 +85,19 @@ void FactorizationController::setIterationsPerCycle(int number) {
|
||||||
emit iterationsPerCycleChanged();
|
emit iterationsPerCycleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
long long FactorizationController::currentFactor() const {
|
unsigned long long FactorizationController::currentFactor() const {
|
||||||
return m_currentFactor;
|
return m_currentFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long FactorizationController::stopFactor() const {
|
unsigned long long FactorizationController::stopFactor() const {
|
||||||
return m_stopFactor;
|
return m_stopFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<long long> FactorizationController::factors() const {
|
QList<unsigned long long> FactorizationController::factors() const {
|
||||||
return m_factors;
|
return m_factors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FactorizationController::start(long long number) {
|
void FactorizationController::start(unsigned long long number) {
|
||||||
m_originalNumber = number;
|
m_originalNumber = number;
|
||||||
m_currentFactNumber = number;
|
m_currentFactNumber = number;
|
||||||
m_currentFactor = 2;
|
m_currentFactor = 2;
|
||||||
|
@ -106,7 +106,7 @@ void FactorizationController::start(long long number) {
|
||||||
m_factors.clear();
|
m_factors.clear();
|
||||||
if (m_useSqrtOptimization) {
|
if (m_useSqrtOptimization) {
|
||||||
// we could also just compute this every time, but sqrt is pretty expensive
|
// we could also just compute this every time, but sqrt is pretty expensive
|
||||||
m_stopFactor = static_cast<long long>(std::sqrt(m_currentFactNumber));
|
m_stopFactor = static_cast<unsigned long long>(std::sqrt(m_currentFactNumber));
|
||||||
} else {
|
} else {
|
||||||
m_stopFactor = m_currentFactNumber - 1;
|
m_stopFactor = m_currentFactNumber - 1;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ void FactorizationController::factorize() {
|
||||||
// the new number being factorized, rather than keeping it at the original number.
|
// the new number being factorized, rather than keeping it at the original number.
|
||||||
// (This might make the progress bar jump radically)
|
// (This might make the progress bar jump radically)
|
||||||
if (m_useSqrtOptimization) {
|
if (m_useSqrtOptimization) {
|
||||||
m_stopFactor = static_cast<long long>(std::sqrt(m_currentFactNumber));
|
m_stopFactor = static_cast<unsigned long long>(std::sqrt(m_currentFactNumber));
|
||||||
} else {
|
} else {
|
||||||
m_stopFactor = m_currentFactNumber - 1;
|
m_stopFactor = m_currentFactNumber - 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,12 @@ class FactorizationController : public QObject {
|
||||||
Q_PROPERTY(int iterationsPerCycle READ iterationsPerCycle WRITE setIterationsPerCycle NOTIFY iterationsPerCycleChanged)
|
Q_PROPERTY(int iterationsPerCycle READ iterationsPerCycle WRITE setIterationsPerCycle NOTIFY iterationsPerCycleChanged)
|
||||||
Q_PROPERTY(bool useSqrtOptimization READ useSqrtOptimization WRITE setUseSqrtOptimization NOTIFY useSqrtOptimizationChanged)
|
Q_PROPERTY(bool useSqrtOptimization READ useSqrtOptimization WRITE setUseSqrtOptimization NOTIFY useSqrtOptimizationChanged)
|
||||||
Q_PROPERTY(bool pauseOnFound READ pauseOnFound WRITE setPauseOnFound NOTIFY pauseOnFoundChanged)
|
Q_PROPERTY(bool pauseOnFound READ pauseOnFound WRITE setPauseOnFound NOTIFY pauseOnFoundChanged)
|
||||||
Q_PROPERTY(long long number READ number NOTIFY numberChanged)
|
Q_PROPERTY(unsigned long long number READ number NOTIFY numberChanged)
|
||||||
Q_PROPERTY(long long curFactNumber READ curFactNumber NOTIFY curFactNumberChanged)
|
Q_PROPERTY(unsigned long long curFactNumber READ curFactNumber NOTIFY curFactNumberChanged)
|
||||||
Q_PROPERTY(long long currentFactor READ currentFactor NOTIFY currentFactorChanged)
|
Q_PROPERTY(unsigned long long currentFactor READ currentFactor NOTIFY currentFactorChanged)
|
||||||
Q_PROPERTY(long long stopFactor READ stopFactor NOTIFY stopFactorChanged)
|
Q_PROPERTY(unsigned long long stopFactor READ stopFactor NOTIFY stopFactorChanged)
|
||||||
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
|
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
|
||||||
Q_PROPERTY(QList<long long> factors READ factors NOTIFY factorsChanged)
|
Q_PROPERTY(QList<unsigned long long> factors READ factors NOTIFY factorsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FactorizationController(QObject* parent = nullptr);
|
explicit FactorizationController(QObject* parent = nullptr);
|
||||||
|
@ -99,7 +99,7 @@ class FactorizationController : public QObject {
|
||||||
* @brief Gets the original number being factorized.
|
* @brief Gets the original number being factorized.
|
||||||
* @return The number being factorized.
|
* @return The number being factorized.
|
||||||
*/
|
*/
|
||||||
long long number() const;
|
unsigned long long number() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The current number being factorized.
|
* @brief The current number being factorized.
|
||||||
|
@ -108,7 +108,7 @@ class FactorizationController : public QObject {
|
||||||
* As the factorization process is going on, the number being factorized might change
|
* As the factorization process is going on, the number being factorized might change
|
||||||
* from the original number, as we're dividing it by the found factors.
|
* from the original number, as we're dividing it by the found factors.
|
||||||
*/
|
*/
|
||||||
long long curFactNumber() const;
|
unsigned long long curFactNumber() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the current factor being tested.
|
* @brief Gets the current factor being tested.
|
||||||
|
@ -118,7 +118,7 @@ class FactorizationController : public QObject {
|
||||||
* is a factor, going one by one. This returns the current factor (to be checked in the
|
* is a factor, going one by one. This returns the current factor (to be checked in the
|
||||||
* next iteration).
|
* next iteration).
|
||||||
*/
|
*/
|
||||||
long long currentFactor() const;
|
unsigned long long currentFactor() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the number at which the factorization process will stop
|
* @brief Get the number at which the factorization process will stop
|
||||||
|
@ -128,7 +128,7 @@ class FactorizationController : public QObject {
|
||||||
* If sqrt optimizations are enabled, this will generally be the square root of the number
|
* If sqrt optimizations are enabled, this will generally be the square root of the number
|
||||||
* currently being factorized. If not, it will be the number being factorized - 1.
|
* currently being factorized. If not, it will be the number being factorized - 1.
|
||||||
*/
|
*/
|
||||||
long long stopFactor() const;
|
unsigned long long stopFactor() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the list of discovered factors (may not be complete).
|
* @brief Gets the list of discovered factors (may not be complete).
|
||||||
|
@ -138,7 +138,7 @@ class FactorizationController : public QObject {
|
||||||
* be complete (if the computation is still running). If you need to know whether you
|
* be complete (if the computation is still running). If you need to know whether you
|
||||||
* can trust this result, check isFinished first.
|
* can trust this result, check isFinished first.
|
||||||
*/
|
*/
|
||||||
QList<long long> factors() const;
|
QList<unsigned long long> factors() const;
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
// region: Setters
|
// region: Setters
|
||||||
|
@ -189,7 +189,7 @@ class FactorizationController : public QObject {
|
||||||
* This will start a 0-tick timer, which triggers a partial computation on each run,
|
* This will start a 0-tick timer, which triggers a partial computation on each run,
|
||||||
* to let the event loop cycle in between. This implementation does NOT rely on threads.
|
* to let the event loop cycle in between. This implementation does NOT rely on threads.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void start(long long number);
|
Q_INVOKABLE void start(unsigned long long number);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stops the ongoing factorization process.
|
* @brief Stops the ongoing factorization process.
|
||||||
|
@ -241,11 +241,11 @@ class FactorizationController : public QObject {
|
||||||
bool m_useSqrtOptimization; ///< Indicates whether to use the sqrt optimization
|
bool m_useSqrtOptimization; ///< Indicates whether to use the sqrt optimization
|
||||||
bool m_pauseOnFound; ///< Indicates whether the computation should be paused when a new factor is found.
|
bool m_pauseOnFound; ///< Indicates whether the computation should be paused when a new factor is found.
|
||||||
int m_iterationsPerCycle; ///< The number of iterations to perform per cycle.
|
int m_iterationsPerCycle; ///< The number of iterations to perform per cycle.
|
||||||
long long m_currentFactNumber; ///< The number currently being factorized.
|
unsigned long long m_currentFactNumber; ///< The number currently being factorized.
|
||||||
long long m_originalNumber; ///< The original input number.
|
unsigned long long m_originalNumber; ///< The original input number.
|
||||||
long long m_currentFactor; ///< The current divisor being checked.
|
unsigned long long m_currentFactor; ///< The current divisor being checked.
|
||||||
long long m_stopFactor; ///< The stopping limit (square root of original number, saved for efficiency).
|
unsigned long long m_stopFactor; ///< The stopping limit (square root of original number, saved for efficiency).
|
||||||
QList<long long> m_factors; ///< List of discovered prime factors.
|
QList<unsigned long long> m_factors; ///< List of discovered prime factors.
|
||||||
QTimer m_timer; ///< Timer for stepwise execution.
|
QTimer m_timer; ///< Timer for stepwise execution.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue