7#ifndef KUDU_UTIL_SLICE_H_
8#define KUDU_UTIL_SLICE_H_
22#ifdef KUDU_HEADERS_USE_RICH_SLICE
23#include "kudu/gutil/strings/fastmem.h"
24#include "kudu/gutil/strings/stringpiece.h"
25#include "kudu/util/faststring.h"
27#ifdef KUDU_HEADERS_NO_STUBS
28#include "kudu/gutil/port.h"
30#include "kudu/util/kudu_export.h"
54 Slice() : data_(reinterpret_cast<const uint8_t *>(
"")),
63 Slice(
const uint8_t* d,
size_t n) : data_(d), size_(n) { }
71 Slice(
const char* d,
size_t n) :
72 data_(reinterpret_cast<const uint8_t *>(d)),
80 data_(reinterpret_cast<const uint8_t *>(s.data())),
88 data_(reinterpret_cast<const uint8_t *>(s)),
91#ifdef KUDU_HEADERS_USE_RICH_SLICE
98 Slice(
const faststring &s)
107 Slice(
const StringPiece& s)
108 : data_(reinterpret_cast<const uint8_t*>(s.data())),
114 const uint8_t*
data()
const {
return data_; }
120 size_t size()
const {
return size_; }
123 bool empty()
const {
return size_ == 0; }
137 data_ =
reinterpret_cast<const uint8_t *
>(
"");
195 int compare(
const Slice& b)
const;
202 return ((size_ >= x.size_) &&
203 (MemEqual(data_, x.data_, x.size_)));
228 memcpy(d, data_, size_);
234 friend bool operator==(
const Slice& x,
const Slice& y);
236 static bool MemEqual(
const void* a,
const void* b,
size_t n) {
237#ifdef KUDU_HEADERS_USE_RICH_SLICE
238 return strings::memeq(a, b, n);
240 return memcmp(a, b, n) == 0;
244 static int MemCompare(
const void* a,
const void* b,
size_t n) {
245#ifdef KUDU_HEADERS_USE_RICH_SLICE
246 return strings::fastmemcmp_inlined(a, b, n);
248 return memcmp(a, b, n);
252 const uint8_t* data_;
277inline bool operator!=(
const Slice& x,
const Slice& y) {
288inline bool operator<(
const Slice& x,
const Slice& y) {
289 return x.compare(y) < 0;
299inline bool operator>(
const Slice& x,
const Slice& y) {
300 return x.compare(y) > 0;
310inline bool operator>=(
const Slice& x,
const Slice& y) {
311 return x.compare(y) >= 0;
321inline bool operator<=(
const Slice& x,
const Slice& y) {
322 return x.compare(y) <= 0;
332inline std::ostream& operator<<(std::ostream& o,
const Slice& s) {
333 return o << s.ToDebugString(16);
337 const size_t min_len = (size_ < b.size_) ? size_ : b.size_;
338 const int r = MemCompare(data_, b.data_, min_len);
342 if (size_ < b.size_) {
345 if (size_ > b.size_) {
354#ifdef KUDU_HEADERS_NO_STUBS
355ATTRIBUTE_NO_SANITIZE_THREAD
357bool IsAllZeros(
const Slice& s);
377 typedef std::map<Slice, T, Slice::Comparator>
type;
A wrapper around externally allocated data.
Definition slice.h:51
void remove_prefix(size_t n)
Definition slice.h:150
std::string ToString() const
bool empty() const
Definition slice.h:123
Slice(const std::string &s)
Definition slice.h:79
void truncate(size_t n)
Definition slice.h:165
uint8_t * mutable_data()
Definition slice.h:117
Status check_size(size_t expected_size) const
void relocate(uint8_t *d)
Definition slice.h:226
const uint8_t * data() const
Definition slice.h:114
const uint8_t & operator[](size_t n) const
Definition slice.h:130
int compare(const Slice &b) const
Definition slice.h:336
Slice(const uint8_t *d, size_t n)
Definition slice.h:63
Slice(const char *d, size_t n)
Definition slice.h:71
Slice()
Create an empty slice.
Definition slice.h:54
bool starts_with(const Slice &x) const
Definition slice.h:201
std::string ToDebugString(size_t max_len=0) const
Slice(const char *s)
Definition slice.h:87
size_t size() const
Definition slice.h:120
void clear()
Change this slice to refer to an empty array.
Definition slice.h:136
A representation of an operation's outcome.
Definition status.h:165
STL map whose keys are Slices.
Definition slice.h:375
std::map< Slice, T, Slice::Comparator > type
A handy typedef for the slice map with appropriate comparison operator.
Definition slice.h:377
Comparator struct, useful for ordered collections (like STL maps).
Definition slice.h:207
bool operator()(const Slice &a, const Slice &b) const
Definition slice.h:215