本站源代码
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.

33 lines
766B

  1. // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. package util
  7. // Range is a key range.
  8. type Range struct {
  9. // Start of the key range, include in the range.
  10. Start []byte
  11. // Limit of the key range, not include in the range.
  12. Limit []byte
  13. }
  14. // BytesPrefix returns key range that satisfy the given prefix.
  15. // This only applicable for the standard 'bytes comparer'.
  16. func BytesPrefix(prefix []byte) *Range {
  17. var limit []byte
  18. for i := len(prefix) - 1; i >= 0; i-- {
  19. c := prefix[i]
  20. if c < 0xff {
  21. limit = make([]byte, i+1)
  22. copy(limit, prefix)
  23. limit[i] = c + 1
  24. break
  25. }
  26. }
  27. return &Range{prefix, limit}
  28. }
上海开阖软件有限公司 沪ICP备12045867号-1