Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
echo 'export GOPATH="$HOME/go"' >> $BASH_ENV
source $BASH_ENV
- checkout
- run: go test
- run: go test -v ./...

workflows:
version: 2
Expand Down
16 changes: 9 additions & 7 deletions simple.go → simple/simple.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright 2019, LightStep Inc.

package varopt
package simple

import (
"math/rand"

"github.com/lightstep/varopt"
)

// Simple implements unweighted reservoir sampling using Algorithm R
Expand All @@ -12,13 +14,13 @@ import (
type Simple struct {
capacity int
observed int
buffer []Sample
buffer []varopt.Sample
rnd *rand.Rand
}

// NewSimple returns a simple reservoir sampler with given capacity
// New returns a simple reservoir sampler with given capacity
// (i.e., reservoir size) and random number generator.
func NewSimple(capacity int, rnd *rand.Rand) *Simple {
func New(capacity int, rnd *rand.Rand) *Simple {
return &Simple{
capacity: capacity,
rnd: rnd,
Expand All @@ -27,11 +29,11 @@ func NewSimple(capacity int, rnd *rand.Rand) *Simple {

// Add considers a new observation for the sample. Items have unit
// weight.
func (s *Simple) Add(span Sample) {
func (s *Simple) Add(span varopt.Sample) {
s.observed++

if s.buffer == nil {
s.buffer = make([]Sample, 0, s.capacity)
s.buffer = make([]varopt.Sample, 0, s.capacity)
}

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

// Get returns the i'th selected item from the sample.
func (s *Simple) Get(i int) Sample {
func (s *Simple) Get(i int) varopt.Sample {
return s.buffer[i]
}

Expand Down
41 changes: 0 additions & 41 deletions simple_test.go

This file was deleted.

11 changes: 6 additions & 5 deletions varopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/lightstep/varopt"
"github.com/lightstep/varopt/simple"
"github.com/stretchr/testify/require"
)

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

for _, blockList := range blockLists {
for _, block := range blockList {
simple := varopt.NewSimple(sampleSize, rnd)
ss := simple.New(sampleSize, rnd)

for _, s := range block {
simple.Add(s)
ss.Add(s)
}

weight := simple.Weight()
for i := 0; i < simple.Size(); i++ {
vsample.Add(simple.Get(i), weight)
weight := ss.Weight()
for i := 0; i < ss.Size(); i++ {
vsample.Add(ss.Get(i), weight)
}
}
}
Expand Down