[Rsiena-commits] r233 - pkg/RSienaTest/src/network

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 26 06:32:49 CEST 2013


Author: ortmann
Date: 2013-07-26 06:32:48 +0200 (Fri, 26 Jul 2013)
New Revision: 233

Added:
   pkg/RSienaTest/src/network/IncidentTieIterator.cpp
   pkg/RSienaTest/src/network/IncidentTieIterator.h
Removed:
   pkg/RSienaTest/src/network/IncidentTieIterator.cpp
   pkg/RSienaTest/src/network/IncidentTieIterator.h
Log:
changes:
	IncidentTieIterator inherits from ITieIterator
	moved constructor body to initializiation list
	removed bool indicating the validity of the Iterator
	inlined several functions

Deleted: pkg/RSienaTest/src/network/IncidentTieIterator.cpp
===================================================================
--- pkg/RSienaTest/src/network/IncidentTieIterator.cpp	2013-07-26 04:26:06 UTC (rev 232)
+++ pkg/RSienaTest/src/network/IncidentTieIterator.cpp	2013-07-26 04:32:48 UTC (rev 233)
@@ -1,103 +0,0 @@
-/******************************************************************************
- * SIENA: Simulation Investigation for Empirical Network Analysis
- *
- * Web: http://www.stats.ox.ac.uk/~snijders/siena/
- *
- * File: IncidentTieIterator.cpp
- *
- * Description: This module defines the class IncidentTieIterator for
- * convenient iteration over incoming or outgoing ties of an actor.
- *****************************************************************************/
-
-#include "IncidentTieIterator.h"
-#include "../utils/Utils.h"
-
-namespace siena
-{
-
-/**
- * Creates a dummy iterator with no underlying collection of ties.
- */
-IncidentTieIterator::IncidentTieIterator()
-{
-	// The internal iterators lcurrent and lend are not initialized,
-	// and consequently this iterator is not valid.
-
-	this->linitialized = false;
-}
-
-
-//
-// Creates an iterator over a collection of ties represented by the
-// given map. The values of the pairs in the map represent the values
-// of ties, and the keys represent the corresponding neighbors.
-//
-IncidentTieIterator::IncidentTieIterator(std::map<int, int> & ties)
-{
-	this->lcurrent = ties.begin();
-	this->lend = ties.end();
-	this->linitialized = true;
-}
-
-
-//
-// Creates an iterator over a collection of ties represented by the
-// given map. The values of the pairs in the map represent the values
-// of ties, and the keys represent the corresponding neighbors. Only
-// neighbors that are greater or equal with the given bound are returned.
-//
-IncidentTieIterator::IncidentTieIterator(std::map<int, int> & ties,
-	int lowerBound)
-{
-	this->lcurrent = ties.lower_bound(lowerBound);
-	this->lend = ties.end();
-	this->linitialized = true;
-}
-
-
-/**
- * Returns the neighbor incident to the current tie.
- */
-int IncidentTieIterator::actor() const
-{
-	if (!this->valid())
-	{
-		throw InvalidIteratorException();
-	}
-
-	return this->lcurrent->first;
-}
-
-
-/**
- * Returns the value of the current tie.
- */
-int IncidentTieIterator::value() const
-{
-	if (!this->valid())
-	{
-		throw InvalidIteratorException();
-	}
-
-	return this->lcurrent->second;
-}
-
-
-/**
- * Indicates if the iterator still points to a valid tie.
- */
-bool IncidentTieIterator::valid() const
-{
-	return this->linitialized && this->lcurrent != this->lend;
-}
-
-
-/**
- * Moves the iterator to the next tie.
- */
-void IncidentTieIterator::next()
-{
-	this->lcurrent++;
-}
-
-}

Copied: pkg/RSienaTest/src/network/IncidentTieIterator.cpp (from rev 231, pkg/RSienaTest/src/network/IncidentTieIterator.cpp)
===================================================================
--- pkg/RSienaTest/src/network/IncidentTieIterator.cpp	                        (rev 0)
+++ pkg/RSienaTest/src/network/IncidentTieIterator.cpp	2013-07-26 04:32:48 UTC (rev 233)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: IncidentTieIterator.cpp
+ *
+ * Description: This module defines the class IncidentTieIterator for
+ * convenient iteration over incoming or outgoing ties of an actor.
+ *****************************************************************************/
+
+#include "IncidentTieIterator.h"
+
+namespace siena {
+
+/**
+ * Creates a dummy iterator with no underlying collection of ties.
+ */
+IncidentTieIterator::IncidentTieIterator() :
+		ITieIterator(), //
+		lcurrent(0), //
+		lend(0) {
+}
+
+//
+// Creates an iterator over a collection of ties represented by the
+// given map. The values of the pairs in the map represent the values
+// of ties, and the keys represent the corresponding neighbors.
+//
+IncidentTieIterator::IncidentTieIterator(std::map<int, int> & ties) :
+		ITieIterator(), //
+		lcurrent(ties.begin()), //
+		lend(ties.end()) {
+}
+
+//
+// Creates an iterator over a collection of ties represented by the
+// given map. The values of the pairs in the map represent the values
+// of ties, and the keys represent the corresponding neighbors. Only
+// neighbors that are greater or equal with the given bound are returned.
+//
+IncidentTieIterator::IncidentTieIterator(std::map<int, int> & ties,
+		int lowerBound) :
+		ITieIterator(), //
+		lcurrent(ties.lower_bound(lowerBound)), //
+		lend(ties.end()) {
+}
+
+}

Deleted: pkg/RSienaTest/src/network/IncidentTieIterator.h
===================================================================
--- pkg/RSienaTest/src/network/IncidentTieIterator.h	2013-07-26 04:26:06 UTC (rev 232)
+++ pkg/RSienaTest/src/network/IncidentTieIterator.h	2013-07-26 04:32:48 UTC (rev 233)
@@ -1,56 +0,0 @@
-/******************************************************************************
- * SIENA: Simulation Investigation for Empirical Network Analysis
- *
- * Web: http://www.stats.ox.ac.uk/~snijders/siena/
- *
- * File: IncidentTieIterator.h
- *
- * Description: This module defines the class IncidentTieIterator for
- * convenient iteration over incoming or outgoing ties of an actor.
- *****************************************************************************/
-
-#ifndef INCIDENTTIEITERATOR_H_
-#define INCIDENTTIEITERATOR_H_
-
-#include <map>
-
-namespace siena
-{
-
-/**
- * This class defines an iterator over incoming or outgoing ties of a specific
- * actor <i>i</i>. The ties are sorted in an increasing order of the neighbors
- * of <i>i</i>.
- */
-class IncidentTieIterator
-{
-	// The class Network needs access to the private constructor.
-	friend class Network;
-
-public:
-	IncidentTieIterator();
-
-	int actor() const;
-	int value() const;
-	bool valid() const;
-	void next();
-
-private:
-	IncidentTieIterator(std::map<int, int> & ties);
-	IncidentTieIterator(std::map<int, int> & ties, int lowerBound);
-
-	// Points to the current element in the underlying map
-	std::map<int, int>::const_iterator lcurrent;
-
-	// Points to the end of the underlying map
-	std::map<int, int>::const_iterator lend;
-
-	// Indicates if the internal iterators have been initialized to
-	// point to elements of some underlying map.
-
-	bool linitialized;
-};
-
-}
-
-#endif /*INCIDENTTIEITERATOR_H_*/

Copied: pkg/RSienaTest/src/network/IncidentTieIterator.h (from rev 231, pkg/RSienaTest/src/network/IncidentTieIterator.h)
===================================================================
--- pkg/RSienaTest/src/network/IncidentTieIterator.h	                        (rev 0)
+++ pkg/RSienaTest/src/network/IncidentTieIterator.h	2013-07-26 04:32:48 UTC (rev 233)
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * SIENA: Simulation Investigation for Empirical Network Analysis
+ *
+ * Web: http://www.stats.ox.ac.uk/~snijders/siena/
+ *
+ * File: IncidentTieIterator.h
+ *
+ * Description: This module defines the class IncidentTieIterator for
+ * convenient iteration over incoming or outgoing ties of an actor.
+ *****************************************************************************/
+
+#ifndef INCIDENTTIEITERATOR_H_
+#define INCIDENTTIEITERATOR_H_
+
+#include <map>
+
+#include "iterators/ITieIterator.h"
+
+namespace siena {
+
+/**
+ * This class defines an iterator over incoming or outgoing ties of a specific
+ * actor <i>i</i>. The ties are sorted in an increasing order of the neighbors
+ * of <i>i</i>.
+ */
+class IncidentTieIterator: public ITieIterator {
+	// The class Network needs access to the private constructor.
+	friend class Network;
+
+public:
+	IncidentTieIterator();
+
+	/**
+	 * Returns the neighbor incident to the current tie.
+	 */
+	inline int actor() const {
+		if (valid()) {
+			return lcurrent->first;
+		}
+		throw InvalidIteratorException();
+	}
+
+	/**
+	 * Returns the value of the current tie.
+	 */
+	inline int value() const {
+		if (valid()) {
+			return lcurrent->second;
+		}
+		throw InvalidIteratorException();
+	}
+
+	/**
+	 * Indicates if the iterator still points to a valid tie.
+	 */
+	inline bool valid() const {
+		return lcurrent != lend;
+	}
+
+	/**
+	 * Moves the iterator to the next tie.
+	 */
+	inline void next() {
+		++lcurrent;
+	}
+
+private:
+	IncidentTieIterator(std::map<int, int> & ties);
+	IncidentTieIterator(std::map<int, int> & ties, int lowerBound);
+
+	// Points to the current element in the underlying map
+	std::map<int, int>::const_iterator lcurrent;
+
+	// Points to the end of the underlying map
+	std::map<int, int>::const_iterator lend;
+};
+
+}
+
+#endif /*INCIDENTTIEITERATOR_H_*/



More information about the Rsiena-commits mailing list