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.

45 lines
829 B

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package db
  2. import (
  3. "bytes"
  4. )
  5. func cp(bz []byte) (ret []byte) {
  6. ret = make([]byte, len(bz))
  7. copy(ret, bz)
  8. return ret
  9. }
  10. // Returns a slice of the same length (big endian)
  11. // except incremented by one.
  12. // Returns nil on overflow (e.g. if bz bytes are all 0xFF)
  13. // CONTRACT: len(bz) > 0
  14. func cpIncr(bz []byte) (ret []byte) {
  15. if len(bz) == 0 {
  16. panic("cpIncr expects non-zero bz length")
  17. }
  18. ret = cp(bz)
  19. for i := len(bz) - 1; i >= 0; i-- {
  20. if ret[i] < byte(0xFF) {
  21. ret[i]++
  22. return
  23. }
  24. ret[i] = byte(0x00)
  25. if i == 0 {
  26. // Overflow
  27. return nil
  28. }
  29. }
  30. return nil
  31. }
  32. // See DB interface documentation for more information.
  33. func IsKeyInDomain(key, start, end []byte) bool {
  34. if bytes.Compare(key, start) < 0 {
  35. return false
  36. }
  37. if end != nil && bytes.Compare(end, key) <= 0 {
  38. return false
  39. }
  40. return true
  41. }