[mathic] 33/62: Added support for MATHIC_SLOW_DEBUG and MATHIC_SLOW_ASSERT to disable the very slowest asserts for a standard build with asserts.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Wed Apr 1 11:36:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository mathic.

commit 37652a4af2cc2acb353da31ac622afe18e336552
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Tue Aug 7 07:16:09 2012 -0400

    Added support for MATHIC_SLOW_DEBUG and MATHIC_SLOW_ASSERT to disable the very slowest asserts for a standard build with asserts.
---
 src/mathic/ComTree.h   |  4 ++--
 src/mathic/Geobucket.h |  5 +++--
 src/mathic/Heap.h      | 11 ++++++-----
 src/mathic/TourTree.h  | 19 ++++++++++++-------
 src/mathic/stdinc.h    | 12 +++++++++---
 5 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/mathic/ComTree.h b/src/mathic/ComTree.h
old mode 100644
new mode 100755
index dcc5d60..f6cc77c
--- a/src/mathic/ComTree.h
+++ b/src/mathic/ComTree.h
@@ -142,7 +142,7 @@ namespace mathic {
   }
 
   template<class E, bool FI>
-	E& ComTree<E, FI>::operator[](Node n) {
+  inline E& ComTree<E, FI>::operator[](Node n) {
 	if (!FI)
 	  return _array[n._index];
 	char* base = reinterpret_cast<char*>(_array);
@@ -152,7 +152,7 @@ namespace mathic {
   }
 
   template<class E, bool FI>
-	const E& ComTree<E, FI>::operator[](Node n) const {
+  inline const E& ComTree<E, FI>::operator[](Node n) const {
 	return const_cast<ComTree<E, FI>*>(this)->operator[](n);
   }
 
diff --git a/src/mathic/Geobucket.h b/src/mathic/Geobucket.h
index f741b8e..6bb40fc 100755
--- a/src/mathic/Geobucket.h
+++ b/src/mathic/Geobucket.h
@@ -430,11 +430,12 @@ namespace mathic {
 		break;
 	  }
 	}
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
   template<class C>
   void Geobucket<C>::clear() {
+	MATHIC_ASSERT(isValid());
     _entryCount = 0;
     _front.clear();
     for (Bucket* bucket = _bucketBegin; bucket != _bucketEnd; ++bucket)
@@ -450,7 +451,7 @@ namespace mathic {
 	maxBucket->pop_back();
 	--_entryCount;
 	_front.keyDecreased(maxBucket);
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
 	return top;
   }
 
diff --git a/src/mathic/Heap.h b/src/mathic/Heap.h
index a3f7978..860da51 100755
--- a/src/mathic/Heap.h
+++ b/src/mathic/Heap.h
@@ -93,7 +93,7 @@ namespace mathic {
 	void Heap<C>::push(Entry entry) {
 	_tree.pushBack(entry);
 	moveValueUp(_tree.lastLeaf(), entry);
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
   template<class C>
@@ -106,11 +106,12 @@ namespace mathic {
   template<class C>
 	void Heap<C>::decreaseTop(Entry newEntry) {
 	moveValueUp(moveHoleDown(Node()), newEntry);
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
   template<class C>
   void Heap<C>::clear() {
+	MATHIC_ASSERT(isValid());
     _tree.clear();
 	MATHIC_ASSERT(isValid());
   }
@@ -123,7 +124,7 @@ namespace mathic {
 	if (!_tree.empty())
 	  moveValueUp(moveHoleDown(Node()), movedValue);
 	return top;
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
   template<class C>
@@ -174,7 +175,7 @@ namespace mathic {
 		value = _tree[_tree.lastLeaf()];
 		_tree.popBack();
 		if (origPos == _tree.lastLeaf().next()) {
-		  MATHIC_ASSERT(isValid());
+		  MATHIC_SLOW_ASSERT(isValid());
 		  return;
 		}
 		goto again;
@@ -182,7 +183,7 @@ namespace mathic {
 		break;
 	}
 	_tree[pos] = value;
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
 #ifdef MATHIC_DEBUG
diff --git a/src/mathic/TourTree.h b/src/mathic/TourTree.h
index e2459e9..71bcef0 100755
--- a/src/mathic/TourTree.h
+++ b/src/mathic/TourTree.h
@@ -81,8 +81,10 @@ namespace mathic {
 
   template<class C>
   void TourTree<C>::clear() {
+	MATHIC_ASSERT(isValid());
     _tree.clear();
     _players.clear();
+	MATHIC_ASSERT(isValid());
   }
 
   template<class C>
@@ -105,13 +107,13 @@ namespace mathic {
 
   template<class C>
 	void TourTree<C>::push(Entry entry) {
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
 	if (!_tree.hasFreeCapacity(2))
 	  reallocate();
 	if (empty()) {
 	  _players.push_back(Player(entry, Node()));
 	  _tree.pushBackWithCapacity(&_players.back());
-	  MATHIC_ASSERT(isValid());
+	  MATHIC_SLOW_ASSERT(isValid());
 	  return;
 	}
 	// move leaf down as left child
@@ -138,7 +140,7 @@ namespace mathic {
 	  pos = posParent;
 	  posParent = pos.parent();
 	} while (!pos.isRoot());
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
   template<class C>
@@ -159,7 +161,7 @@ namespace mathic {
 		player = opponent;
 	  _tree[pos.parent()] = player;
 	}
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
   }
 
   template<class C>
@@ -169,7 +171,7 @@ namespace mathic {
 	if (_tree.lastLeaf().isRoot()) {
 	  _tree.popBack();
 	  _players.pop_back();
-	  MATHIC_ASSERT(isValid());
+	  MATHIC_SLOW_ASSERT(isValid());
 	  return top;
 	}
 	Node parentPos = _tree.lastLeaf().parent();
@@ -202,7 +204,7 @@ namespace mathic {
 	  pos = pos.parent();
 	  _tree[pos] = player;
 	}
-	MATHIC_ASSERT(isValid());
+	MATHIC_SLOW_ASSERT(isValid());
 	return top;
   }
 
@@ -219,6 +221,7 @@ namespace mathic {
 
   template<class C>
 	void TourTree<C>::reallocate() {
+	MATHIC_ASSERT(isValid());
 	_tree.increaseCapacity();
 	const size_t newCapacity = _tree.capacity();
 	if (_players.empty())
@@ -236,7 +239,9 @@ namespace mathic {
 #ifdef MATHIC_DEBUG
   template<class C>
 	bool TourTree<C>::isValid() const {
-	MATHIC_ASSERT(_tree.capacity() + 1 <= 2 * _players.capacity());
+	MATHIC_ASSERT
+	  ((_tree.empty() && _players.empty()) || // just constructed
+	   (_tree.capacity() + 1 <= 2 * _players.capacity()));
 	MATHIC_ASSERT((empty() && _players.empty()) ||
 		   (_tree.size() + 1 == 2 * _players.size()));
 	// _tree points into _players
diff --git a/src/mathic/stdinc.h b/src/mathic/stdinc.h
index b4368bf..6eff6dd 100755
--- a/src/mathic/stdinc.h
+++ b/src/mathic/stdinc.h
@@ -1,8 +1,14 @@
 #ifndef MATHIC_STDINC_GUARD
 #define MATHIC_STDINC_GUARD
 
-#if (defined MATHIC_DEBUG) && (defined MATHIC_NDEBUG)
-#error Both MATHIC_DEBUG and MATHIC_NDEBUG defined
+#ifdef MATHIC_SLOW_DEBUG
+// for asserts that take a long time.
+#define MATHIC_SLOW_ASSERT(X) MATHIC_ASSERT(X)
+#ifndef MATHIC_DEBUG
+#define MATHIC_DEBUG
+#endif
+#else
+#define MATHIC_SLOW_ASSERT(X)
 #endif
 
 #ifdef MATHIC_DEBUG
@@ -13,7 +19,7 @@
 #endif
 
 namespace mathic {
-  static const unsigned long BitsPerByte = 8;
+  static unsigned long const BitsPerByte = 8;
 }
 
 #ifndef MATHIC_NO_MIC_NAMESPACE

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathic.git



More information about the debian-science-commits mailing list