Skip to content

CopyTo and AppendTo - #6

Merged
kazeburo merged 4 commits into
mainfrom
feat/copy-append-to
Sep 20, 2026
Merged

kazeburo merged 4 commits into
mainfrom
feat/copy-append-to

Conversation

@kazeburo

@kazeburo kazeburo commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

PR Type

Enhancement, Tests


Description

  • Adds point counting and transfer operations

  • Validates nil sources and destinations

  • Adds comprehensive operation coverage


Diagram Walkthrough

flowchart LR
  Sampdo["Sampdo instance"] -- "Count points" --> Count["Point count"]
  Sampdo -- "Copy points" --> Slice["Destination slice"]
  Sampdo -- "Append points" --> Destination["Destination Sampdo"]
  Tests["Operation tests"] --> Sampdo
Loading

File Walkthrough

Relevant files
Enhancement
stats.go
Add point counting and transfer methods                                   

stats.go

  • Adds Count for retrieving stored point counts.
  • Adds CopyTo for appending points to slices.
  • Adds AppendTo for transferring points between instances.
  • Returns errors for nil sources or destinations.
+31/-0   
Tests
stats_test.go
Test counting and point transfer operations                           

stats_test.go

  • Tests counts before and after sorting.
  • Verifies copying into empty and existing slices.
  • Covers nil destination error handling.
  • Verifies append operations and sum preservation.
+91/-0   

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Comparison

Base: main
PR: feat/copy-append-to

BenchmarkSampdoAll results
goos: linux
goarch: amd64
pkg: github.com/monitoring-forge/sampdo
cpu: AMD EPYC 9V74 80-Core Processor                
                                        │ base-bench.txt │            pr-bench.txt             │
                                        │     sec/op     │    sec/op     vs base               │
SampdoAll/sampdo/100000/duplicates-4         921.7µ ± 5%   920.3µ ± 12%       ~ (p=0.218 n=10)
SampdoAll/sampdo/100000/random-4             1.852m ± 1%   1.684m ±  1%  -9.06% (p=0.001 n=10)
SampdoAll/sampdo/100000/wide-4               1.891m ± 1%   1.872m ±  8%       ~ (p=0.315 n=10)
SampdoAll/sampdo/100000/sorted-4             191.1µ ± 1%   192.6µ ±  1%       ~ (p=0.052 n=10)
SampdoAll/sampdo/100000/response_time-4      1.624m ± 1%   1.626m ±  1%       ~ (p=0.912 n=10)
geomean                                      1.000m        980.9µ        -1.94%

                                        │ base-bench.txt │             pr-bench.txt              │
                                        │      B/op      │     B/op      vs base                 │
SampdoAll/sampdo/100000/duplicates-4        1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.099 n=10)
SampdoAll/sampdo/100000/random-4            1.532Mi ± 0%   1.532Mi ± 0%  -0.00% (p=0.004 n=10)
SampdoAll/sampdo/100000/wide-4              1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.102 n=10)
SampdoAll/sampdo/100000/sorted-4            785.1Ki ± 0%   785.1Ki ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/response_time-4     1.532Mi ± 0%   1.532Mi ± 0%  +0.00% (p=0.033 n=10)
geomean                                     1.334Mi        1.334Mi       -0.00%
¹ all samples are equal

                                        │ base-bench.txt │            pr-bench.txt             │
                                        │   allocs/op    │ allocs/op   vs base                 │
SampdoAll/sampdo/100000/duplicates-4          5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/random-4              5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/wide-4                5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/sorted-4              4.000 ± 0%   4.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/response_time-4       5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                       4.782        4.782       +0.00%
¹ all samples are equal

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Nil Receiver Panic

The new methods dereference t without checking whether the source receiver is nil. Calling Count or CopyTo on a nil *Sampdo panics, unlike the nearby Sorted method which returns an error for a nil receiver. AppendTo has the same issue and should validate the source before accessing t.points.

func (t *Sampdo) Count() int {
	return len(t.points)
}

// CopyTo copies all points from the current Sampdo instance to the provided destination slice.
func (t *Sampdo) CopyTo(dst *[]float64) error {
	if dst == nil || *dst == nil {
		return fmt.Errorf("destination slice is nil")
	}
	*dst = append(*dst, t.points...)

Comment thread stats.go
@github-actions

Copy link
Copy Markdown
Contributor

Standalone PR Review

PR-Agent could not safely update the persistent review. This standalone result will not replace the canonical review.

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

Comment thread stats.go
Comment thread stats.go
kazeburo and others added 2 commits September 20, 2026 17:59
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Standalone PR Review

PR-Agent could not safely update the persistent review. This standalone result will not replace the canonical review.

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Standalone PR Review

PR-Agent could not safely update the persistent review. This standalone result will not replace the canonical review.

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@kazeburo
kazeburo merged commit bff7301 into main Sep 20, 2026
4 checks passed
@kazeburo
kazeburo deleted the feat/copy-append-to branch September 20, 2026 09:02
@github-actions github-actions Bot mentioned this pull request Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant