Skip to content

Commit b81671b

Browse files
Initial work on ring buffer.
1 parent fe62d5c commit b81671b

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

btree/palm/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func (ptree *ptree) runOperations() {
151151
writeOperations[n] = append(writeOperations[n], toPerform.writes[i])
152152
}
153153

154-
toPerform.signaler <- true
155154
ptree.runAdds(writeOperations)
155+
toPerform.signaler <- true
156156
}
157157

158158
func (ptree *ptree) recursiveSplit(n, parent, left *node, nodes *[]*node, keys *Keys) {

btree/palm/tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func BenchmarkBulkAddToExisting(b *testing.B) {
331331
keySet = append(keySet, generateRandomKeys(numItems))
332332
}
333333

334-
tree := newTree(1024)
334+
tree := newTree(32768)
335335

336336
b.ResetTimer()
337337

queue/error.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ limitations under the License.
1616

1717
package queue
1818

19-
type DisposedError struct{}
19+
import "errors"
2020

21-
func (de DisposedError) Error() string {
22-
return `Queue has been disposed.`
23-
}
21+
var disposedError = errors.New(`Queue has been disposed.`)

queue/priority_queue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (pq *PriorityQueue) Put(items ...Item) error {
107107
pq.lock.Lock()
108108
if pq.disposed {
109109
pq.lock.Unlock()
110-
return DisposedError{}
110+
return disposedError
111111
}
112112

113113
for _, item := range items {
@@ -144,7 +144,7 @@ func (pq *PriorityQueue) Get(number int) ([]Item, error) {
144144

145145
if pq.disposed {
146146
pq.lock.Unlock()
147-
return nil, DisposedError{}
147+
return nil, disposedError
148148
}
149149

150150
var items []Item
@@ -159,7 +159,7 @@ func (pq *PriorityQueue) Get(number int) ([]Item, error) {
159159
pq.disposeLock.Lock()
160160
if pq.disposed {
161161
pq.disposeLock.Unlock()
162-
return nil, DisposedError{}
162+
return nil, disposedError
163163
}
164164
pq.disposeLock.Unlock()
165165

queue/queue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (q *Queue) Put(items ...interface{}) error {
128128

129129
if q.disposed {
130130
q.lock.Unlock()
131-
return DisposedError{}
131+
return disposedError
132132
}
133133

134134
q.items = append(q.items, items...)
@@ -163,7 +163,7 @@ func (q *Queue) Get(number int64) ([]interface{}, error) {
163163

164164
if q.disposed {
165165
q.lock.Unlock()
166-
return nil, DisposedError{}
166+
return nil, disposedError
167167
}
168168

169169
var items []interface{}
@@ -177,7 +177,7 @@ func (q *Queue) Get(number int64) ([]interface{}, error) {
177177
sema.wg.Wait()
178178
// we are now inside the put's lock
179179
if q.disposed {
180-
return nil, DisposedError{}
180+
return nil, disposedError
181181
}
182182
items = q.items.get(number)
183183
sema.response.Done()
@@ -201,7 +201,7 @@ func (q *Queue) TakeUntil(checker func(item interface{}) bool) ([]interface{}, e
201201

202202
if q.disposed {
203203
q.lock.Unlock()
204-
return nil, DisposedError{}
204+
return nil, disposedError
205205
}
206206

207207
result := q.items.getUntil(checker)

queue/queue.prof

30.4 KB
Binary file not shown.

queue/ring.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2014 Workiva, LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package queue
17+
18+
type RingBuffer struct {
19+
ifs []interface{}
20+
placed, retrieved uint64
21+
size int64
22+
}
23+
24+
func (rb *RingBuffer) Put(items ...interface{}) error {
25+
if len(items) == 0 {
26+
return nil
27+
}
28+
29+
return nil
30+
}

0 commit comments

Comments
 (0)