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 +4 -4
- data/CHANGELOG +12 -0
- data/lib/Namo/Enumerable.rb +6 -4
- data/lib/Namo/VERSION.rb +1 -1
- data/test/namo_test.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e6f9ea9ed29bd86c309865e0c49d03122b7fa50460e34fd7a42a9a273bb220c0
|
|
4
|
+
data.tar.gz: 99d5e8191c3458b498c6fe297c2af8b94d8bb73aced942d9f3da67af94ace454
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
data/lib/Namo/Enumerable.rb
CHANGED
|
@@ -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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
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
|