github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/util/fst/bytesRefEnum.go (about)

     1  package fst
     2  
     3  import (
     4  	"github.com/balzaczyy/golucene/core/util"
     5  )
     6  
     7  type BytesRefFSTEnum struct {
     8  	*FSTEnum
     9  	current *util.BytesRef
    10  	result  *BytesRefFSTEnumIO
    11  	target  *util.BytesRef
    12  }
    13  
    14  /* Holds a single input ([]byte) + output pair. */
    15  type BytesRefFSTEnumIO struct {
    16  	Input  *util.BytesRef
    17  	Output interface{}
    18  }
    19  
    20  func NewBytesRefFSTEnum(fst *FST) *BytesRefFSTEnum {
    21  	ans := &BytesRefFSTEnum{
    22  		current: util.NewBytesRefFrom(make([]byte, 10)),
    23  		result:  new(BytesRefFSTEnumIO),
    24  	}
    25  	ans.FSTEnum = newFSTEnum(ans, fst)
    26  	ans.result.Input = ans.current
    27  	ans.current.Offset = 1
    28  	return ans
    29  }
    30  
    31  func (e *BytesRefFSTEnum) Next() (*BytesRefFSTEnumIO, error) {
    32  	if err := e.doNext(); err != nil {
    33  		return nil, err
    34  	}
    35  	return e.setResult(), nil
    36  }
    37  
    38  func (e *BytesRefFSTEnum) setCurrentLabel(label int) {
    39  	e.current.Bytes[e.upto] = byte(label)
    40  }
    41  
    42  func (e *BytesRefFSTEnum) grow() {
    43  	e.current.Bytes = util.GrowByteSlice(e.current.Bytes, e.upto+1)
    44  }
    45  
    46  func (e *BytesRefFSTEnum) setResult() *BytesRefFSTEnumIO {
    47  	if e.upto == 0 {
    48  		return nil
    49  	}
    50  	e.current.Length = e.upto - 1
    51  	e.result.Output = e.output[e.upto]
    52  	return e.result
    53  }