philiprehberger-graph 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73596f486ec100249fa2df0e4a9ef6aa1bdcd5e37e16b9b587dd6802f3fc9584
4
- data.tar.gz: 0ddc969e510fb5543d9b981d53f73c15b53e73066defb0b7226998c79ef7ec15
3
+ metadata.gz: 178b5edb15123981edaaa93532c454677d40753f5ff3729fbe62026c0020f768
4
+ data.tar.gz: 3446356ba683b0077338dfa55dc052e36546c39d9606e67e0e37ad114368cdfd
5
5
  SHA512:
6
- metadata.gz: 4cffa4c6398bfa251b9b8f82704d883d36e4c2dc7f1296369ff073364b8a71d0256a8f75b056d78372a38ca99809e8a09c560d549da4b8b8efa38ccf35130811
7
- data.tar.gz: 80ca432cc5c0b1b35c979ccfebb1e7409d9170687a99ae9f4336e5159ce72a8d063cd5c8f7cc4829a4e22d9bad34c8d329e4fb8e8d3a3a668876994455ac628d
6
+ metadata.gz: f24fbd86ab0237395a61f5b012091817c4b152b24af2797e7264b2e853177fba4502a234863f1c56c83ecd9adb4bd11f5f0af4d804fae3afdf820a574ae09530
7
+ data.tar.gz: 16ecb22d98f3a29f2db9d12ae2f08d7ca4e5b03abd0af0c6a348dc2706a6bd4b0bec4e966a05bf662166c857bd6f73c06842c0cd3610caeafeba8454d9e1bf77
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-04-29
11
+
12
+ ### Added
13
+ - `Graph#total_weight` returning the sum of edge weights across all edges (cheap baseline for MST/flow comparisons)
14
+
10
15
  ## [0.4.0] - 2026-04-17
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -177,6 +177,16 @@ c.edge?(:a, :c) # => true
177
177
  c.edge?(:a, :b) # => false
178
178
  ```
179
179
 
180
+ ### Total Edge Weight
181
+
182
+ ```ruby
183
+ g = Philiprehberger::Graph.new
184
+ g.add_edge(:a, :b, weight: 3)
185
+ g.add_edge(:b, :c, weight: 5)
186
+
187
+ g.total_weight # => 8
188
+ ```
189
+
180
190
  ### Query Methods
181
191
 
182
192
  ```ruby
@@ -269,6 +279,7 @@ g2 = Philiprehberger::Graph::Graph.from_json(g.to_json)
269
279
  | `#edges` | All edges as hashes |
270
280
  | `#node_count` | Number of nodes |
271
281
  | `#edge_count` | Number of edges |
282
+ | `#total_weight` | Sum of edge weights across all edges |
272
283
  | `#empty?` | Whether the graph has no nodes |
273
284
  | `#each_node` | Iterate nodes (yields or returns Enumerator) |
274
285
  | `#each_edge` | Iterate edges (yields or returns Enumerator) |
@@ -177,6 +177,17 @@ module Philiprehberger
177
177
  edges.length
178
178
  end
179
179
 
180
+ # Sum of weights across all edges. Returns 0 for an empty or edgeless graph.
181
+ #
182
+ # For undirected graphs each edge is counted once.
183
+ #
184
+ # @return [Numeric]
185
+ def total_weight
186
+ total = 0
187
+ each_edge { |edge| total += edge[:weight] }
188
+ total
189
+ end
190
+
180
191
  # Whether the graph has no nodes.
181
192
  #
182
193
  # @return [Boolean]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module Graph
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-17 00:00:00.000000000 Z
11
+ date: 2026-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Graph data structure supporting directed and undirected modes with adjacency
14
14
  list storage. Includes BFS, DFS, Dijkstra shortest path, topological sort, cycle