Skip to content

Commit 8fa9c70

Browse files
authored
Merge pull request #6 from lightstep/jmacd/move_simple
Move simple into subpackage
2 parents d93f23f + cd73568 commit 8fa9c70

File tree

4 files changed

+16
-54
lines changed

4 files changed

+16
-54
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
echo 'export GOPATH="$HOME/go"' >> $BASH_ENV
1313
source $BASH_ENV
1414
- checkout
15-
- run: go test
15+
- run: go test -v ./...
1616

1717
workflows:
1818
version: 2

simple.go renamed to simple/simple.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright 2019, LightStep Inc.
22

3-
package varopt
3+
package simple
44

55
import (
66
"math/rand"
7+
8+
"github.com/lightstep/varopt"
79
)
810

911
// Simple implements unweighted reservoir sampling using Algorithm R
@@ -12,13 +14,13 @@ import (
1214
type Simple struct {
1315
capacity int
1416
observed int
15-
buffer []Sample
17+
buffer []varopt.Sample
1618
rnd *rand.Rand
1719
}
1820

19-
// NewSimple returns a simple reservoir sampler with given capacity
21+
// New returns a simple reservoir sampler with given capacity
2022
// (i.e., reservoir size) and random number generator.
21-
func NewSimple(capacity int, rnd *rand.Rand) *Simple {
23+
func New(capacity int, rnd *rand.Rand) *Simple {
2224
return &Simple{
2325
capacity: capacity,
2426
rnd: rnd,
@@ -27,11 +29,11 @@ func NewSimple(capacity int, rnd *rand.Rand) *Simple {
2729

2830
// Add considers a new observation for the sample. Items have unit
2931
// weight.
30-
func (s *Simple) Add(span Sample) {
32+
func (s *Simple) Add(span varopt.Sample) {
3133
s.observed++
3234

3335
if s.buffer == nil {
34-
s.buffer = make([]Sample, 0, s.capacity)
36+
s.buffer = make([]varopt.Sample, 0, s.capacity)
3537
}
3638

3739
if len(s.buffer) < s.capacity {
@@ -47,7 +49,7 @@ func (s *Simple) Add(span Sample) {
4749
}
4850

4951
// Get returns the i'th selected item from the sample.
50-
func (s *Simple) Get(i int) Sample {
52+
func (s *Simple) Get(i int) varopt.Sample {
5153
return s.buffer[i]
5254
}
5355

simple_test.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

varopt_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/lightstep/varopt"
11+
"github.com/lightstep/varopt/simple"
1112
"github.com/stretchr/testify/require"
1213
)
1314

@@ -106,15 +107,15 @@ func testUnbiased(t *testing.T, bbr, bsr float64) {
106107

107108
for _, blockList := range blockLists {
108109
for _, block := range blockList {
109-
simple := varopt.NewSimple(sampleSize, rnd)
110+
ss := simple.New(sampleSize, rnd)
110111

111112
for _, s := range block {
112-
simple.Add(s)
113+
ss.Add(s)
113114
}
114115

115-
weight := simple.Weight()
116-
for i := 0; i < simple.Size(); i++ {
117-
vsample.Add(simple.Get(i), weight)
116+
weight := ss.Weight()
117+
for i := 0; i < ss.Size(); i++ {
118+
vsample.Add(ss.Get(i), weight)
118119
}
119120
}
120121
}

0 commit comments

Comments
 (0)