// Initialises the validator Ring from the validator storage in forest
343480
func LoadValidatorRing(version int64, ringSize int,
	getImmutable func(version int64) (*storage.ImmutableForest, error)) (*validator.Ring, error) {

	// In this method we have to page through previous version of the tree in order to reconstruct the in-memory
	// ring structure. The corner cases are a little subtle but printing the buckets helps

	// The basic idea is to load each version of the tree ringSize back, work out the difference that must have occurred
	// between each bucket in the ring, and apply each diff to the ring. Once the ring is full it is symmetrical (up to
	// a reindexing). If we are loading a chain whose height is less than the ring size we need to get the initial state
	// correct

	startVersion := version - int64(ringSize)
	if startVersion < 1 {
		// The ring will not be fully populated
		startVersion = 1
	}
	var err error
	// Read state to pull immutable forests from
	rs := &ReadState{}
	// Start with an empty ring - we want the initial bucket to have no cumulative power
	ring := validator.NewRing(nil, ringSize)
	// Load the IAVL state
	rs.Forest, err = getImmutable(startVersion)
	// Write the validator state at startVersion from IAVL tree into the ring's current bucket delta
	err = validator.Write(ring, rs)
	if err != nil {
		return nil, err
	}
	// Rotate, now we have [ {bucket 0: cum: {}, delta: {start version changes} }, {bucket 1: cum: {start version changes}, delta {}, ... ]
	// which is what we need (in particular we need this initial state if we are loading into a incompletely populated ring
	_, _, err = ring.Rotate()
	if err != nil {
		return nil, err
	}

	// Rebuild validator Ring
	for v := startVersion + 1; v <= version; v++ {
		// Update IAVL read state to version of interest
		rs.Forest, err = getImmutable(v)
		if err != nil {
			return nil, err
		}
		// Calculate the difference between the rings current cum and what is in state at this version
		diff, err := validator.Diff(ring.CurrentSet(), rs)
		if err != nil {
			return nil, err
		}
		// Write that diff into the ring (just like it was when it was originally written to setPower)
		err = validator.Write(ring, diff)
		if err != nil {
			return nil, err
		}
		// Rotate just like it was on the original commit
		_, _, err = ring.Rotate()
		if err != nil {
			return nil, err
		}
	}
	// Our ring should be the same up to symmetry in its index so we reindex to regain equality with the version we are loading
	// This is the head index we would have had if we had started from version 1 like the chain did
	ring.ReIndex(int(version % int64(ringSize)))
	return ring, err
}
26526
func (conf *rExecConf) validate() error {
	// Validate the filters
	if conf.node != "" {
		if _, err := regexp.Compile(conf.node); err != nil {
			return fmt.Errorf("Failed to compile node filter regexp: %v", err)
		}
	}
	if conf.service != "" {
		if _, err := regexp.Compile(conf.service); err != nil {
			return fmt.Errorf("Failed to compile service filter regexp: %v", err)
		}
	}
	if conf.tag != "" {
		if _, err := regexp.Compile(conf.tag); err != nil {
			return fmt.Errorf("Failed to compile tag filter regexp: %v", err)
		}
	}
	if conf.tag != "" && conf.service == "" {
		return fmt.Errorf("Cannot provide tag filter without service filter.")
	}
	return nil
}
839068
func ValidateNodeSelector(nodeSelector *core.NodeSelector, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}

	termFldPath := fldPath.Child("nodeSelectorTerms")
	if len(nodeSelector.NodeSelectorTerms) == 0 {
		return append(allErrs, field.Required(termFldPath, "must have at least one node selector term"))
	}

	for i, term := range nodeSelector.NodeSelectorTerms {
		allErrs = append(allErrs, ValidateNodeSelectorTerm(term, termFldPath.Index(i))...)
	}

	return allErrs
}
883548
func (c C) Ring3(val Input) Input {
	if v, ok := val.(C); ok {
		return C((c * v) * v)
	}
	return val.Ring3(c)
}
184320
func (as ArraySpec) Ring4(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.Ring4(val)
	})
}
301826
func Ring(r orb.Ring, proj orb.Projection) orb.Ring {
	return orb.Ring(LineString(orb.LineString(r), proj))
}
441097
func (d *DenyExec) ValidateInitialization() error {
	if d.client == nil {
		return fmt.Errorf("missing client")
	}
	return nil
}
694271
func (t *Tree) Init(c CompareFunc, flags byte) *Tree {
	t.compare = c
	t.root = nil
	t.treeFlags = flags
	return t
}
381795
func (a *addrBook) init() {
	a.key = crypto.CRandHex(24) // 24/2 * 8 = 96 bits
	// New addr buckets
	a.bucketsNew = make([]map[string]*knownAddress, newBucketCount)
	for i := range a.bucketsNew {
		a.bucketsNew[i] = make(map[string]*knownAddress)
	}
	// Old addr buckets
	a.bucketsOld = make([]map[string]*knownAddress, oldBucketCount)
	for i := range a.bucketsOld {
		a.bucketsOld[i] = make(map[string]*knownAddress)
	}
}
1246906
func (as ArraySpec) Ring3(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.Ring3(val)
	})
}
739393
func (f *WorkflowFactory) Init(_ *workflow.Manager, w *workflowpb.Workflow, args []string) error {
	// No parameters to parse.
	if len(args) > 0 {
		return fmt.Errorf("%v doesn't take any parameter", topoValidatorFactoryName)
	}
	w.Name = "Topology Validator"
	return nil
}
1048003
func (cm *containerManagerImpl) validateNodeAllocatable() error {
	var errors []string
	nar := cm.GetNodeAllocatableReservation()
	for k, v := range nar {
		value := cm.capacity[k].DeepCopy()
		value.Sub(v)

		if value.Sign() < 0 {
			errors = append(errors, fmt.Sprintf("Resource %q has an allocatable of %v, capacity of %v", k, v, value))
		}
	}

	if len(errors) > 0 {
		return fmt.Errorf("Invalid Node Allocatable configuration. %s", strings.Join(errors, " "))
	}
	return nil
}
833203
func (as ArraySpec) Ring1(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.Ring1(val)
	})
}
152399
func Ring(r orb.Ring, z maptile.Zoom) maptile.Set {
	if len(r) == 0 {
		return make(maptile.Set)
	}

	return Polygon(orb.Polygon{r}, z)
}
675732
func Init(m interface{}, factory Factory, globalTags map[string]string) error {
	// Allow user to opt out of reporting metrics by passing in nil.
	if factory == nil {
		factory = NullFactory
	}

	counterPtrType := reflect.TypeOf((*Counter)(nil)).Elem()
	gaugePtrType := reflect.TypeOf((*Gauge)(nil)).Elem()
	timerPtrType := reflect.TypeOf((*Timer)(nil)).Elem()
	histogramPtrType := reflect.TypeOf((*Histogram)(nil)).Elem()

	v := reflect.ValueOf(m).Elem()
	t := v.Type()
	for i := 0; i < t.NumField(); i++ {
		tags := make(map[string]string)
		for k, v := range globalTags {
			tags[k] = v
		}
		var buckets []float64
		field := t.Field(i)
		metric := field.Tag.Get("metric")
		if metric == "" {
			return fmt.Errorf("Field %s is missing a tag 'metric'", field.Name)
		}
		if tagString := field.Tag.Get("tags"); tagString != "" {
			tagPairs := strings.Split(tagString, ",")
			for _, tagPair := range tagPairs {
				tag := strings.Split(tagPair, "=")
				if len(tag) != 2 {
					return fmt.Errorf(
						"Field [%s]: Tag [%s] is not of the form key=value in 'tags' string [%s]",
						field.Name, tagPair, tagString)
				}
				tags[tag[0]] = tag[1]
			}
		}
		if bucketString := field.Tag.Get("buckets"); bucketString != "" {
			if field.Type.AssignableTo(timerPtrType) {
				// TODO: Parse timer duration buckets
				return fmt.Errorf(
					"Field [%s]: Buckets are not currently initialized for timer metrics",
					field.Name)
			} else if field.Type.AssignableTo(histogramPtrType) {
				bucketValues := strings.Split(bucketString, ",")
				for _, bucket := range bucketValues {
					b, err := strconv.ParseFloat(bucket, 64)
					if err != nil {
						return fmt.Errorf(
							"Field [%s]: Bucket [%s] could not be converted to float64 in 'buckets' string [%s]",
							field.Name, bucket, bucketString)
					}
					buckets = append(buckets, b)
				}
			} else {
				return fmt.Errorf(
					"Field [%s]: Buckets should only be defined for Timer and Histogram metric types",
					field.Name)
			}
		}
		help := field.Tag.Get("help")
		var obj interface{}
		if field.Type.AssignableTo(counterPtrType) {
			obj = factory.Counter(Options{
				Name: metric,
				Tags: tags,
				Help: help,
			})
		} else if field.Type.AssignableTo(gaugePtrType) {
			obj = factory.Gauge(Options{
				Name: metric,
				Tags: tags,
				Help: help,
			})
		} else if field.Type.AssignableTo(timerPtrType) {
			// TODO: Add buckets once parsed (see TODO above)
			obj = factory.Timer(TimerOptions{
				Name: metric,
				Tags: tags,
				Help: help,
			})
		} else if field.Type.AssignableTo(histogramPtrType) {
			obj = factory.Histogram(HistogramOptions{
				Name:    metric,
				Tags:    tags,
				Help:    help,
				Buckets: buckets,
			})
		} else {
			return fmt.Errorf(
				"Field %s is not a pointer to timer, gauge, or counter",
				field.Name)
		}
		v.Field(i).Set(reflect.ValueOf(obj))
	}
	return nil
}
682265
func (s *RadialSimplifier) Ring(r orb.Ring) orb.Ring {
	return ring(s, r)
}
1303485
func NewRingBuffer(
	capacity int,
	consolidateFunc MsgConsolidateFunc) *RingBuffer {
	return &RingBuffer{
		consolidateFunc: consolidateFunc,
		next:            0,
		msgs:            make([]Msg, capacity),
	}
}