[mathicgb] 09/393: working on HashTable, soon to be HashMap in mathic, and how it is used in mathicgb. So far, BjarkeGeobucket2 is in the midst of being simlpified.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:21 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 c2445ce061f9c214052341914bc1679f633c6905
Author: Mike Stillman <mikestillman1 at gmail.com>
Date:   Fri Aug 3 16:56:45 2012 -0400

    working on HashTable, soon to be HashMap in mathic, and how it is used in mathicgb.  So far, BjarkeGeobucket2 is in the midst of being simlpified.
---
 src/mathicgb/BjarkeGeobucket2.cpp | 50 ++++++++++++++++++++-------------------
 src/mathicgb/BjarkeGeobucket2.hpp | 39 +++++++++++++-----------------
 2 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/src/mathicgb/BjarkeGeobucket2.cpp b/src/mathicgb/BjarkeGeobucket2.cpp
index cd2e291..55086ab 100644
--- a/src/mathicgb/BjarkeGeobucket2.cpp
+++ b/src/mathicgb/BjarkeGeobucket2.cpp
@@ -10,15 +10,38 @@ BjarkeGeobucket2::BjarkeGeobucket2(const PolyRing *R0)
   : Reducer(),
     mRing(*R0),
     mHashTableOLD(R0,10),
-    mNodeCount(0),
-    mHeap(Configuration(*R0,4,1))
+    mHeap(GeoConfiguration(*R0,4,1)),
+    mHashTable(BjarkeGeobucket2Configuration(*R0),10)
 {
+  std::cerr << "Creating geobucket2" << std::endl;
 }
 
 BjarkeGeobucket2::~BjarkeGeobucket2()
 {
 }
 
+void BjarkeGeobucket2::insert(Poly::const_iterator first, 
+                              Poly::const_iterator last,
+                              std::vector<node*> &result)
+{
+  for (Poly::const_iterator i = first; i != last; ++i)
+    {
+      monomial monomspace = mRing.allocMonomial(mArena);
+      node *p;
+      mRing.monomialCopy(i.getMonomial(), monomspace);
+      std::pair<bool, node*> found = mHashTable.insert(monomspace, i.getCoefficient());
+      if (found.first)
+        {
+          // remove the monomial.  It should be at the top of the mArena arena.
+          mRing.freeTopMonomial(mArena,monomspace);
+        }
+      else
+        {
+          result.push_back(found.second);
+        }
+    }
+}
+
 ///////////////////////////////////////
 // External interface routines ////////
 ///////////////////////////////////////
@@ -26,54 +49,43 @@ void BjarkeGeobucket2::insertTail(const_term multiplier, const Poly *g1)
 {
   if (g1->nTerms() <= 1) return;
 
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
   HashPoly M;
   mHashTableOLD.insert(multiplier, ++(g1->begin()), g1->end(), M);
 
   if (!M.empty())
     {
       mHeap.push(M.begin(),M.end());
-      mNodeCount += M.size();
     }
 
   stats_n_inserts++;
   stats_n_compares += mHeap.getConfiguration().getComparisons();
   mHeap.getConfiguration().resetComparisons();
-
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
 }
 
 void BjarkeGeobucket2::insert(monomial multiplier, const Poly *g1)
 {
   HashPoly M;
 
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
-
   mHashTableOLD.insert(multiplier, g1->begin(), g1->end(), M);
 
   if (!M.empty())
     {
       mHeap.push(M.begin(),M.end());
-      mNodeCount += M.size();
     }
 
   stats_n_inserts++;
   stats_n_compares += mHeap.getConfiguration().getComparisons();
   mHeap.getConfiguration().resetComparisons();
-
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
 }
 
 bool BjarkeGeobucket2::findLeadTerm(const_term &result)
 {
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
   while (!mHeap.empty())
     {
       if (mHashTableOLD.popTerm(mHeap.top(), result.coeff, result.monom))
         // returns true if mHeap.top() is not the zero element
         return true;
       mHeap.pop();
-      mNodeCount--;
     }
   return false;
 }
@@ -82,9 +94,6 @@ void BjarkeGeobucket2::removeLeadTerm()
 // returns true if there is a term to extract
 {
   mHeap.pop();
-  mNodeCount--;
-
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
 }
 
 void BjarkeGeobucket2::value(Poly &result)
@@ -95,25 +104,18 @@ void BjarkeGeobucket2::value(Poly &result)
     {
       result.appendTerm(t.coeff, t.monom);
       mHeap.pop();
-      mNodeCount--;
     }
-
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
   resetReducer();
 }
 
 void BjarkeGeobucket2::resetReducer()
 {
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
   const_term t;
   while (findLeadTerm(t))
     {
       mHeap.pop();
-      mNodeCount--;
     }
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
   mHashTableOLD.reset();
-  ASSERT(mNodeCount == mHashTableOLD.getNodeCount());
   // how to reset mHeap ?
 }
 
@@ -121,7 +123,7 @@ size_t BjarkeGeobucket2::getMemoryUse() const
 {
   size_t result = mHashTableOLD.getMemoryUse();
   result += mHeap.getMemoryUse();
-  //  std::cerr << "[reducer: " << mHashTableOLD.getMemoryUse() << " " << mHeap.getMemoryUse() << "]" << std::endl;
+  result += mHashTable.memoryUse();
   return result;
 }
 
diff --git a/src/mathicgb/BjarkeGeobucket2.hpp b/src/mathicgb/BjarkeGeobucket2.hpp
index c0baba2..080bdcb 100644
--- a/src/mathicgb/BjarkeGeobucket2.hpp
+++ b/src/mathicgb/BjarkeGeobucket2.hpp
@@ -7,14 +7,6 @@
 #include "Reducer.hpp"
 #include "PolyHashTable.hpp"
 
-template<
-  bool TrackFront,
-  bool MinBucketBinarySearch,
-  bool Deduplicate,
-  bool Premerge,
-  bool CollectMax,
-  int BucketStorage,
-  size_t InsertFactor = 1>
 class GeoConfiguration {
 public:
   GeoConfiguration(
@@ -37,20 +29,19 @@ public:
   }
   bool cmpLessThan(CompareResult r) const {return r;}
 
-  static const bool supportDeduplication = Deduplicate;
-  bool cmpEqual(CompareResult r) const {return r;} // NOT USED IN OUR CASE HERRE!
+  static const bool supportDeduplication = false;
+  bool cmpEqual(CompareResult r) const {ASSERT(false);return r;} // NOT USED IN OUR CASE HERRE!
   Entry deduplicate(const Entry& a, const Entry& /* b */) const {ASSERT(false); return a;}
 
   size_t getComparisons() const {return _comparisons;}
   void resetComparisons() const {_comparisons = 0;}
 
-  static const bool minBucketBinarySearch = MinBucketBinarySearch;
-  static const bool trackFront = TrackFront;
-  static const bool premerge = Premerge;
-  static const bool collectMax = CollectMax;
-  static const mic::GeobucketBucketStorage bucketStorage =
-    (mic::GeobucketBucketStorage)BucketStorage;
-  static const size_t insertFactor = InsertFactor;
+  static const bool minBucketBinarySearch = true; // MinBucketBinarySearch;
+  static const bool trackFront = true; //TrackFront;
+  static const bool premerge = false;
+  static const bool collectMax = false;
+  static const mic::GeobucketBucketStorage bucketStorage = static_cast<mic::GeobucketBucketStorage>(1);
+  static const size_t insertFactor = 1;
 
 private:
   mutable size_t _comparisons;
@@ -99,16 +90,20 @@ protected:
   void resetReducer();
 
 private:
-  void insert(const_term multiplier, Poly::iterator first, Poly::iterator last);
-
+  typedef mic::HashTable<BjarkeGeobucket2Configuration>::Node node;
   typedef PolyHashTable::MonomialArray HashPoly;
-  typedef GeoConfiguration<true,true,false,false,false,1,1> Configuration;
 
-  size_t mNodeCount;  // number of (distinct) monomials in mHeap
+  void insert(Poly::const_iterator first, 
+              Poly::const_iterator last,
+              std::vector<node*> &result);
+
+  void insert(const_term multiplier, Poly::iterator first, Poly::iterator last);
+
 
   const PolyRing &mRing;
   PolyHashTable mHashTableOLD;
-  mic::Geobucket< Configuration > mHeap;
+  mic::HashTable<BjarkeGeobucket2Configuration> mHashTable;
+  mic::Geobucket< GeoConfiguration > mHeap;
 };
 
 #endif

-- 
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