/*
Inverts one field for one document; first is true if this is the
first time we are seeing this field name in this document.
*/
546070
func (f *PerField) invert(field IndexableField, first bool) error {
	if first {
		// first time we're seeing this field (indexed) in this document:
		f.invertState.reset()
	}

	fieldType := field.FieldType()

	analyzed := fieldType.Tokenized() && f.docState.analyzer != nil

	if err := func() (err error) {
		// only bother checking offsets if something will consume them
		// TODO: after we fix analyzers, also check if termVectorOffsets will be indexed.
		checkOffsets := fieldType.IndexOptions() == INDEX_OPT_DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS

		// To assist people in tracking down problems in analysis components,
		// we wish to write the field name to the infostream when we fail.
		// We expect some caller to eventually deal with the real error, so
		// we don't want any error handling, but rather a deferred function
		// that takes note of the problem.
		aborting := false
		succeededInProcessingField := false
		defer func() {
			if err != nil {
				if _, ok := err.(util.MaxBytesLengthExceededError); ok {
					aborting = false
					prefix := make([]byte, 30)
					bigTerm := f.invertState.termAttribute.BytesRef()
					copy(prefix, bigTerm.ToBytes()[:30]) // keep at most 30 characters
					if f.docState.infoStream.IsEnabled("IW") {
						f.docState.infoStream.Message("IW",
							"ERROR: Document contains at least one immense term in field='%v' "+
								"(whose UTF8 encoding is longer than the max length %v), "+
								"all of which were skipped. Please correct the analyzer to not produce such terms. "+
								"The prefix of the first immense term is: '%v...', original message: %v",
							f.fieldInfo.Name, MAX_TERM_LENGTH_UTF8, string(prefix), err)
					}
				}
			}
			if !succeededInProcessingField && aborting {
				f.docState.docWriter.setAborting()
			}

			if !succeededInProcessingField && f.docState.infoStream.IsEnabled("DW") {
				f.docState.infoStream.Message("DW",
					"An error was returned while processing field %v",
					f.fieldInfo.Name)
			}
		}()

		var stream analysis.TokenStream
		stream, err = field.TokenStream(f.docState.analyzer, f.tokenStream)
		if err != nil {
			return err
		}
		defer stream.Close()

		f.tokenStream = stream
		// reset the TokenStream to the first token
		if err = stream.Reset(); err != nil {
			return err
		}

		f.invertState.setAttributeSource(stream.Attributes())

		f.termsHashPerField.start(field, first)

		for {
			var ok bool
			if ok, err = stream.IncrementToken(); err != nil {
				return err
			}
			if !ok {
				break
			}

			// if we hit an error in stream.next below (which is fairly
			// common, e.g. if analyzer chokes on a given document), then
			// it's non-aborting and (above) this one document will be
			// marked as deleted, but still consume a docId

			posIncr := f.invertState.posIncrAttribute.PositionIncrement()
			if f.invertState.position += posIncr; f.invertState.position < f.invertState.lastPosition {
				assert2(posIncr != 0,
					"first position increment must be > 0 (got 0) for field '%v'",
					field.Name)
				panic(fmt.Sprintf(
					"position increments (and gaps) must be >= 0 (got %v) for field '%v'",
					posIncr, field.Name))
			}
			f.invertState.lastPosition = f.invertState.position
			if posIncr == 0 {
				f.invertState.numOverlap++
			}

			if checkOffsets {
				startOffset := f.invertState.offset + f.invertState.offsetAttribute.StartOffset()
				endOffset := f.invertState.offset + f.invertState.offsetAttribute.EndOffset()
				assert2(startOffset >= f.invertState.lastStartOffset && startOffset <= endOffset,
					"startOffset must be non-negative, "+
						"and endOffset must be >= startOffset, "+
						"and offsets must not go backwards "+
						"startOffset=%v,endOffset=%v,lastStartOffset=%v for field '%v'",
					startOffset, endOffset, f.invertState.lastStartOffset, field.Name)
				f.invertState.lastStartOffset = startOffset
			}

			// fmt.Printf("  term=%v\n", f.invertState.termAttribute)

			// if we hit an error in here, we abort all buffered documents
			// since the last flush, on the likelihood that the internal
			// state of the terms hash is now corrupt and should not be
			// flushed to a new segment:
			aborting = true
			if err = f.termsHashPerField.add(); err != nil {
				return err
			}
			aborting = false

			f.invertState.length++
		}

		// trigger streams to perform end-of-stream operations
		if err = stream.End(); err != nil {
			return err
		}

		// TODO: maybe add some safety? then again, it's already checked
		// when we come back arond to the field...
		f.invertState.position += f.invertState.posIncrAttribute.PositionIncrement()
		f.invertState.offset += f.invertState.offsetAttribute.EndOffset()

		// if there is an error coming through, we don't set this to true here:
		succeededInProcessingField = true
		return nil
	}(); err != nil {
		return err
	}

	if analyzed {
		f.invertState.position += f.docState.analyzer.PositionIncrementGap(f.fieldInfo.Name)
		f.invertState.offset += f.docState.analyzer.OffsetGap(f.fieldInfo.Name)
	}

	f.invertState.boost *= field.Boost()
	return nil
}
1115364
func (document Document) Field(field string) interface{} {
	r, _ := document.Fields[field]
	return r
}
1288343
func (t *kutenTable) Reverse() {
	t.once.Do(func() {
		t.FromUnicode = make([][2]byte, 65536)
		for ku := range t.Data {
			for ten, unicode := range t.Data[ku] {
				t.FromUnicode[unicode] = [2]byte{byte(ku), byte(ten)}
			}
		}
	})
}
824892
func (f *Field) init() error {
	if f.initialized {
		return nil
	}

	_, oidNum, oidText, conversion, err := snmpTranslate(f.Oid)
	if err != nil {
		return Errorf(err, "translating")
	}
	f.Oid = oidNum
	if f.Name == "" {
		f.Name = oidText
	}
	if f.Conversion == "" {
		f.Conversion = conversion
	}

	//TODO use textual convention conversion from the MIB

	f.initialized = true
	return nil
}
504023
func (doc PluginDocument) GetRST() string {
	result := ""

	// Print top comment
	result += ".. Autogenerated by Gollum RST generator (docs/generator/*.go)\n\n"

	// Print heading
	result += doc.PluginName + "\n"
	result += strings.Repeat("=", len(doc.PluginName)) + "\n"

	// Print description
	result += "\n"
	result += docBulletsToRstBullets(doc.Description) + "\n"
	result += "\n"

	// Print native metadata
	if len(doc.Metadata.slice) > 0 {
		result += formatRstHeading("Metadata")
		result += doc.Metadata.getRST(false, 0)
	}

	// Print inherited metadata
	for _, parentName := range sortInheritedKeys(doc.InheritedMetadata) {
		if len(doc.InheritedMetadata[parentName].slice) == 0 {
			// Skip title for empty sets
			continue
		}
		result += formatRstHeading(
			"Metadata (from " + /* strings.TrimPrefix(*/ parentName /*, "core.") */ + ")")

		result += doc.InheritedMetadata[parentName].getRST(false, 0)
	}

	// Print native parameters
	if len(doc.Parameters.slice) > 0 {
		result += formatRstHeading("Parameters")
		result += doc.Parameters.getRST(true, 0)
	}

	// Print inherited parameters
	for _, parentName := range sortInheritedKeys(doc.InheritedParameters) {
		if len(doc.InheritedParameters[parentName].slice) == 0 {
			// Skip title for empty param sets
			continue
		}
		result += formatRstHeading(
			"Parameters (from " + /* strings.TrimPrefix(*/ parentName /*, "core.") */ + ")")
		result += doc.InheritedParameters[parentName].getRST(true, 0)
	}

	// Print config example
	if len(doc.Example) > 0 {
		result += formatRstHeading("Examples")
		codeBlock := false

		for _, line := range strings.Split(doc.Example, "\n") {

			if strings.Index(line, " ") == 0 {
				if !codeBlock {
					result += ".. code-block:: yaml\n\n"
					codeBlock = true
				}
			} else {
				if codeBlock {
					result += "\n"
					codeBlock = false
				}
			}

			if codeBlock {
				result += "\t" + line + "\n"
			} else {
				result += line + "\n"
			}
		}
	}

	return result
}
1131963
func fieldNameMapping(obj interface{}) map[string]string {
	st := reflect.TypeOf(obj)
	fl := st.NumField()

	jsonToForce := make(map[string]string, fl)

	for i := 0; i < fl; i++ {
		sf := st.Field(i)
		jName := strings.SplitN(sf.Tag.Get("json"), ",", 2)[0]
		fName := strings.SplitN(sf.Tag.Get("force"), ",", 2)[0]

		if jName == "-" {
			continue
		}

		if fName == "-" {
			continue
		}

		if jName == "" {
			jName = sf.Name
		}

		if fName == "" {
			fName = sf.Name
		}

		jsonToForce[jName] = fName
	}

	for k, v := range baseFieldNameMap {
		jsonToForce[k] = v
	}

	return jsonToForce
}
1114552
func Invert(src image.Image) *image.RGBA {
	fn := func(c color.RGBA) color.RGBA {
		return color.RGBA{255 - c.R, 255 - c.G, 255 - c.B, c.A}
	}

	img := adjust.Apply(src, fn)

	return img
}
1323406
func (self *list) Reverse() List {
	reversed := NewList()
	self.ForEach(func(v interface{}) { reversed = reversed.Cons(v) })
	return reversed
}
300008
func (t *TagSet) Reverse() {
	for i, j := 0, len(t.Filters)-1; i < j; i, j = i+1, j-1 {
		t.Filters[i], t.Filters[j] = t.Filters[j], t.Filters[i]
		t.SeriesKeys[i], t.SeriesKeys[j] = t.SeriesKeys[j], t.SeriesKeys[i]
	}
}
285713
func (vec *T) Invert() *T {
	vec[0] = -vec[0]
	vec[1] = -vec[1]
	vec[2] = -vec[2]
	return vec
}
223751
func HiddenFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string) *Field {
	ret := HiddenField(name)
	ret.SetValue(fmt.Sprintf("%v", val.Field(fieldNo).Interface()))
	return ret
}
506172
func (s Style) Reverse(on bool) Style {
	return s.setAttrs(Style(AttrReverse), on)
}
658700
func (options *Options) Inverse() string {
	result := ""
	if block := options.eval.curBlock(); (block != nil) && (block.Inverse != nil) {
		result, _ = block.Inverse.Accept(options.eval).(string)
	}

	return result
}
1036000
func (p *Polyline) Reverse() {
	for i := 0; i < len(*p)/2; i++ {
		(*p)[i], (*p)[len(*p)-i-1] = (*p)[len(*p)-i-1], (*p)[i]
	}
}
597778
func (m matrix) Invert() (matrix, error) {
	if !m.IsSquare() {
		return nil, errNotSquare
	}

	size := len(m)
	work, _ := identityMatrix(size)
	work, _ = m.Augment(work)

	err := work.gaussianElimination()
	if err != nil {
		return nil, err
	}

	return work.SubMatrix(0, size, size, size*2)
}
847188
func (dc *Context) InvertY() {
	dc.Translate(0, float64(dc.height))
	dc.Scale(1, -1)
}
330348
func (s *UpdateHealthCheckInput) SetInverted(v bool) *UpdateHealthCheckInput {
	s.Inverted = &v
	return s
}