From fdda21b114e2c6615a870880d5d0d1184cd3d6c0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 24 Jun 2013 17:02:28 -0400 Subject: [PATCH] use explicit data types --- DataStructures/DynamicGraph.h | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/DataStructures/DynamicGraph.h b/DataStructures/DynamicGraph.h index abc238e27..537ec3d65 100644 --- a/DataStructures/DynamicGraph.h +++ b/DataStructures/DynamicGraph.h @@ -21,18 +21,20 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef DYNAMICGRAPH_H_INCLUDED #define DYNAMICGRAPH_H_INCLUDED -#include +#include "../DataStructures/DeallocatingVector.h" + +#include + #include #include - -#include "../DataStructures/DeallocatingVector.h" +#include template< typename EdgeDataT> class DynamicGraph { public: typedef EdgeDataT EdgeData; - typedef unsigned NodeIterator; - typedef unsigned EdgeIterator; + typedef uint32_t NodeIterator; + typedef uint32_t EdgeIterator; class InputEdge { public: @@ -47,15 +49,16 @@ class DynamicGraph { }; //Constructs an empty graph with a given number of nodes. - DynamicGraph( int nodes ) : m_numNodes(nodes), m_numEdges(0) { + DynamicGraph( int32_t nodes ) : m_numNodes(nodes), m_numEdges(0) { m_nodes.reserve( m_numNodes ); m_nodes.resize( m_numNodes ); m_edges.reserve( m_numNodes * 1.1 ); m_edges.resize( m_numNodes ); } + template - DynamicGraph( const int nodes, const ContainerT &graph ) { + DynamicGraph( const int32_t nodes, const ContainerT &graph ) { m_numNodes = nodes; m_numEdges = ( EdgeIterator ) graph.size(); m_nodes.reserve( m_numNodes +1); @@ -90,15 +93,15 @@ class DynamicGraph { ~DynamicGraph(){ } - unsigned GetNumberOfNodes() const { + uint32_t GetNumberOfNodes() const { return m_numNodes; } - unsigned GetNumberOfEdges() const { + uint32_t GetNumberOfEdges() const { return m_numEdges; } - unsigned GetOutDegree( const NodeIterator n ) const { + uint32_t GetOutDegree( const NodeIterator n ) const { return m_nodes[n].edges; } @@ -133,7 +136,7 @@ class DynamicGraph { m_edges[node.firstEdge] = m_edges[node.firstEdge + node.edges]; } else { EdgeIterator newFirstEdge = ( EdgeIterator ) m_edges.size(); - unsigned newSize = node.edges * 1.1 + 2; + uint32_t newSize = node.edges * 1.1 + 2; EdgeIterator requiredCapacity = newSize + m_edges.size(); EdgeIterator oldCapacity = m_edges.capacity(); if ( requiredCapacity >= oldCapacity ) { @@ -162,15 +165,15 @@ class DynamicGraph { Node &node = m_nodes[source]; --m_numEdges; --node.edges; - const unsigned last = node.firstEdge + node.edges; + const uint32_t last = node.firstEdge + node.edges; //swap with last edge m_edges[e] = m_edges[last]; makeDummy( last ); } //removes all edges (source,target) - int DeleteEdgesTo( const NodeIterator source, const NodeIterator target ) { - int deleted = 0; + int32_t DeleteEdgesTo( const NodeIterator source, const NodeIterator target ) { + int32_t deleted = 0; for ( EdgeIterator i = BeginEdges( source ), iend = EndEdges( source ); i < iend - deleted; ++i ) { if ( m_edges[i].target == target ) { do { @@ -212,7 +215,7 @@ class DynamicGraph { //index of the first edge EdgeIterator firstEdge; //amount of edges - unsigned edges; + uint32_t edges; }; struct Edge {