[mathicgb] 355/393: Improved the implementation of ReducerHashPack so that it is a bit faster and so that it does not move monomials out of hash table nodes. The latter was a barrier to making changes in PolyHashTable.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.
commit 908fb762b2141e3169b3243ea1ea9c9604f315f1
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Tue Sep 3 13:13:21 2013 +0200
Improved the implementation of ReducerHashPack so that it is a bit faster and so that it does not move monomials out of hash table nodes. The latter was a barrier to making changes in PolyHashTable.
---
build/vs12/mathicgb-lib/mathicgb-lib.vcxproj | 2 -
.../vs12/mathicgb-lib/mathicgb-lib.vcxproj.filters | 6 --
src/mathicgb/ReducerHashPack.hpp | 102 ++++++++-------------
3 files changed, 40 insertions(+), 70 deletions(-)
diff --git a/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj b/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj
index eed2994..541cb6a 100755
--- a/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj
+++ b/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj
@@ -441,7 +441,6 @@
<ItemGroup>
<ClCompile Include="..\..\..\src\mathicgb.cpp" />
<ClCompile Include="..\..\..\src\mathicgb\Basis.cpp" />
- <ClCompile Include="..\..\..\src\mathicgb\BjarkeGeobucket.cpp" />
<ClCompile Include="..\..\..\src\mathicgb\BjarkeGeobucket2.cpp" />
<ClCompile Include="..\..\..\src\mathicgb\CFile.cpp" />
<ClCompile Include="..\..\..\src\mathicgb\ChainedHashTable.cpp" />
@@ -478,7 +477,6 @@
<ClInclude Include="..\..\..\src\mathicgb.h" />
<ClInclude Include="..\..\..\src\mathicgb\Atomic.hpp" />
<ClInclude Include="..\..\..\src\mathicgb\Basis.hpp" />
- <ClInclude Include="..\..\..\src\mathicgb\BjarkeGeobucket.hpp" />
<ClInclude Include="..\..\..\src\mathicgb\BjarkeGeobucket2.hpp" />
<ClInclude Include="..\..\..\src\mathicgb\CFile.hpp" />
<ClInclude Include="..\..\..\src\mathicgb\ChainedHashTable.hpp" />
diff --git a/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj.filters b/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj.filters
index 4a92b2b..4e35a20 100755
--- a/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj.filters
+++ b/build/vs12/mathicgb-lib/mathicgb-lib.vcxproj.filters
@@ -11,9 +11,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\..\..\src\mathicgb\BjarkeGeobucket.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\src\mathicgb\BjarkeGeobucket2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -115,9 +112,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="..\..\..\src\mathicgb\BjarkeGeobucket.hpp">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\src\mathicgb\BjarkeGeobucket2.hpp">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/src/mathicgb/ReducerHashPack.hpp b/src/mathicgb/ReducerHashPack.hpp
index 2563126..834d202 100755
--- a/src/mathicgb/ReducerHashPack.hpp
+++ b/src/mathicgb/ReducerHashPack.hpp
@@ -65,8 +65,6 @@ private:
void insertEntry(MultipleWithPos* entry);
const PolyRing& mRing;
- term mLeadTerm;
- bool mLeadTermKnown;
Queue<Configuration> mQueue;
PolyHashTable mHashTable;
memt::BufferPool mPool;
@@ -75,8 +73,6 @@ private:
template<template<typename> class Q>
ReducerHashPack<Q>::ReducerHashPack(const PolyRing& ring):
mRing(ring),
- mLeadTerm(0, mRing.allocMonomial()),
- mLeadTermKnown(false),
mQueue(Configuration(ring)),
mHashTable(&ring, 10),
mPool(sizeof(MultipleWithPos))
@@ -101,7 +97,6 @@ template<template<typename> class Q>
ReducerHashPack<Q>::~ReducerHashPack()
{
resetReducer();
- mRing.freeMonomial(mLeadTerm.monom);
}
///////////////////////////////////////
@@ -173,66 +168,54 @@ void ReducerHashPack<Q>::MultipleWithPos::destroy(const PolyRing& ring) {
}
template<template<typename> class Q>
-bool ReducerHashPack<Q>::leadTerm(const_term& result)
-{
- if (mLeadTermKnown) {
- result = mLeadTerm;
- return true;
- }
-
- do {
- if (mQueue.empty())
- return false;
+bool ReducerHashPack<Q>::leadTerm(const_term& result) {
+ while (!mQueue.empty()) {
MultipleWithPos* entry = mQueue.top();
MATHICGB_ASSERT(entry != 0);
- // remove node from hash table first since we are going to be changing
- // the monomial after this, and if we do that before the hash value will
- // change.
- mHashTable.remove(entry->node);
-
- // extract information into mLeadTerm
- mLeadTerm.monom.swap(entry->current);
- entry->node->mono() = entry->current;
- mLeadTerm.coeff = entry->node->value();
-
- // remove old monomial from hash table and insert next
- MATHICGB_ASSERT(entry->pos != entry->end);
- while (true) {
- ++entry->pos;
- if (entry->pos == entry->end) {
- mQueue.pop();
- entry->destroy(mRing);
- mPool.free(entry);
- break;
- }
- term t;
- t.monom = entry->current;
- entry->computeCurrent(mRing, t.monom);
- entry->currentCoefficient(mRing, t.coeff);
-
- std::pair<bool, PolyHashTable::node*> p = mHashTable.insert(t);
- if (p.first) {
- entry->node = p.second;
- mQueue.decreaseTop(entry);
- break;
- }
+ if (!mRing.coefficientIsZero(entry->node->value())) {
+ result.coeff = entry->node->value();
+ result.monom = entry->node->mono();
+ return true;
}
- } while (mRing.coefficientIsZero(mLeadTerm.coeff));
-
- result = mLeadTerm;
- mLeadTermKnown = true;
- return true;
+ removeLeadTerm();
+ }
+ return false;
}
template<template<typename> class Q>
-void ReducerHashPack<Q>::removeLeadTerm()
-{
- if (!mLeadTermKnown) {
- const_term dummy;
- leadTerm(dummy);
+void ReducerHashPack<Q>::removeLeadTerm() {
+ MATHICGB_ASSERT(!mQueue.empty());
+
+ MultipleWithPos* entry = mQueue.top();
+ MATHICGB_ASSERT(entry != 0);
+
+ // remove node from hash table first since we are going to be changing
+ // the monomial after this, and if we do that before the hash value will
+ // change.
+ mHashTable.remove(entry->node);
+
+ MATHICGB_ASSERT(entry->pos != entry->end);
+ while (true) {
+ ++entry->pos;
+ if (entry->pos == entry->end) {
+ mQueue.pop();
+ entry->destroy(mRing);
+ mPool.free(entry);
+ break;
+ }
+ term t;
+ t.monom = entry->current;
+ entry->computeCurrent(mRing, t.monom);
+ entry->currentCoefficient(mRing, t.coeff);
+
+ std::pair<bool, PolyHashTable::node*> p = mHashTable.insert(t);
+ if (p.first) {
+ entry->node = p.second;
+ mQueue.decreaseTop(entry);
+ break;
+ }
}
- mLeadTermKnown = false;
}
template<template<typename> class Q>
@@ -246,7 +229,6 @@ void ReducerHashPack<Q>::insertEntry(MultipleWithPos* entry) {
std::pair<bool, PolyHashTable::node*> p = mHashTable.insert(t);
if (p.first) {
- mLeadTermKnown = false;
entry->node = p.second;
mQueue.push(entry);
return;
@@ -259,13 +241,9 @@ void ReducerHashPack<Q>::insertEntry(MultipleWithPos* entry) {
template<template<typename> class Q>
void ReducerHashPack<Q>::resetReducer()
{
- mLeadTermKnown = false;
MonomialFree freeer(mRing);
-#if 0
- //TODO: reinstate these lines, once Geobucket, TourTree and Heap can all handle them
mQueue.forAll(freeer);
mQueue.clear();
-#endif
mHashTable.reset();
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git
More information about the debian-science-commits
mailing list