Ejemplo n.º 1
0
/* Create a new ForUtil instance and save state into out. */
func NewForUtilInto(accetableOverheadRatio float32, out util.DataOutput) (*ForUtil, error) {
	ans, err := &ForUtil{}, out.WriteVInt(packed.VERSION_CURRENT)
	if err != nil {
		return ans, err
	}
	ans.encodedSizes = make([]int32, 33)
	ans.encoders = make([]packed.PackedIntsEncoder, 33)
	ans.decoders = make([]packed.PackedIntsDecoder, 33)
	ans.iterations = make([]int32, 33)

	packedIntsVersion := int32(packed.VERSION_CURRENT)
	for bpv := 1; bpv <= 32; bpv++ {
		formatAndBits := packed.FastestFormatAndBits(
			LUCENE41_BLOCK_SIZE, bpv, accetableOverheadRatio)
		format := formatAndBits.Format
		bitsPerValue := formatAndBits.BitsPerValue
		assert(format.IsSupported(bitsPerValue))
		assert(bitsPerValue <= 32)
		ans.encodedSizes[bpv] = encodedSize(format, packedIntsVersion, uint32(bitsPerValue))
		ans.encoders[bpv] = packed.GetPackedIntsEncoder(format, packedIntsVersion, uint32(bitsPerValue))
		ans.decoders[bpv] = packed.GetPackedIntsDecoder(format, packedIntsVersion, uint32(bitsPerValue))
		ans.iterations[bpv] = computeIterations(ans.decoders[bpv])

		err = out.WriteVInt(int32(format.Id()<<5 | (bitsPerValue - 1)))
		if err != nil {
			return ans, err
		}
	}
	return ans, err
}
Ejemplo n.º 2
0
/* Writes all of our bytes to the target DataOutput. */
func (s *BytesStore) writeTo(out util.DataOutput) error {
	for _, block := range s.blocks {
		err := out.WriteBytes(block)
		if err != nil {
			return err
		}
	}
	return nil
}
Ejemplo n.º 3
0
func (w *Lucene41PostingsWriter) EncodeTerm(longs []int64,
	out util.DataOutput, fieldInfo *FieldInfo, _state *BlockTermState,
	absolute bool) (err error) {

	assert(longs != nil)
	assert(len(longs) > 0)
	state := _state.Self.(*intBlockTermState)
	if absolute {
		w.lastState = emptyState
	}
	longs[0] = state.docStartFP - w.lastState.docStartFP
	if w.fieldHasPositions {
		longs[1] = state.posStartFP - w.lastState.posStartFP
		if w.fieldHasPayloads || w.fieldHasOffsets {
			longs[2] = state.payStartFP - w.lastState.payStartFP
		}
	}
	if state.singletonDocID != -1 {
		if err = out.WriteVInt(int32(state.singletonDocID)); err != nil {
			return
		}
	}
	if w.fieldHasPositions && state.lastPosBlockOffset != -1 {
		if err = out.WriteVLong(state.lastPosBlockOffset); err != nil {
			return
		}
	}
	if state.skipOffset != -1 {
		if err = out.WriteVLong(state.skipOffset); err != nil {
			return
		}
	}
	w.lastState = state
	return nil
}
Ejemplo n.º 4
0
/* Copy the current contents of this buffer to the named output. */
func (out *RAMOutputStream) WriteTo(output util.DataOutput) error {
	err := out.Flush()
	if err != nil {
		return err
	}
	end := out.file.length
	pos := int64(0)
	buffer := 0
	for pos < end {
		length := BUFFER_SIZE
		nextPos := pos + int64(length)
		if nextPos > end { // at the last buffer
			length = int(end - pos)
		}
		err = output.WriteBytes(out.file.Buffer(buffer)[:length])
		if err != nil {
			return err
		}
		buffer++
		pos = nextPos
	}
	return nil
}