github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/database/leveldb.chai2010/comparator.go (about) 1 // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package leveldb 6 7 // Comparator defines a total ordering over the space 8 // of []byte keys: a 'less than' relationship. 9 type Comparator interface { 10 // Three-way comparison. Returns value: 11 // < 0 if "a" < "b", 12 // == 0 if "a" == "b", 13 // > 0 if "a" > "b" 14 Compare(a, b []byte) int 15 16 // The name of the comparator. Used to check for comparator 17 // mismatches (i.e., a DB created with one comparator is 18 // accessed using a different comparator. 19 // 20 // The client of this package should switch to a new name whenever 21 // the comparator implementation changes in a way that will cause 22 // the relative ordering of any two keys to change. 23 // 24 // Names starting with "leveldb." are reserved and should not be used 25 // by any clients of this package. 26 Name() string 27 28 // Separator appends a sequence of bytes x to dst such that a <= x && x < b, 29 // where 'less than' is consistent with Compare. An implementation should 30 // return nil if x equal to a. 31 // 32 // Either contents of a or b should not by any means modified. Doing so 33 // may cause corruption on the internal state. 34 Separator(dst, a, b []byte) []byte 35 36 // Successor appends a sequence of bytes x to dst such that x >= b, where 37 // 'less than' is consistent with Compare. An implementation should return 38 // nil if x equal to b. 39 // 40 // Contents of b should not by any means modified. Doing so may cause 41 // corruption on the internal state. 42 Successor(dst, b []byte) []byte 43 }