philiprehberger-counter 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: ec5f8cbe5ef7c7233a73a37cbb103098418654492af1cbfbad0743e8a64045c2
4
- data.tar.gz: 10fd4fabf5dc064c088e0c1f40a576cad7e5c0901aad13ed6cbfd9b21427be68
3
+ metadata.gz: 9235199a1afba364ec57b7c6107386e10c538941a6469a2555e80f452f1bc14a
4
+ data.tar.gz: 3de6990335685ca1d28a98e4ea796c5488ba9d52fafc04b5a4258255be8f504d
5
5
  SHA512:
6
- metadata.gz: 6076470a39f47c2ae0a024ee5479ec66029df9cd2d3b90da0533ee239afbfc02addc90b8ddaf2d7dce6aa5efaa995ba13b874c639c96c628417a2eb35a83b1ea
7
- data.tar.gz: 49f7f17e8541bafadc97442d14410d8c163aea4e64e4c5251b1a65edf8460c57bf2a8b747e1bff01eb5d5d170d8705713167665fdb27a6ebb2952388d2a08487
6
+ metadata.gz: de7b409893d4e6f89a94f8f2afde8629f19a631c6606be3a8075ba0151ae45f3ba65c0803de527d73eb686bf3de153b1479da5419e51aac6eaeda3fd8ad7b163
7
+ data.tar.gz: 99f089682769fff8d738f3a89df4de0133fbf09dbd84e86c0ca1af072f0418880f7468ca5dec2a706ab0ccff87ebd920103fe83f6e3821982688cc659e41d8c1
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-04-24
11
+
12
+ ### Added
13
+ - `#mode` method returning the single most-common key (shorthand for `max_count.first`); returns `nil` for empty counters
14
+
10
15
  ## [0.4.0] - 2026-04-15
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -95,6 +95,7 @@ counter.delete('z') # => nil (key not present)
95
95
  counter = Philiprehberger::Counter.new(%w[a b a c a b])
96
96
  counter.max_count # => ["a", 3]
97
97
  counter.min_count # => ["c", 1]
98
+ counter.mode # => "a"
98
99
  ```
99
100
 
100
101
  ### JSON Serialization
@@ -159,6 +160,7 @@ skewed.entropy # => ~0.7219 (less than uniform upper bound)
159
160
  | `#delete(key)` | Remove a key entirely, returns count or nil |
160
161
  | `#max_count` | Key-count pair with highest count |
161
162
  | `#min_count` | Key-count pair with lowest count |
163
+ | `#mode` | Most-common key (just the key, not the pair) |
162
164
  | `#to_json` | Serialize counter to JSON string |
163
165
  | `.from_json(str)` | Deserialize counter from JSON string |
164
166
  | `#sample(n)` | Weighted random sample based on counts |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  class Counter
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -184,6 +184,17 @@ module Philiprehberger
184
184
  @counts.max_by { |_, count| count }
185
185
  end
186
186
 
187
+ # Return the single most-common key (the mode of the count distribution)
188
+ #
189
+ # When multiple keys tie for the highest count, returns the first one
190
+ # encountered via `Hash#max_by` (i.e., insertion order among ties).
191
+ #
192
+ # @return [Object, nil] the most-common key, or nil if empty
193
+ def mode
194
+ pair = max_count
195
+ pair && pair[0]
196
+ end
197
+
187
198
  # Return the [key, count] pair with the lowest count
188
199
  #
189
200
  # @return [Array, nil] [key, count] or nil if empty
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-counter
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-15 00:00:00.000000000 Z
11
+ date: 2026-04-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Count element frequencies from any enumerable with most-common and least-common
14
14
  queries, merge and subtract operations, percentage calculations, and Enumerable