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

     1  package packed
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/balzaczyy/golucene/core/util"
     6  	"math"
     7  )
     8  
     9  var PACKED8_THREE_BLOCKS_MAX_SIZE = int32(math.MaxInt32 / 3)
    10  
    11  type Packed8ThreeBlocks struct {
    12  	*MutableImpl
    13  	blocks []byte
    14  }
    15  
    16  func newPacked8ThreeBlocks(valueCount int32) *Packed8ThreeBlocks {
    17  	assert2(valueCount <= PACKED8_THREE_BLOCKS_MAX_SIZE, "MAX_SIZE exceeded")
    18  	ans := &Packed8ThreeBlocks{blocks: make([]byte, valueCount*3)}
    19  	ans.MutableImpl = newMutableImpl(ans, int(valueCount), 24)
    20  	return ans
    21  }
    22  
    23  func newPacked8ThreeBlocksFromInput(version int32, in DataInput, valueCount int32) (r PackedIntsReader, err error) {
    24  	ans := newPacked8ThreeBlocks(valueCount)
    25  	if err = in.ReadBytes(ans.blocks); err == nil {
    26  		// because packed ints have not always been byte-aligned
    27  		remaining := PackedFormat(PACKED).ByteCount(version, valueCount, 24) - 3*int64(valueCount)
    28  		for i := int64(0); i < remaining; i++ {
    29  			if _, err = in.ReadByte(); err != nil {
    30  				break
    31  			}
    32  		}
    33  	}
    34  	return ans, err
    35  }
    36  
    37  func (r *Packed8ThreeBlocks) Get(index int) int64 {
    38  	o := index * 3
    39  	return int64(r.blocks[o])<<16 | int64(r.blocks[o+1])<<8 | int64(r.blocks[o+2])
    40  }
    41  
    42  func (r *Packed8ThreeBlocks) getBulk(index int, arr []int64) int {
    43  	panic("niy")
    44  }
    45  
    46  func (r *Packed8ThreeBlocks) Set(index int, value int64) {
    47  	panic("not implemented yet")
    48  }
    49  
    50  func (r *Packed8ThreeBlocks) setBulk(idnex int, arr []int64) int {
    51  	panic("niy")
    52  }
    53  
    54  func (r *Packed8ThreeBlocks) fill(from, to int, val int64) {
    55  	panic("niy")
    56  }
    57  
    58  func (r *Packed8ThreeBlocks) Clear() {
    59  	panic("niy")
    60  }
    61  
    62  func (r *Packed8ThreeBlocks) RamBytesUsed() int64 {
    63  	return util.AlignObjectSize(
    64  		util.NUM_BYTES_OBJECT_HEADER +
    65  			2*util.NUM_BYTES_INT +
    66  			util.NUM_BYTES_OBJECT_REF +
    67  			util.SizeOf(r.blocks))
    68  }
    69  
    70  func (r *Packed8ThreeBlocks) String() string {
    71  	return fmt.Sprintf("Packed8ThreeBlocks(bitsPerValue=%v, size=%v, elements.length=%v)",
    72  		r.bitsPerValue, r.Size(), len(r.blocks))
    73  }