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