// New creates a new chunk.
//  cap: the limit for the max number of rows.
//  maxChunkSize: the max limit for the number of rows.
330155
func New(fields []*types.FieldType, cap, maxChunkSize int) *Chunk {
	chk := new(Chunk)
	chk.columns = make([]*column, 0, len(fields))
	chk.capacity = mathutil.Min(cap, maxChunkSize)
	for _, f := range fields {
		elemLen := getFixedLen(f)
		if elemLen == varElemLen {
			chk.columns = append(chk.columns, newVarLenColumn(chk.capacity, nil))
		} else {
			chk.columns = append(chk.columns, newFixedLenColumn(elemLen, chk.capacity))
		}
	}
	chk.numVirtualRows = 0

	// set the default value of requiredRows to maxChunkSize to let chk.IsFull() behave
	// like how we judge whether a chunk is full now, then the statement
	// "chk.NumRows() < maxChunkSize"
	// is equal to
	// "!chk.IsFull()".
	chk.requiredRows = maxChunkSize
	return chk
}
522637
func New(maxentries int) *Cache {
	return &Cache{
		MaxEntries: maxentries,
		ll:         list.New(),
		cache:      make(map[string]*list.Element),
	}
}
709726
func New(storageConfig config.Storage) error {
	// create handler based on the storage config
	switch handlerName(storageConfig.Handler) {
	case mongodbHandler:
		handler = mongo.NewHandler(storageConfig)
	default:
		return errors.New("Invalid storage handler `" + storageConfig.Handler + "`")
	}
	// prepare handler
	return handler.Prepare()
}
1122544
func New(ctx context.Context, c *isolatedclient.Client, out io.Writer) *Archiver {
	// TODO(maruel): Cache hashes and server cache presence.
	ctx2, cancel := context.WithCancel(common.CancelOnCtrlC(ctx))
	a := &Archiver{
		ctx:      ctx2,
		cancel:   cancel,
		progress: progress.New(headers, out),
		c:        c,
		stage1:   make(chan *PendingItem),
	}
	tracer.NewPID(a, "archiver")

	// Tuning parameters.

	// Stage 1 is single threaded.

	// Stage 2; Disk I/O bound.
	// TODO(maruel): Reduce to 1 or 2.
	const maxConcurrentHash = 5

	// Stage 3; Control server overload due to parallelism (DDoS).
	const maxConcurrentContains = 64
	const containsBatchingDelay = 100 * time.Millisecond
	const containsBatchSize = 50

	// Stage 4; Network I/O bound.
	const maxConcurrentUpload = 8

	stage2 := make(chan *PendingItem)
	stage3 := make(chan *PendingItem)
	stage4 := make(chan *PendingItem)
	a.wg.Add(1)
	go func() {
		defer func() {
			a.wg.Done()
			close(stage2)
		}()
		a.stage1DedupeLoop(a.stage1, stage2)
	}()

	// TODO(todd): Create on-disk cache in a new stage inserted between stages 1
	// and 2. This should be a separate interface with its own implementation
	// that 'archiver' keeps a reference to as member.

	a.wg.Add(1)
	go func() {
		defer func() {
			a.wg.Done()
			close(stage3)
		}()
		a.stage2HashLoop(stage2, stage3, maxConcurrentHash)
	}()

	a.wg.Add(1)
	go func() {
		defer func() {
			a.wg.Done()
			close(stage4)
		}()
		a.stage3LookupLoop(stage3, stage4, maxConcurrentContains, containsBatchingDelay, containsBatchSize)
	}()

	a.wg.Add(1)
	go func() {
		defer a.wg.Done()
		a.stage4UploadLoop(stage4, maxConcurrentUpload)
	}()

	// Push an nil item to enforce stage1DedupeLoop() woke up. Otherwise this
	// could lead to a race condition if Close() is called too quickly.
	a.stage1 <- nil
	return a
}
455512
func New(metricSender MetricSender, batchDuration time.Duration) *MetricBatcher {
	mb := &MetricBatcher{
		batchTicker:  time.NewTicker(batchDuration),
		metricSender: metricSender,
		closed:       false,
		closedChan:   make(chan struct{}),
	}

	go func() {
		for {
			select {
			case <-mb.batchTicker.C:
				mb.flush(mb.resetAndReturnMetrics())
			case <-mb.closedChan:
				mb.batchTicker.Stop()
				return
			}
		}
	}()

	return mb
}
485611
func New(buckets []Bucket) *Continuum {
	var ret Continuum
	ret.Reset(buckets)
	return &ret
}
110348
func New(minSize, maxSize int) *Pool {
	if maxSize < minSize {
		panic("maxSize can't be less than minSize")
	}
	const multiplier = 2
	var pools []*sizedPool
	curSize := minSize
	for curSize < maxSize {
		pools = append(pools, newSizedPool(curSize))
		curSize *= multiplier
	}
	pools = append(pools, newSizedPool(maxSize))
	return &Pool{
		minSize: minSize,
		maxSize: maxSize,
		pools:   pools,
	}
}
483199
func New(stateSize, outputSize int) (*Skein, error) {
	if stateSize != 256 && stateSize != 512 && stateSize != 1024 {
		return nil, stateSizeError(stateSize)
	}
	if outputSize <= 0 {
		return nil, outputSizeError(outputSize)
	}
	s := new(Skein)
	s.setup(stateSize, outputSize)
	s.config = newSkeinConfiguration(s)
	s.config.setSchema(schema[:]) // "SHA3"
	s.config.setVersion(1)
	s.config.generateConfiguration()
	s.initialize()
	return s, nil
}
918640
func New(client *gumble.Client, source Source) *Stream {
	return &Stream{
		client:  client,
		Volume:  1.0,
		Source:  source,
		Command: "ffmpeg",
		pause:   make(chan struct{}),
		state:   StateInitial,
	}
}
211470
func New(hashsize int, conf *Config) (hash.Hash, error) {
	h := new(hashFunc)
	if err := Configure(&(h.hVal), hashsize, conf); err != nil {
		return nil, err
	}
	h.hashsize = hashsize
	h.hValCpy = h.hVal

	if conf != nil && len(conf.Key) > 0 {
		copy(h.key[:], conf.Key)
		h.block = h.key
		h.off = BlockSize
		h.hasKey = true
	}
	return h, nil
}
628184
func New(capacity int) queue.Interface {
	return &stack{data: make([]interface{}, capacity), length: 0}
}
349348
func New(mHandlers ...MiddlewareHandler) *NapNap {
	nap := &NapNap{
		handlers:            mHandlers,
		middleware:          build(mHandlers),
		MaxRequestBodySize:  10485760, // default 10MB for request body size
		ForwardedByClientIP: true,
	}

	nap.pool.New = func() interface{} {
		rw := NewResponseWriter()
		return NewContext(nap, nil, rw)
	}

	return nap
}
908836
func newChunkedSeq(v *PVector, i int, offset int) *chunkedSeq {
	return newChunkedSeqM(nil, v, v.arrayFor(i), i, offset)
}
900524
func New(maxEntries int, lifetime time.Duration) *Cache {
	return newWithTimeFunction(maxEntries, lifetime, time.Now)
}
702049
func New(capacity int) queue.Interface {
	return &ring{data: make([]interface{}, capacity), head: 0, tail: 0, length: 0}
}
932238
func New(min, max int) *Pool {
	return Custom(
		WithLogSizeMapping(),
		WithLogSizeRange(min, max),
	)
}
1105138
func NewWithBoundaries(rd io.Reader, pol Pol, min, max uint) *Chunker {
	c := &Chunker{
		chunkerState: chunkerState{
			buf: make([]byte, chunkerBufSize),
		},
		chunkerConfig: chunkerConfig{
			pol:       pol,
			rd:        rd,
			MinSize:   min,
			MaxSize:   max,
			splitmask: (1 << 20) - 1, // aim to create chunks of 20 bits or about 1MiB on average.
		},
	}

	c.reset()

	return c
}