Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Just go fmt... #3

Closed
wants to merge 1 commit into from

2 participants

Nolan Caudill Richard Crowley
Nolan Caudill

Nothing exciting here, just ran 'go fmt'.

Richard Crowley rcrowley closed this September 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 10, 2012
Nolan Caudill Ran go fmt 103024a
This page is out of date. Refresh to see the latest.
12  ewma.go
@@ -20,10 +20,10 @@ type EWMA interface {
20 20
 // events and processes them on each tick.  It uses the sync/atomic package
21 21
 // to manage uncounted events.
22 22
 type StandardEWMA struct {
23  
-	alpha float64
  23
+	alpha     float64
24 24
 	uncounted int64
25  
-	in chan bool
26  
-	out chan float64
  25
+	in        chan bool
  26
+	out       chan float64
27 27
 }
28 28
 
29 29
 // Create a new EWMA with the given alpha.  Create the clock channel and
@@ -36,17 +36,17 @@ func NewEWMA(alpha float64) *StandardEWMA {
36 36
 
37 37
 // Create a new EWMA with alpha set for a one-minute moving average.
38 38
 func NewEWMA1() *StandardEWMA {
39  
-	return NewEWMA(1 - math.Exp(-5.0 / 60.0 / 1))
  39
+	return NewEWMA(1 - math.Exp(-5.0/60.0/1))
40 40
 }
41 41
 
42 42
 // Create a new EWMA with alpha set for a five-minute moving average.
43 43
 func NewEWMA5() *StandardEWMA {
44  
-	return NewEWMA(1 - math.Exp(-5.0 / 60.0 / 5))
  44
+	return NewEWMA(1 - math.Exp(-5.0/60.0/5))
45 45
 }
46 46
 
47 47
 // Create a new EWMA with alpha set for a fifteen-minute moving average.
48 48
 func NewEWMA15() *StandardEWMA {
49  
-	return NewEWMA(1 - math.Exp(-5.0 / 60.0 / 15))
  49
+	return NewEWMA(1 - math.Exp(-5.0/60.0/15))
50 50
 }
51 51
 
52 52
 // Return the moving average rate of events per second.
4  ewma_test.go
@@ -210,5 +210,7 @@ func TestEWMA15(t *testing.T) {
210 210
 }
211 211
 
212 212
 func elapseMinute(a EWMA) {
213  
-	for i := 0; i < 12; i++ { a.Tick() }
  213
+	for i := 0; i < 12; i++ {
  214
+		a.Tick()
  215
+	}
214 216
 }
45  histogram.go
@@ -25,9 +25,9 @@ type Histogram interface {
25 25
 // The standard implementation of a Histogram uses a Sample and a goroutine
26 26
 // to synchronize its calculations.
27 27
 type StandardHistogram struct {
28  
-	s Sample
29  
-	in chan int64
30  
-	out chan histogramV
  28
+	s     Sample
  29
+	in    chan int64
  30
+	out   chan histogramV
31 31
 	reset chan bool
32 32
 }
33 33
 
@@ -35,7 +35,7 @@ type StandardHistogram struct {
35 35
 // from the synchronizing goroutine.
36 36
 type histogramV struct {
37 37
 	count, sum, min, max int64
38  
-	variance [2]float64
  38
+	variance             [2]float64
39 39
 }
40 40
 
41 41
 // Create a new histogram with the given Sample.  Create the communication
@@ -74,7 +74,9 @@ func (h *StandardHistogram) Count() int64 {
74 74
 // Return the maximal value seen since the histogram was last cleared.
75 75
 func (h *StandardHistogram) Max() int64 {
76 76
 	hv := <-h.out
77  
-	if 0 < hv.count { return hv.max }
  77
+	if 0 < hv.count {
  78
+		return hv.max
  79
+	}
78 80
 	return 0
79 81
 }
80 82
 
@@ -90,7 +92,9 @@ func (h *StandardHistogram) Mean() float64 {
90 92
 // Return the minimal value seen since the histogram was last cleared.
91 93
 func (h *StandardHistogram) Min() int64 {
92 94
 	hv := <-h.out
93  
-	if 0 < hv.count { return hv.min }
  95
+	if 0 < hv.count {
  96
+		return hv.min
  97
+	}
94 98
 	return 0
95 99
 }
96 100
 
@@ -109,15 +113,15 @@ func (h *StandardHistogram) Percentiles(ps []float64) []float64 {
109 113
 	if size > 0 {
110 114
 		sort.Sort(values)
111 115
 		for i, p := range ps {
112  
-			pos := p * float64(size + 1)
  116
+			pos := p * float64(size+1)
113 117
 			if pos < 1.0 {
114 118
 				scores[i] = float64(values[0])
115 119
 			} else if pos >= float64(size) {
116  
-				scores[i] = float64(values[size - 1])
  120
+				scores[i] = float64(values[size-1])
117 121
 			} else {
118  
-				lower := float64(values[int(pos) - 1])
  122
+				lower := float64(values[int(pos)-1])
119 123
 				upper := float64(values[int(pos)])
120  
-				scores[i] = lower + (pos - math.Floor(pos)) * (upper - lower)
  124
+				scores[i] = lower + (pos-math.Floor(pos))*(upper-lower)
121 125
 			}
122 126
 		}
123 127
 	}
@@ -138,8 +142,10 @@ func (h *StandardHistogram) Update(v int64) {
138 142
 // Return the variance of all values seen since the histogram was last cleared.
139 143
 func (h *StandardHistogram) Variance() float64 {
140 144
 	hv := <-h.out
141  
-	if 1 >= hv.count { return 0.0 }
142  
-	return hv.variance[1] / float64(hv.count - 1)
  145
+	if 1 >= hv.count {
  146
+		return 0.0
  147
+	}
  148
+	return hv.variance[1] / float64(hv.count-1)
143 149
 }
144 150
 
145 151
 // Receive inputs and send outputs.  Sample each input and update values in
@@ -151,8 +157,12 @@ func (h *StandardHistogram) arbiter() {
151 157
 		case v := <-h.in:
152 158
 			h.s.Update(v)
153 159
 			hv.count++
154  
-			if v < hv.min { hv.min = v }
155  
-			if v > hv.max { hv.max = v }
  160
+			if v < hv.min {
  161
+				hv.min = v
  162
+			}
  163
+			if v > hv.max {
  164
+				hv.max = v
  165
+			}
156 166
 			hv.sum += v
157 167
 			fv := float64(v)
158 168
 			if -1.0 == hv.variance[0] {
@@ -161,11 +171,11 @@ func (h *StandardHistogram) arbiter() {
161 171
 			} else {
162 172
 				m := hv.variance[0]
163 173
 				s := hv.variance[1]
164  
-				hv.variance[0] = m + (fv - m) / float64(hv.count)
165  
-				hv.variance[1] = s + (fv - m) * (fv - hv.variance[0])
  174
+				hv.variance[0] = m + (fv-m)/float64(hv.count)
  175
+				hv.variance[1] = s + (fv-m)*(fv-hv.variance[0])
166 176
 			}
167 177
 		case h.out <- hv:
168  
-		case <- h.reset:
  178
+		case <-h.reset:
169 179
 			h.s.Clear()
170 180
 			hv = newHistogramV()
171 181
 		}
@@ -174,6 +184,7 @@ func (h *StandardHistogram) arbiter() {
174 184
 
175 185
 // Cribbed from the standard library's `sort` package.
176 186
 type int64Slice []int64
  187
+
177 188
 func (p int64Slice) Len() int           { return len(p) }
178 189
 func (p int64Slice) Less(i, j int) bool { return p[i] < p[j] }
179 190
 func (p int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
4  histogram_test.go
@@ -33,7 +33,9 @@ func TestEmptyHistogram(t *testing.T) {
33 33
 
34 34
 func TestHistogram10000(t *testing.T) {
35 35
 	h := NewHistogram(NewUniformSample(100000))
36  
-	for i := 1; i <= 10000; i++ { h.Update(int64(i)) }
  36
+	for i := 1; i <= 10000; i++ {
  37
+		h.Update(int64(i))
  38
+	}
37 39
 	if count := h.Count(); 10000 != count {
38 40
 		t.Errorf("h.Count(): 10000 != %v\n", count)
39 41
 	}
16  sample_test.go
@@ -4,7 +4,9 @@ import "testing"
4 4
 
5 5
 func TestExpDecaySample10(t *testing.T) {
6 6
 	s := NewExpDecaySample(100, 0.99)
7  
-	for i := 0; i < 10; i++ { s.Update(int64(i)) }
  7
+	for i := 0; i < 10; i++ {
  8
+		s.Update(int64(i))
  9
+	}
8 10
 	if size := s.Size(); 10 != size {
9 11
 		t.Errorf("s.Size(): 10 != %v\n", size)
10 12
 	}
@@ -20,7 +22,9 @@ func TestExpDecaySample10(t *testing.T) {
20 22
 
21 23
 func TestExpDecaySample100(t *testing.T) {
22 24
 	s := NewExpDecaySample(1000, 0.01)
23  
-	for i := 0; i < 100; i++ { s.Update(int64(i)) }
  25
+	for i := 0; i < 100; i++ {
  26
+		s.Update(int64(i))
  27
+	}
24 28
 	if size := s.Size(); 100 != size {
25 29
 		t.Errorf("s.Size(): 100 != %v\n", size)
26 30
 	}
@@ -36,7 +40,9 @@ func TestExpDecaySample100(t *testing.T) {
36 40
 
37 41
 func TestExpDecaySample1000(t *testing.T) {
38 42
 	s := NewExpDecaySample(100, 0.99)
39  
-	for i := 0; i < 1000; i++ { s.Update(int64(i)) }
  43
+	for i := 0; i < 1000; i++ {
  44
+		s.Update(int64(i))
  45
+	}
40 46
 	if size := s.Size(); 100 != size {
41 47
 		t.Errorf("s.Size(): 100 != %v\n", size)
42 48
 	}
@@ -52,7 +58,9 @@ func TestExpDecaySample1000(t *testing.T) {
52 58
 
53 59
 func TestUniformSample(t *testing.T) {
54 60
 	s := NewUniformSample(100)
55  
-	for i := 0; i < 1000; i++ { s.Update(int64(i)) }
  61
+	for i := 0; i < 1000; i++ {
  62
+		s.Update(int64(i))
  63
+	}
56 64
 	if size := s.Size(); 100 != size {
57 65
 		t.Errorf("s.Size(): 100 != %v\n", size)
58 66
 	}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.