1 // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
11 type bytesComparer struct{}
13 func (bytesComparer) Compare(a, b []byte) int {
14 return bytes.Compare(a, b)
17 func (bytesComparer) Name() string {
18 return "leveldb.BytewiseComparator"
21 func (bytesComparer) Separator(dst, a, b []byte) []byte {
26 for ; i < n && a[i] == b[i]; i++ {
29 // Do not shorten if one string is a prefix of the other
30 } else if c := a[i]; c < 0xff && c+1 < b[i] {
31 dst = append(dst, a[:i+1]...)
38 func (bytesComparer) Successor(dst, b []byte) []byte {
41 dst = append(dst, b[:i+1]...)
49 // DefaultComparer are default implementation of the Comparer interface.
50 // It uses the natural ordering, consistent with bytes.Compare.
51 var DefaultComparer = bytesComparer{}