MCPcopy Create free account
hub / github.com/blindlobstar/go-interview-problems / Push

Method Push

12-concurrent-queue-iii/solution/solution.go:23–34  ·  view source on GitHub ↗
(val int)

Source from the content-addressed store, hash-verified

21}
22
23func (q *Queue) Push(val int) error {
24 q.Lock()
25 defer q.Unlock()
26
27 if q.w == q.r || q.w%len(q.data) != q.r%len(q.data) {
28 q.data[q.w%len(q.data)] = val
29 q.w++
30 return nil
31 } else {
32 return ErrQueueFull
33 }
34}
35
36func (q *Queue) Pop() int {
37 q.Lock()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected