MCPcopy Create free account
hub / github.com/careercup/ctci / Push

Method Push

go/chapter04/queue/queue.go:69–83  ·  view source on GitHub ↗

Pushes/inserts a value at the end/tail of the queue. Note: this function does mutate the queue. go-routine safe.

(item interface{})

Source from the content-addressed store, hash-verified

67// Note: this function does mutate the queue.
68// go-routine safe.
69func (q *Queue) Push(item interface{}) {
70 q.lock.Lock()
71 defer q.lock.Unlock()
72
73 n := &queuenode{data: item}
74
75 if q.tail == nil {
76 q.tail = n
77 q.head = n
78 } else {
79 q.tail.next = n
80 q.tail = n
81 }
82 q.count++
83}
84
85// Returns the value at the front of the queue.
86// i.e. the oldest value in the queue.

Callers 2

mainFunction · 0.45
isPathAvailableFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected