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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/lib/philiprehberger/counter/version.rb +1 -1
- data/lib/philiprehberger/counter.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9235199a1afba364ec57b7c6107386e10c538941a6469a2555e80f452f1bc14a
|
|
4
|
+
data.tar.gz: 3de6990335685ca1d28a98e4ea796c5488ba9d52fafc04b5a4258255be8f504d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 |
|
|
@@ -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
|
+
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-
|
|
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
|