2019-04-19 04:43:36 +00:00
|
|
|
package needle_map
|
2017-05-27 05:51:25 +00:00
|
|
|
|
|
|
|
import (
|
2018-07-08 09:28:04 +00:00
|
|
|
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
2019-05-19 05:46:24 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2018-07-22 00:39:10 +00:00
|
|
|
"github.com/google/btree"
|
2017-05-27 05:51:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type NeedleValue struct {
|
2018-07-08 09:28:04 +00:00
|
|
|
Key NeedleId
|
|
|
|
Offset Offset `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G
|
2020-08-19 00:04:28 +00:00
|
|
|
Size Size `comment:"Size of the data portion"`
|
2017-05-27 05:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this NeedleValue) Less(than btree.Item) bool {
|
|
|
|
that := than.(NeedleValue)
|
|
|
|
return this.Key < that.Key
|
|
|
|
}
|
2019-05-19 05:46:24 +00:00
|
|
|
|
|
|
|
func (nv NeedleValue) ToBytes() []byte {
|
|
|
|
return ToBytes(nv.Key, nv.Offset, nv.Size)
|
|
|
|
}
|
|
|
|
|
2020-08-19 00:04:28 +00:00
|
|
|
func ToBytes(key NeedleId, offset Offset, size Size) []byte {
|
2019-05-19 05:46:24 +00:00
|
|
|
bytes := make([]byte, NeedleIdSize+OffsetSize+SizeSize)
|
|
|
|
NeedleIdToBytes(bytes[0:NeedleIdSize], key)
|
|
|
|
OffsetToBytes(bytes[NeedleIdSize:NeedleIdSize+OffsetSize], offset)
|
2020-08-19 00:04:28 +00:00
|
|
|
util.Uint32toBytes(bytes[NeedleIdSize+OffsetSize:NeedleIdSize+OffsetSize+SizeSize], uint32(size))
|
2019-05-19 05:46:24 +00:00
|
|
|
return bytes
|
|
|
|
}
|