0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
QualifiedRangeSpec.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, or any later version.
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 
28 
29 #ifndef Hypertable_Lib_QualifiedRangeSpec_h
30 #define Hypertable_Lib_QualifiedRangeSpec_h
31 
35 
36 #include <Common/ByteString.h>
37 #include <Common/MurmurHash.h>
39 #include <Common/String.h>
40 #include <Common/Serializable.h>
41 
42 #include <cassert>
43 #include <utility>
44 #include <vector>
45 
46 namespace Hypertable {
47 
50 
53  public:
55  : table(tid), range(rs) {}
58  table.id = arena.dup(other.table.id);
59  range.start_row = arena.dup(other.range.start_row);
60  range.end_row = arena.dup(other.range.end_row);
61  }
63  virtual ~QualifiedRangeSpec() { }
64 
65  virtual bool operator<(const QualifiedRangeSpec &other) const;
66  virtual bool operator==(const QualifiedRangeSpec &other) const;
67  virtual bool is_root() const;
68 
71 
72  protected:
73 
76  uint8_t encoding_version() const override;
77 
80 
82  size_t encoded_length_internal() const override;
83 
86  void encode_internal(uint8_t **bufp) const override;
87 
94  void decode_internal(uint8_t version, const uint8_t **bufp,
95  size_t *remainp) override;
96 
97  };
98 
101  public:
106  set_table_id(table);
107  set_range_spec(range);
108  }
109 
111 
113  const QualifiedRangeSpec *otherp = &other;
114  return operator=(*otherp);
115  }
116 
118  m_range = other.range;
119  range = m_range;
120  m_table = other.table;
121  table = m_table;
122  return *this;
123  }
124 
125  void set_range_spec(const RangeSpec &rs) {
126  m_range = rs;
127  range = m_range;
128  }
129 
130  void set_table_id(const TableIdentifier &tid) {
131  m_table = tid;
132  table = m_table;
133  }
134 
135  bool operator<(const QualifiedRangeSpecManaged &other) const;
136 
137  friend std::ostream &operator<<(std::ostream &os,
138  const QualifiedRangeSpecManaged &qualified_range);
139 
140  private:
141 
148  void decode_internal(uint8_t version, const uint8_t **bufp,
149  size_t *remainp) override;
150 
153  };
154 
155 
158  const QualifiedRangeSpecManaged *qr2) {
159  if (qr1)
160  return ((*qr1) < *qr2);
161  else
162  return false;
163  }
164  };
165 
167  public:
168  size_t operator()(const QualifiedRangeSpec &spec) const {
169  return murmurhash2(spec.range.start_row, strlen(spec.range.start_row),
171  strlen(spec.range.end_row), 0));
172  }
173  };
174 
176  bool
178  return !strcmp(x.table.id, y.table.id) &&
179  !strcmp(x.range.start_row, y.range.start_row) &&
180  !strcmp(x.range.end_row, y.range.end_row);
181  }
182  };
183 
184  std::ostream &operator<<(std::ostream &os, const QualifiedRangeSpec &qualified_range);
185 
186  std::ostream &operator<<(std::ostream &os, const QualifiedRangeSpecManaged &qualified_range);
187 
189 
190 }
191 
192 
193 #endif // Hypertable_Lib_QualifiedRangeSpec_h
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
QualifiedRangeSpecManaged(const TableIdentifier &table, const RangeSpec &range)
bool operator<(const QualifiedRangeSpecManaged &other) const
bool operator()(const QualifiedRangeSpecManaged *qr1, const QualifiedRangeSpecManaged *qr2)
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Qualified (with table identifier) range specification, with storage.
Range specification.
Definition: RangeSpec.h:40
MurmurHash2 digest routine.
QualifiedRangeSpecManaged(const QualifiedRangeSpecManaged &other)
uint32_t murmurhash2(const void *key, size_t len, uint32_t seed)
The murmurhash2 implementation.
Definition: MurmurHash.cc:29
Declarations for TableIdentifier and TableIdentifierManaged.
void set_table_id(const TableIdentifier &tid)
PageArena memory allocator for STL classes.
size_t operator()(const QualifiedRangeSpec &spec) const
virtual bool operator==(const QualifiedRangeSpec &other) const
Wrapper for TableIdentifier providing member storage.
CharT * dup(const CharT *s)
Duplicate a null terminated string; memory is allocated from the pool.
Definition: PageArena.h:274
uint8_t encoding_version() const override
Returns encoding version.
const char * end_row
Definition: RangeSpec.h:60
Declarations for RangeState.
size_t encoded_length_internal() const override
Returns internal serialized length.
friend std::ostream & operator<<(std::ostream &os, const QualifiedRangeSpecManaged &qualified_range)
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
The PageArena allocator is simple and fast, avoiding individual mallocs/frees.
Definition: PageArena.h:69
QualifiedRangeSpecManaged(const QualifiedRangeSpec &other)
QualifiedRangeSpec(CharArena &arena, const QualifiedRangeSpec &other)
QualifiedRangeSpec(const TableIdentifier &tid, const RangeSpec &rs)
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Declarations for RangeSpec and RangeSpecManaged.
Declarations for Serializable.
bool operator()(const QualifiedRangeSpec &x, const QualifiedRangeSpec &y) const
Hypertable definitions
const char * start_row
Definition: RangeSpec.h:59
Mixin class that provides a standard serialization interface.
Definition: Serializable.h:65
void set_range_spec(const RangeSpec &rs)
A String class based on std::string.
A serializable ByteString.
Qualified (with table identifier) range specification.
QualifiedRangeSpecManaged & operator=(const QualifiedRangeSpec &other)
QualifiedRangeSpecManaged & operator=(const QualifiedRangeSpecManaged &other)
virtual bool operator<(const QualifiedRangeSpec &other) const
Wrapper for RangeSpec providing member storage.
Definition: RangeSpec.h:89