You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
884 B

6 years ago
7 years ago
  1. package needle_map
  2. import (
  3. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "github.com/google/btree"
  6. )
  7. type NeedleValue struct {
  8. Key NeedleId
  9. Offset Offset `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G
  10. Size uint32 `comment:"Size of the data portion"`
  11. }
  12. func (this NeedleValue) Less(than btree.Item) bool {
  13. that := than.(NeedleValue)
  14. return this.Key < that.Key
  15. }
  16. func (nv NeedleValue) ToBytes() []byte {
  17. return ToBytes(nv.Key, nv.Offset, nv.Size)
  18. }
  19. func ToBytes(key NeedleId, offset Offset, size uint32) []byte {
  20. bytes := make([]byte, NeedleIdSize+OffsetSize+SizeSize)
  21. NeedleIdToBytes(bytes[0:NeedleIdSize], key)
  22. OffsetToBytes(bytes[NeedleIdSize:NeedleIdSize+OffsetSize], offset)
  23. util.Uint32toBytes(bytes[NeedleIdSize+OffsetSize:NeedleIdSize+OffsetSize+SizeSize], size)
  24. return bytes
  25. }