Switched counters to macros
authorDmitriy Morozov <morozov@cs.duke.edu>
Wed, 07 Feb 2007 14:00:39 -0500
changeset 17 b1757b725708
parent 16 626e2b875d21
child 18 a4d403087fbc
child 21 565a3e60eb7e
Switched counters to macros
include/counter.h
include/filtration.hpp
include/lowerstarfiltration.hpp
--- a/include/counter.h	Wed Jan 31 16:53:35 2007 -0500
+++ b/include/counter.h	Wed Feb 07 14:00:39 2007 -0500
@@ -12,17 +12,23 @@
 #include <string>
 #include <iostream>
 
+#ifndef COUNTERS
+#define Count(x)
+#define CountNum(x,y)
+#else // COUNTERS
+#define Count(x) counters.inc(x)
+#define CountNum(x,y) counters.inc(x,y)
+#endif
+
 typedef 		unsigned long 		CounterType;
 typedef			std::string			KeyType;
 
 class CounterFactory
 {
 	private:
-#ifdef COUNTERS
 		typedef				std::map<int, CounterType> 			CountersMap;
 		typedef				std::map<KeyType, CountersMap>		KeyMap;
 		KeyMap				ctrs;
-#endif // COUNTERS
 		
 	public:
 		~CounterFactory()
@@ -48,16 +54,12 @@
 
 		void inc(const KeyType& key, int num = 0)
 		{
-#ifdef COUNTERS
 			ctrs[key][num]++;
-#endif // COUNTERS
 		}
 
 		CounterType lookup(const KeyType& key, int num = 0) const
 		{
-#ifdef COUNTERS
 			return const_cast<KeyMap&>(ctrs)[key][num];
-#endif // COUNTERS
 		}
 };
 
--- a/include/filtration.hpp	Wed Jan 31 16:53:35 2007 -0500
+++ b/include/filtration.hpp	Wed Feb 07 14:00:39 2007 -0500
@@ -30,8 +30,8 @@
 		Cycle& bdry = j->cycle();
 		Dout(dc::finish, bdry);
 		
-		counters.inc("Boundaries", j->dimension());
-		counters.inc("SimplexCount");
+		CountNum("Boundaries", j->dimension());
+		Count("SimplexCount");
 
 		while(!bdry.empty())
 		{
@@ -46,7 +46,7 @@
 				Dout(dc::filtration, "Pairing " << *i << " and " << *j << " with cycle " << j->cycle());
 				i->set_pair(j);
 				j->set_pair(i);
-				counters.inc("DepositedCycleLength", j->cycle().size());
+				CountNum("DepositedCycleLength", j->cycle().size());
 				break;
 			}
 
@@ -167,7 +167,7 @@
 transpose_simplices(Index i, bool maintain_lazy)
 {
 	AssertMsg(is_paired(), "Pairing must be computed before transpositions");
-	counters.inc("SimplexTransposition");
+	Count("SimplexTransposition");
 	
 	Index i_prev = i++;
 
@@ -175,7 +175,7 @@
 	{
 		swap(i_prev, i);
 		Dout(dc::transpositions, "Different dimension");
-		counters.inc("Case DiffDim");
+		Count("Case DiffDim");
 		return false;
 	}
 	
@@ -201,7 +201,7 @@
 			swap(i_prev, i);
 			Dout(dc::transpositions, "Case 1.2 --- unpaired");
 			Dout(dc::transpositions, *i_prev);
-			counters.inc("Case 1.2");
+			Count("Case 1.2");
 			return false;
 		} else if (k == i_prev)
 		{
@@ -211,7 +211,7 @@
 				swap(i_prev, i);
 				Dout(dc::transpositions, "Case 1.2 --- unpaired");
 				Dout(dc::transpositions, *i_prev);
-				counters.inc("Case 1.2");
+				Count("Case 1.2");
 				return false;
 			} else
 			{
@@ -220,7 +220,7 @@
 				pairing_switch(i_prev, i);
 				Dout(dc::transpositions, "Case 1.1.2 --- unpaired");
 				Dout(dc::transpositions, *i_prev);
-				counters.inc("Case 1.1.2");
+				Count("Case 1.1.2");
 				return true;
 			}
 		}
@@ -240,7 +240,7 @@
 			}
 			swap(i_prev, i);
 			Dout(dc::transpositions, "Case 1.2");
-			counters.inc("Case 1.2");
+			Count("Case 1.2");
 			return false;
 		} else
 		{
@@ -252,7 +252,7 @@
 				l->cycle().add(k->cycle(), Filtration::get_consistency_cmp());		// Add column k to l
 				k->trail().add(l->trail(), Filtration::get_consistency_cmp());		// Add row l to k
 				Dout(dc::transpositions, "Case 1.1.1");
-				counters.inc("Case 1.1.1");
+				Count("Case 1.1.1");
 				return false;
 			} else
 			{
@@ -262,7 +262,7 @@
 				l->trail().add(k->trail(), Filtration::get_consistency_cmp());		// Add row k to l
 				pairing_switch(i_prev, i);
 				Dout(dc::transpositions, "Case 1.1.2");
-				counters.inc("Case 1.1.2");
+				Count("Case 1.1.2");
 				return true;
 			}
 		}
@@ -274,7 +274,7 @@
 			// Case 2.2
 			swap(i_prev, i);
 			Dout(dc::transpositions, "Case 2.2");
-			counters.inc("Case 2.2");
+			Count("Case 2.2");
 			return false;
 		} else
 		{
@@ -291,13 +291,13 @@
 				i->trail().add(i_prev->trail(), Filtration::get_consistency_cmp());			// Add row i to i_prev
 				pairing_switch(i_prev, i);
 				Dout(dc::transpositions, "Case 2.1.2");
-				counters.inc("Case 2.1.2");
+				Count("Case 2.1.2");
 				return true;
 			} 
 			
 			// Case 2.1.1
 			Dout(dc::transpositions, "Case 2.1.1");
-			counters.inc("Case 2.1.1");
+			Count("Case 2.1.1");
 			return false;
 		}
 	} else if (!si && sii)
@@ -308,7 +308,7 @@
 			// Case 3.2
 			swap(i_prev, i);
 			Dout(dc::transpositions, "Case 3.2");
-			counters.inc("Case 3.2");
+			Count("Case 3.2");
 			return false;
 		} else
 		{
@@ -320,7 +320,7 @@
 			i->trail().add(i_prev->trail(), Filtration::get_consistency_cmp());			// Add row i to i_prev
 			pairing_switch(i_prev, i);
 			Dout(dc::transpositions, "Case 3.1");
-			counters.inc("Case 3.1");
+			Count("Case 3.1");
 			return true;
 		}
 	} else if (si && !sii)
@@ -334,7 +334,7 @@
 		}
 		swap(i_prev, i);
 		Dout(dc::transpositions, "Case 4");
-		counters.inc("Case 4");
+		Count("Case 4");
 		return false;
 	}
 	
--- a/include/lowerstarfiltration.hpp	Wed Jan 31 16:53:35 2007 -0500
+++ b/include/lowerstarfiltration.hpp	Wed Feb 07 14:00:39 2007 -0500
@@ -59,8 +59,9 @@
 LowerStarFiltration<VI,Smplx,FltrSmplx,Vnrd>::
 transpose_vertices(const VertexOrderIndex& order)
 {
-	counters.inc("VertexTransposition");
+	Count("VertexTransposition");
 
+#if COUNTERS
 	if ((counters.lookup("VertexTransposition") % 1000000) == 0)
 	{
 		Dout(dc::lsfiltration, "Vertex transpositions:  " << counters.lookup("VertexTransposition"));
@@ -70,6 +71,7 @@
 		Dout(dc::lsfiltration, "Pairing Changed:        " << counters.lookup("ChangedPairing"));
 		Dout(dc::lsfiltration, "------------------------");
 	}
+#endif // COUNTERS
 	
 	Dout(dc::lsfiltration, "Transposing vertices (" << order->vertex_index << ", " 
 													<< boost::next(order)->vertex_index << ")");
@@ -101,7 +103,7 @@
 		Dout(dc::lsfiltration, "  Considering " << *j);
 		if (nbghrs && j->contains(v_i))			// short circuit
 		{
-			counters.inc("ChangedAttachment");
+			Count("ChangedAttachment");
 			Dout(dc::lsfiltration, "  Attachment changed for " << *j);
 			j->set_attachment(v_i);
 			++j;