0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SerializedKey.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef HYPERTABLE_SERIALIZEDKEY_H
23 #define HYPERTABLE_SERIALIZEDKEY_H
24 
25 #include "Common/ByteString.h"
26 #include "Common/Logger.h"
27 
28 namespace Hypertable {
29 
30  class SerializedKey : public ByteString {
31  public:
33  SerializedKey(const uint8_t *buf) : ByteString(buf) { }
35 
36  int compare(const SerializedKey sk) const {
37  const uint8_t *ptr1, *ptr2;
38  int len1 = decode_length(&ptr1);
39  int len2 = sk.decode_length(&ptr2);
40 
41  if (*ptr1 != *ptr2) {
42  // see Key.h
43  if (*ptr1 >= 0x80 && *ptr1 != 0xD0)
44  len1 -= 8;
45  if (*ptr2 >= 0x80 && *ptr2 != 0xD0)
46  len2 -= 8;
47  }
48  int len = (len1 < len2) ? len1 : len2;
49  int cmp = memcmp(ptr1+1, ptr2+1, len-1);
50  return (cmp==0) ? len1 - len2 : cmp;
51  }
52 
53  const char *row() const {
54  const uint8_t *rptr = ptr;
56  return (const char *)rptr+1;
57  }
58  };
59 
60  inline bool operator==(const SerializedKey sk1, const SerializedKey sk2) {
61  return sk1.compare(sk2) == 0;
62  }
63 
64  inline bool operator!=(const SerializedKey sk1, const SerializedKey sk2) {
65  return sk1.compare(sk2) != 0;
66  }
67 
68  inline bool operator<(const SerializedKey sk1, const SerializedKey sk2) {
69  return sk1.compare(sk2) < 0;
70  }
71 
72  inline bool operator<=(const SerializedKey sk1, const SerializedKey sk2) {
73  return sk1.compare(sk2) <= 0;
74  }
75 
76  inline bool operator>(const SerializedKey sk1, const SerializedKey sk2) {
77  return sk1.compare(sk2) > 0;
78  }
79 
80  inline bool operator>=(const SerializedKey sk1, const SerializedKey sk2) {
81  return sk1.compare(sk2) >= 0;
82  }
83 
84 
85 }
86 
87 #endif // HYPERTABLE_SERIALIZEDKEY_H
bool operator<=(const directory< _Key, _Tp, _Compare, _Allocator > &__x, const directory< _Key, _Tp, _Compare, _Allocator > &__y)
Definition: directory.h:868
const char * row() const
Definition: SerializedKey.h:53
SerializedKey(const uint8_t *buf)
Definition: SerializedKey.h:33
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
Logging routines and macros.
bool operator==(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
Definition: directory.h:112
int compare(const SerializedKey sk) const
Definition: SerializedKey.h:36
bool operator!=(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
Definition: directory.h:122
const uint8_t * ptr
The pointer to the serialized data.
Definition: ByteString.h:121
bool operator<(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
Definition: directory.h:128
Hypertable definitions
bool operator>=(const directory< _Key, _Tp, _Compare, _Allocator > &__x, const directory< _Key, _Tp, _Compare, _Allocator > &__y)
Definition: directory.h:860
size_t decode_length(const uint8_t **dptr) const
Retrieves the decoded length and returns a pointer to the string.
Definition: ByteString.h:83
A serializable ByteString.
SerializedKey(ByteString bs)
Definition: SerializedKey.h:34
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
bool operator>(const directory< _Key, _Tp, _Compare, _Allocator > &__x, const directory< _Key, _Tp, _Compare, _Allocator > &__y)
Definition: directory.h:852