// NewFinalizer instantiates a finalize code generator.
552561
func NewFinalizer() *Finalizer {
	var (
		f   = &Finalizer{seen: make(map[*design.AttributeDefinition]map[*design.AttributeDefinition]*bytes.Buffer)}
		err error
	)
	fm := template.FuncMap{
		"tabs":         Tabs,
		"goify":        Goify,
		"gotyperef":    GoTypeRef,
		"add":          Add,
		"finalizeCode": f.Code,
	}
	f.assignmentT, err = template.New("assignment").Funcs(fm).Parse(assignmentTmpl)
	if err != nil {
		panic(err)
	}
	f.arrayAssignmentT, err = template.New("arrAssignment").Funcs(fm).Parse(arrayAssignmentTmpl)
	if err != nil {
		panic(err)
	}
	return f
}
1046537
func NewGenerator(options ...Option) *Generator {
	g := &Generator{}

	for _, option := range options {
		option(g)
	}

	return g
}
1045899
func NewChecker() *Checker {
	pc := make([]uintptr, 50)
	ch := &Checker{pc[:runtime.Callers(0, pc)]}
	runtime.SetFinalizer(ch, (*Checker).finalize)
	return ch
}
382540
func validateKubeFinalizerName(stringValue string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	if len(strings.Split(stringValue, "/")) == 1 {
		if !helper.IsStandardFinalizerName(stringValue) {
			return append(allErrs, field.Invalid(fldPath, stringValue, "name is neither a standard finalizer name nor is it fully qualified"))
		}
	}

	return allErrs
}
1279365
func NewLinearizer(ctx context.Context, r io.Reader, readSize, bufferSize int) (l *Linearizer) {
	l = &Linearizer{
		bufferSize: bufferSize,
		bytesPool:  sync.Pool{New: func() interface{} { return make([]byte, readSize) }},
		r:          r,
	}
	l.ctx, l.cancel = context.WithCancel(ctx)
	return
}
1168725
func CRDRemoveFinalizer(crd *CustomResourceDefinition, needle string) {
	newFinalizers := []string{}
	for _, finalizer := range crd.Finalizers {
		if finalizer != needle {
			newFinalizers = append(newFinalizers, finalizer)
		}
	}
	crd.Finalizers = newFinalizers
}
306260
func NewFinally(Stmts []node.Node) *Finally {
	return &Finally{
		FreeFloating: nil,
		Stmts:        Stmts,
	}
}
848720
func NewGenerator(sections uint) (*Generator, error) {
	if sections%8 != 0 {
		return nil, errors.New("section count not multiple of 8")
	}
	b := &Generator{sections: sections}
	for i := 0; i < types.BloomBitLength; i++ {
		b.blooms[i] = make([]byte, sections/8)
	}
	return b, nil
}
414412
func WithFinalizer(finalizer Finalizer) options.Opt {
	return func(p options.Params) {
		logger.Debug("Checking finalizerSetter")
		if setter, ok := p.(finalizerSetter); ok {
			setter.SetFinalizer(finalizer)
		}
	}
}
383703
func NewGenerator(pkg, target string) (*Generator, error) {
	var err error
	if pkg == "" || pkg[0] == '.' {
		pkg, err = filepath.Abs(filepath.Clean(pkg))
		if err != nil {
			return nil, err
		}
		pkg = gogenutil.StripGopath(pkg)
	}
	p, err := importer.Default().Import(pkg)
	if err != nil {
		return nil, err
	}
	obj := p.Scope().Lookup(target)
	if obj == nil {
		return nil, fmt.Errorf("struct %s missing", target)
	}
	if _, ok := obj.Type().Underlying().(*types.Struct); !ok {
		return nil, fmt.Errorf("%s should be an struct, was %s", target, obj.Type().Underlying())
	}
	return &Generator{
		targetName: target,
		pkg:        p,
		target:     obj.Type().Underlying().(*types.Struct),
	}, nil
}
305960
func NewGenerator() (*Generator, error) {
	var g Generator
	_, err := rand.Read(g.seed[:])
	if err != nil {
		return nil, errors.New("cannot generate random seed: " + err.Error())
	}
	return &g, nil
}
464762
func ValidateFinalizers(finalizers []string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	hasFinalizerOrphanDependents := false
	hasFinalizerDeleteDependents := false
	for _, finalizer := range finalizers {
		allErrs = append(allErrs, ValidateFinalizerName(finalizer, fldPath)...)
		if finalizer == metav1.FinalizerOrphanDependents {
			hasFinalizerOrphanDependents = true
		}
		if finalizer == metav1.FinalizerDeleteDependents {
			hasFinalizerDeleteDependents = true
		}
	}
	if hasFinalizerDeleteDependents && hasFinalizerOrphanDependents {
		allErrs = append(allErrs, field.Invalid(fldPath, finalizers, fmt.Sprintf("finalizer %s and %s cannot be both set", metav1.FinalizerOrphanDependents, metav1.FinalizerDeleteDependents)))
	}
	return allErrs
}
1044455
func (c *RefCount) Finalizer() resource.Finalizer {
	finalizerPtr := (*resource.Finalizer)(atomic.LoadPointer(&c.finalizer))
	if finalizerPtr == nil {
		return nil
	}
	return *finalizerPtr
}
514793
func NewProjectionFinal(ctx *Context, p *Select) (*Projection, error) {
	s := &Projection{
		P:        p,
		Stmt:     p.Stmt,
		PlanBase: NewPlanBase(false),
		Final:    true,
	}
	var err error
	if len(p.Stmt.From) == 0 {
		err = s.loadLiteralProjection(ctx)
	} else if len(p.From) == 1 && p.From[0].Proj != nil {
		s.Proj = p.From[0].Proj
	} else {
		err = s.loadFinal(ctx, true)
	}
	if err != nil {
		return nil, err
	}
	return s, nil
}
513216
func NewLimiter(defaultRates *RateSet, capacity int, mapper limit.MapperFn, configMapper ConfigMapperFn, clock timetools.TimeProvider) (*TokenLimiter, error) {
	if defaultRates == nil || len(defaultRates.m) == 0 {
		return nil, fmt.Errorf("Provide default rates")
	}
	if mapper == nil {
		return nil, fmt.Errorf("Provide mapper function")
	}

	// Set default values for optional fields.
	if capacity <= 0 {
		capacity = DefaultCapacity
	}
	if clock == nil {
		clock = &timetools.RealTime{}
	}

	bucketSets, err := ttlmap.NewMapWithProvider(DefaultCapacity, clock)
	if err != nil {
		return nil, err
	}

	return &TokenLimiter{
		defaultRates: defaultRates,
		mapper:       mapper,
		configMapper: configMapper,
		clock:        clock,
		bucketSets:   bucketSets,
	}, nil
}
1235260
func NewCheckedObjectPool(opts ObjectPoolOptions) CheckedObjectPool {
	if opts == nil {
		opts = NewObjectPoolOptions()
	}
	return &checkedObjectPool{
		pool: NewObjectPool(opts),
		finalizerPool: NewObjectPool(opts.SetInstrumentOptions(opts.InstrumentOptions().
			SetMetricsScope(opts.InstrumentOptions().
				MetricsScope().
				SubScope("finalizer-pool")))),
	}
}
1260091
func NewCompiler() (*Compiler, error) {
	var yrCompiler *C.YR_COMPILER
	if err := newError(C.yr_compiler_create(&yrCompiler)); err != nil {
		return nil, err
	}
	c := &Compiler{compiler: &compiler{cptr: yrCompiler}}
	runtime.SetFinalizer(c.compiler, (*compiler).finalize)
	return c, nil
}