By Golang
// Package queue creates a ItemQueue data structure for the Item typepackage queueimport ( "sync")// Item the type of the queuetype Item interface{}// ItemQueue the queue of Itemstype ItemQueue struct { items []Item lock sync.RWMutex}// New creates a new ItemQueuefunc (s *ItemQueue) New() *ItemQueue { s.lock.Lock() s.items = []Item{} s.lock.Unlock() return s}// Enqueue adds an Item to the end of the queuefunc (s *ItemQueue) Enqueue(t Item) { s.lock.Lock() s.items = append(s.items, t) s.lock.Unlock()}// Dequeue removes an Item from the start of the queuefunc (s *ItemQueue) Dequeue() *Item { s.lock.Lock() item := s.items[0] s.items = s.items[1:len(s.items)] s.lock.Unlock() return &item}// Front returns the item next in the queue, without removing itfunc (s *ItemQueue) Front() *Item { s.lock.RLock() item := s.items[0] s.lock.RUnlock() return &item}// IsEmpty returns true if the queue is emptyfunc (s *ItemQueue) IsEmpty() bool { s.lock.RLock() defer s.lock.RUnlock() return len(s.items) == 0}// Size returns the number of Items in the queuefunc (s *ItemQueue) Size() int { s.lock.RLock() defer s.lock.RUnlock() return len(s.items)}