Skip to content

Commit c092bcf

Browse files
committed
Changed the edge weight value for graphs from Int32 to Int64.
1 parent 9fe2336 commit c092bcf

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

DataStructures/Graphs/DirectedWeightedDenseGraph.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public class DirectedWeightedDenseGraph<T> : DirectedDenseGraph<T>, IWeightedGra
2121
/// <summary>
2222
/// INSTANCE VARIABLES
2323
/// </summary>
24-
private const int EMPTY_EDGE_SLOT = 0;
24+
private const long EMPTY_EDGE_SLOT = 0;
2525
private const object EMPTY_VERTEX_SLOT = (object)null;
2626

2727
// Store edges and their weights as integers.
2828
// Any edge with a value of zero means it doesn't exist. Otherwise, it exist with a specific weight value.
2929
// Default value for positive edges is 1.
30-
protected new int[,] _adjacencyMatrix { get; set; }
30+
protected new long[,] _adjacencyMatrix { get; set; }
3131

3232

3333
/// <summary>
@@ -40,7 +40,7 @@ public DirectedWeightedDenseGraph(uint capacity = 10)
4040
_verticesCapacity = (int)capacity;
4141

4242
_vertices = new ArrayList<object>(_verticesCapacity);
43-
_adjacencyMatrix = new int[_verticesCapacity, _verticesCapacity];
43+
_adjacencyMatrix = new long[_verticesCapacity, _verticesCapacity];
4444
_adjacencyMatrix.Populate(rows: _verticesCapacity, columns: _verticesCapacity, defaultValue: EMPTY_EDGE_SLOT);
4545
}
4646

@@ -56,7 +56,7 @@ protected override bool _doesEdgeExist(int source, int destination)
5656
/// <summary>
5757
/// Helper function. Gets the weight of a directed edge.
5858
/// </summary>
59-
private int _getEdgeWeight(int source, int destination)
59+
private long _getEdgeWeight(int source, int destination)
6060
{
6161
return _adjacencyMatrix[source, destination];
6262
}
@@ -95,7 +95,7 @@ public virtual IEnumerable<WeightedEdge<T>> Edges
9595
/// <summary>
9696
/// Connects two vertices together with a weight, in the direction: first->second.
9797
/// </summary>
98-
public virtual bool AddEdge(T source, T destination, int weight)
98+
public virtual bool AddEdge(T source, T destination, long weight)
9999
{
100100
// Return if the weight is equals to the empty edge value
101101
if (weight == EMPTY_EDGE_SLOT)
@@ -145,7 +145,7 @@ public override bool RemoveEdge(T source, T destination)
145145
/// <summary>
146146
/// Updates the edge weight from source to destination.
147147
/// </summary>
148-
public virtual bool UpdateEdgeWeight(T source, T destination, int weight)
148+
public virtual bool UpdateEdgeWeight(T source, T destination, long weight)
149149
{
150150
// Return if the weight is equals to the empty edge value
151151
if (weight == EMPTY_EDGE_SLOT)
@@ -235,20 +235,20 @@ public virtual WeightedEdge<T> GetEdge(T source, T destination)
235235
/// <summary>
236236
/// Returns the edge weight from source to destination.
237237
/// </summary>
238-
public virtual int GetEdgeWeight(T source, T destination)
238+
public virtual long GetEdgeWeight(T source, T destination)
239239
{
240240
return GetEdge(source, destination).Weight;
241241
}
242242

243243
/// <summary>
244244
/// Returns the neighbours of a vertex as a dictionary of nodes-to-weights.
245245
/// </summary>
246-
public virtual Dictionary<T, int> NeighboursMap(T vertex)
246+
public virtual Dictionary<T, long> NeighboursMap(T vertex)
247247
{
248248
if (!HasVertex(vertex))
249249
return null;
250250

251-
var neighbors = new Dictionary<T, int>();
251+
var neighbors = new Dictionary<T, long>();
252252
int source = _vertices.IndexOf(vertex);
253253

254254
// Check existence of vertex
@@ -328,7 +328,7 @@ public override void Clear()
328328
_edgesCount = 0;
329329
_verticesCount = 0;
330330
_vertices = new ArrayList<object>(_verticesCapacity);
331-
_adjacencyMatrix = new int[_verticesCapacity, _verticesCapacity];
331+
_adjacencyMatrix = new long[_verticesCapacity, _verticesCapacity];
332332
_adjacencyMatrix.Populate(rows: _verticesCapacity, columns: _verticesCapacity, defaultValue: EMPTY_EDGE_SLOT);
333333
}
334334

DataStructures/Graphs/DirectedWeightedSparseGraph.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class DirectedWeightedSparseGraph<T> : IGraph<T>, IWeightedGraph<T> where
2222
/// <summary>
2323
/// INSTANCE VARIABLES
2424
/// </summary>
25-
private const int EMPTY_EDGE_VALUE = 0;
25+
private const long EMPTY_EDGE_VALUE = 0;
2626
protected virtual int _edgesCount { get; set; }
2727
protected virtual T _firstInsertedNode { get; set; }
2828
protected virtual Dictionary<T, DLinkedList<WeightedEdge<T>>> _adjacencyList { get; set; }
@@ -72,7 +72,7 @@ protected virtual bool _doesEdgeExist(T source, T destination)
7272
/// Helper function. Gets the weight of a directed edge.
7373
/// Presumes edge does already exist.
7474
/// </summary>
75-
private int _getEdgeWeight(T source, T destination)
75+
private long _getEdgeWeight(T source, T destination)
7676
{
7777
return _tryGetEdge(source, destination).Weight;
7878
}
@@ -147,7 +147,7 @@ public bool AddEdge(T source, T destination)
147147
/// <summary>
148148
/// Connects two vertices together with a weight, in the direction: first->second.
149149
/// </summary>
150-
public bool AddEdge(T source, T destination, int weight)
150+
public bool AddEdge(T source, T destination, long weight)
151151
{
152152
// Check existence of nodes, the validity of the weight value, and the non-existence of edge
153153
if (weight == EMPTY_EDGE_VALUE)
@@ -192,7 +192,7 @@ public virtual bool RemoveEdge(T source, T destination)
192192
return true;
193193
}
194194

195-
public bool UpdateEdgeWeight(T source, T destination, int weight)
195+
public bool UpdateEdgeWeight(T source, T destination, long weight)
196196
{
197197
// Check existence of vertices and validity of the weight value
198198
if (weight == EMPTY_EDGE_VALUE)
@@ -238,7 +238,7 @@ public virtual WeightedEdge<T> GetEdge(T source, T destination)
238238
/// <summary>
239239
/// Returns the edge weight from source to destination.
240240
/// </summary>
241-
public virtual int GetEdgeWeight(T source, T destination)
241+
public virtual long GetEdgeWeight(T source, T destination)
242242
{
243243
return GetEdge(source, destination).Weight;
244244
}
@@ -339,13 +339,13 @@ public virtual DLinkedList<T> Neighbours(T vertex)
339339
/// <summary>
340340
/// Returns the neighbours of a vertex as a dictionary of nodes-to-weights.
341341
/// </summary>
342-
public Dictionary<T, int> NeighboursMap(T vertex)
342+
public Dictionary<T, long> NeighboursMap(T vertex)
343343
{
344344
if (!HasVertex(vertex))
345345
return null;
346346

347347
var neighbors = _adjacencyList[vertex];
348-
var map = new Dictionary<T, int>(neighbors.Count);
348+
var map = new Dictionary<T, long>(neighbors.Count);
349349

350350
foreach (var adjacent in neighbors)
351351
map.Add(adjacent.Destination, adjacent.Weight);

DataStructures/Graphs/IWeightedGraph.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public interface IWeightedGraph<T> where T : IComparable<T>
1515
/// <summary>
1616
/// Connects two vertices together with a weight, in the direction: first->second.
1717
/// </summary>
18-
bool AddEdge(T source, T destination, int weight);
18+
bool AddEdge(T source, T destination, long weight);
1919

2020
/// <summary>
2121
/// Updates the edge weight from source to destination.
2222
/// </summary>
23-
bool UpdateEdgeWeight(T source, T destination, int weight);
23+
bool UpdateEdgeWeight(T source, T destination, long weight);
2424

2525
/// <summary>
2626
/// Get edge object from source to destination.
@@ -30,7 +30,7 @@ public interface IWeightedGraph<T> where T : IComparable<T>
3030
/// <summary>
3131
/// Returns the edge weight from source to destination.
3232
/// </summary>
33-
int GetEdgeWeight(T source, T destination);
33+
long GetEdgeWeight(T source, T destination);
3434

3535
/// <summary>
3636
/// Get all outgoing weighted edges from vertex
@@ -40,7 +40,7 @@ public interface IWeightedGraph<T> where T : IComparable<T>
4040
/// <summary>
4141
/// Returns the neighbours of a vertex as a dictionary of nodes-to-weights.
4242
/// </summary>
43-
System.Collections.Generic.Dictionary<T, int> NeighboursMap(T vertex);
43+
System.Collections.Generic.Dictionary<T, long> NeighboursMap(T vertex);
4444
}
4545
}
4646

DataStructures/Graphs/WeightedEdge.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class WeightedEdge<T> : IComparable<WeightedEdge<T>> where T : IComparabl
1111
{
1212
public T Source { get; set; }
1313
public T Destination { get; set; }
14-
public Int32 Weight { get; set; }
14+
public Int64 Weight { get; set; }
1515

16-
public WeightedEdge(T src, T dst, Int32 weight)
16+
public WeightedEdge(T src, T dst, Int64 weight)
1717
{
1818
Source = src;
1919
Destination = dst;

0 commit comments

Comments
 (0)