// NewQueue creates a new queue with initial size.
490397
func NewAtomicQueue(size int) *AtomicQueue {
	if size <= 0 {
		panic("Queue size cannot be less than 1")
	}

	return &AtomicQueue{
		wrapped: false,
		data:    make([]interface{}, uint32(size)),
		size:    uint32(size),
	}
}
1263779
func (q *execQueue) queue(f func()) bool {
	q.mu.Lock()
	ok := !q.isClosed() && len(q.funcs) < cap(q.funcs)
	if ok {
		q.funcs = append(q.funcs, f)
		q.cond.Signal()
	}
	q.mu.Unlock()
	return ok
}
1342016
func New(size int) *Cache {
	c := Cache{
		size: size,
	}
	c.Reset()
	return &c
}
372824
func New(limit int) SizedWaitGroup {
	size := math.MaxInt32 // 2^32 - 1
	if limit > 0 {
		size = limit
	}
	return SizedWaitGroup{
		Size: size,

		current: make(chan struct{}, size),
		wg:      sync.WaitGroup{},
	}
}
285778
func NewFilterQueue(queueSeparation bool, MarkValue int, QueueStart, NumberOfNetworkQueues, NumberOfApplicationQueues uint16, NetworkQueueSize, ApplicationQueueSize uint32) *FilterQueue {

	fq := &FilterQueue{
		QueueSeparation:      queueSeparation,
		MarkValue:            MarkValue,
		NetworkQueueSize:     NetworkQueueSize,
		ApplicationQueueSize: ApplicationQueueSize,
	}

	if queueSeparation {

		fq.ApplicationQueue = QueueStart
		fq.ApplicationQueuesSynStr = strconv.Itoa(int(fq.ApplicationQueue)) + ":" + strconv.Itoa(int(fq.ApplicationQueue+NumberOfApplicationQueues-1))
		fq.ApplicationQueuesAckStr = strconv.Itoa(int(fq.ApplicationQueue+1*NumberOfApplicationQueues)) + ":" + strconv.Itoa(int(fq.ApplicationQueue+2*NumberOfApplicationQueues-1))
		fq.ApplicationQueuesSynAckStr = strconv.Itoa(int(fq.ApplicationQueue+2*NumberOfApplicationQueues)) + ":" + strconv.Itoa(int(fq.ApplicationQueue+3*NumberOfApplicationQueues-1))
		fq.ApplicationQueuesSvcStr = strconv.Itoa(int(fq.ApplicationQueue+3*NumberOfApplicationQueues)) + ":" + strconv.Itoa(int(fq.ApplicationQueue+4*NumberOfApplicationQueues-1))
		fq.NumberOfApplicationQueues = NumberOfApplicationQueues * 4

		fq.NetworkQueue = QueueStart + fq.NumberOfApplicationQueues
		fq.NetworkQueuesSynStr = strconv.Itoa(int(fq.NetworkQueue)) + ":" + strconv.Itoa(int(fq.NetworkQueue+NumberOfNetworkQueues-1))
		fq.NetworkQueuesAckStr = strconv.Itoa(int(fq.NetworkQueue+1*NumberOfNetworkQueues)) + ":" + strconv.Itoa(int(fq.NetworkQueue+2*NumberOfNetworkQueues-1))
		fq.NetworkQueuesSynAckStr = strconv.Itoa(int(fq.NetworkQueue+2*NumberOfNetworkQueues)) + ":" + strconv.Itoa(int(fq.NetworkQueue+3*NumberOfNetworkQueues-1))
		fq.NetworkQueuesSvcStr = strconv.Itoa(int(fq.NetworkQueue+3*NumberOfNetworkQueues)) + ":" + strconv.Itoa(int(fq.NetworkQueue+4*NumberOfNetworkQueues-1))
		fq.NumberOfNetworkQueues = NumberOfNetworkQueues * 4
	} else {

		fq.ApplicationQueue = QueueStart
		fq.ApplicationQueuesSynStr = strconv.Itoa(int(fq.ApplicationQueue)) + ":" + strconv.Itoa(int(fq.ApplicationQueue+NumberOfApplicationQueues-1))
		fq.ApplicationQueuesAckStr = fq.ApplicationQueuesSynStr
		fq.ApplicationQueuesSvcStr = fq.ApplicationQueuesSynStr
		fq.ApplicationQueuesSynAckStr = fq.ApplicationQueuesSynStr
		fq.NumberOfApplicationQueues = NumberOfApplicationQueues

		fq.NetworkQueue = QueueStart + fq.NumberOfApplicationQueues
		fq.NetworkQueuesSynStr = strconv.Itoa(int(fq.NetworkQueue)) + ":" + strconv.Itoa(int(fq.NetworkQueue+NumberOfNetworkQueues-1))
		fq.NetworkQueuesAckStr = fq.NetworkQueuesSynStr
		fq.NetworkQueuesSynAckStr = fq.NetworkQueuesSynStr
		fq.NetworkQueuesSvcStr = fq.NetworkQueuesSynStr
		fq.NumberOfNetworkQueues = NumberOfNetworkQueues
	}

	return fq
}
1076485
func NewFilterQueueWithDefaults() *FilterQueue {
	return NewFilterQueue(
		DefaultQueueSeperation,
		DefaultMarkValue,
		DefaultQueueStart,
		DefaultNumberOfQueues,
		DefaultNumberOfQueues,
		DefaultQueueSize,
		DefaultQueueSize,
	)
}
322739
func (heap *FloatingFibonacciHeap) Enqueue(priority float64) *Entry {
	singleton := newEntry(priority)

	// Merge singleton list with heap
	heap.min = mergeLists(heap.min, singleton)
	heap.size++
	return singleton
}
152924
func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue, error) {
	namespaced := namespace.Wrap(ds, datastore.NewKey("/"+name+"/queue/"))
	head, tail, err := getQueueHeadTail(ctx, namespaced)
	if err != nil {
		return nil, err
	}
	cancelCtx, cancel := context.WithCancel(ctx)
	q := &Queue{
		name:    name,
		ctx:     cancelCtx,
		head:    head,
		tail:    tail,
		ds:      namespaced,
		dequeue: make(chan cid.Cid),
		enqueue: make(chan cid.Cid),
		close:   cancel,
		closed:  make(chan struct{}, 1),
	}
	q.work()
	return q, nil
}
992094
func NewQueue(service *Service, workers uint) *Queue {
	// unbuffered channels
	q := &Queue{
		service:       service,
		notifications: make(chan notification),
		Responses:     make(chan Response),
	}
	// startup workers to send notifications
	for i := uint(0); i < workers; i++ {
		go worker(q)
	}
	return q
}
1097540
func NewCtxQueue() *CtxQueue {
	return &CtxQueue{
		c:          make(chan ctxQueueMessage),
		o:          &sync.Once{},
		startC:     sync.NewCond(&sync.Mutex{}),
		statListen: astistat.NewDurationRatioStat(),
	}
}
474802
func NewDroppingQueue(max int) Queue {
	return Queue{queue: make([]interface{}, 0, max), maxLen: max, mode: modeDrop}
}
1111651
func (q *Queue) Enqueue(value []byte) (*Item, error) {
	q.Lock()
	defer q.Unlock()

	// Check if queue is closed.
	if !q.isOpen {
		return nil, ErrDBClosed
	}

	// Create new Item.
	item := &Item{
		ID:    q.tail + 1,
		Key:   idToKey(q.tail + 1),
		Value: value,
	}

	// Add it to the queue.
	if err := q.db.Put(item.Key, item.Value, nil); err != nil {
		return nil, err
	}

	// Increment tail position.
	q.tail++

	return item, nil
}
683520
func NewQueue(senderFunc SenderFunc) *Queue {
	q := Queue{
		senderFunc: senderFunc,
		conns:      make(map[string]string),
		reqChans:   make(map[string]queueChan),

		middlewareChan: make(chan middlewareChan, 5000),
		remUserChan:    make(chan string, 5000),
		addReqChan:     make(chan addReqChan, 5000),
		delQueueChan:   make(chan string, 5000),
	}

	go q.worker()

	return &q
}
322457
func (s *GetQueueOutput) SetQueue(v *Queue) *GetQueueOutput {
	s.Queue = v
	return s
}
1108609
func (s *UpdateQueueOutput) SetQueue(v *Queue) *UpdateQueueOutput {
	s.Queue = v
	return s
}
214431
func (pq *PrefixQueue) Enqueue(prefix, value []byte) (*Item, error) {
	pq.Lock()
	defer pq.Unlock()

	// Check if queue is closed.
	if !pq.isOpen {
		return nil, ErrDBClosed
	}

	// Get the queue for this prefix.
	q, err := pq.getOrCreateQueue(prefix)
	if err != nil {
		return nil, err
	}

	// Create new Item.
	item := &Item{
		ID:    q.Tail + 1,
		Key:   generateKeyPrefixID(prefix, q.Tail+1),
		Value: value,
	}

	// Add it to the queue.
	if err := pq.db.Put(item.Key, item.Value, nil); err != nil {
		return nil, err
	}

	// Increment tail position and prefix queue size.
	q.Tail++
	pq.size++

	// Save the queue.
	if err := pq.saveQueue(prefix, q); err != nil {
		return nil, err
	}

	// Save main prefix queue data.
	if err := pq.save(); err != nil {
		return nil, err
	}

	return item, nil
}
347526
func NewEvictingStringQueue(size int) *EvictingStringQueue {
	return &EvictingStringQueue{size: size, set: make(map[string]bool)}
}