namo 0.29.0 → 0.30.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: 5e56f3159063720b0e933e9c346ddad824831a51dac7a576da6d0cf841fd28ea
4
- data.tar.gz: 8aee98bb89f8c7ab978c0ce459cc90c8259123123c13f5158a3e16dbb93922c7
3
+ metadata.gz: e6f9ea9ed29bd86c309865e0c49d03122b7fa50460e34fd7a42a9a273bb220c0
4
+ data.tar.gz: 99d5e8191c3458b498c6fe297c2af8b94d8bb73aced942d9f3da67af94ace454
5
5
  SHA512:
6
- metadata.gz: 16e3d16921ee88ae7d5d76c79227efb035128ac46f17d93fa61c7445434bb1c475c597ff7e2478fe19bbaf8f53b73ed366fee5ed1e514ad99a423a030db0d46c
7
- data.tar.gz: 7e0045e6e6a842be576e171c9c31bde901f7ade581e5dce694e853a868f832c358e5eb7329ce9fc14efdc13a20663f4877135895f99328d646bb8717d177a2af
6
+ metadata.gz: 9e4aca2b13be76dc10a2fcf3eb7122045e600b1ed2410c2f6e82554c7dfc679249bf714fc52939fd4ee058fa6925b1958935bd91281dbf67f48634aec4cd4ea9
7
+ data.tar.gz: d3432cb0f092521adb1e2f60dccbc5b37aff2e4f91511189300b0693d374124e76cf1fde57d64709606ea504aae5db85d9c47e7aba99efcfdfa68b6fcbc38eef
data/CHANGELOG CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## 20260715
4
4
 
5
+ 0.30.0: Assemble Collection objects in a single pass when doing Namo::Enumerable#group_by.
6
+
7
+ Appending one member per group re-materialised Collection#<<'s @data = detail.data over all members-so-far g times; group_by now appends all the members in one << operation and materialises once, causing it be performed in O(rows) instead of O(rows·groups).
8
+
9
+ 1. ~ Namo::Enumerable#group_by: map the groups to members, then append them all in one collection << members, rather than << per group — each of which rebuilt @data over every member-so-far.
10
+ 2. ~ test/namo_test.rb: + a single-pass assembly pin under #group_by — the assembly materialises the detail once whatever the number of groups (not once per group).
11
+ 3. ~ ROADMAP.md: + the 0.30.0 entry; current-state bumped to 0.30.0.
12
+ 4. ~ docs/: regenerate the print-ready PDFs.
13
+ 5. ~ Namo::VERSION: /0.29.0/0.30.0/
14
+
15
+ ## 20260715
16
+
5
17
  0.29.0: Per access indexed materialisation.
6
18
 
7
19
  Materialise each column once per top-level access, collapsing an O(n²) parent-scanning formula to O(n), with no value retained across accesses.
@@ -72,10 +72,12 @@ class Namo
72
72
  def group_by(dimension)
73
73
  collection = Collection.new
74
74
  source = derived_dimensions.include?(dimension) ? self[*data_dimensions, dimension] : self
75
- source.data.group_by{|row_data| row_data[dimension]}.each do |value, rows|
76
- collection << self.class.new(rows, formulae: source.formulae.dup, name: value)
77
- end
78
- collection
75
+ members = (
76
+ source.data.group_by{|row_data| row_data[dimension]}.map do |value, rows|
77
+ self.class.new(rows, formulae: source.formulae.dup, name: value)
78
+ end
79
+ )
80
+ collection << members
79
81
  end
80
82
  end
81
83
  end
data/lib/Namo/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Namo::VERSION
3
3
 
4
4
  class Namo
5
- VERSION = '0.29.0'
5
+ VERSION = '0.30.0'
6
6
  end
data/test/namo_test.rb CHANGED
@@ -3198,5 +3198,27 @@ describe Namo do
3198
3198
  _(collection.detail.values(:close)).must_equal [42.5, 43.0, 118.3, 100.0]
3199
3199
  end
3200
3200
  end
3201
+
3202
+ context "single-pass assembly" do
3203
+ # Collection#<< rebuilds @data = detail.data over all members-so-far on every
3204
+ # append, so appending one member per group re-materialised the data g times
3205
+ # (O(rows·groups)). group_by now hands all members to a single <<: one
3206
+ # materialisation whatever the number of groups.
3207
+ def detail_calls_assembling(namo, dimension)
3208
+ calls = 0
3209
+ tracer = TracePoint.new(:call) do |tp|
3210
+ calls += 1 if tp.method_id == :detail && tp.defined_class == Namo::Collection
3211
+ end
3212
+ tracer.enable{namo.group_by(dimension)}
3213
+ calls
3214
+ end
3215
+
3216
+ it "materialises the assembled data once, whatever the number of groups" do
3217
+ few = Namo.new((1..3).map{|i| {symbol: "S#{i}", close: i.to_f}})
3218
+ many = Namo.new((1..30).map{|i| {symbol: "S#{i}", close: i.to_f}})
3219
+ _(detail_calls_assembling(few, :symbol)).must_equal 1
3220
+ _(detail_calls_assembling(many, :symbol)).must_equal 1
3221
+ end
3222
+ end
3201
3223
  end
3202
3224
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran