Kudu C++ client API
|
A wrapper around externally allocated data. More...
#include <slice.h>
Classes | |
struct | Comparator |
Comparator struct, useful for ordered collections (like STL maps). More... | |
Public Member Functions | |
Slice () | |
Create an empty slice. | |
Slice (const uint8_t *d, size_t n) | |
Slice (const char *d, size_t n) | |
Slice (const std::string &s) | |
Slice (const char *s) | |
const uint8_t * | data () const |
uint8_t * | mutable_data () |
size_t | size () const |
bool | empty () const |
const uint8_t & | operator[] (size_t n) const |
void | clear () |
Change this slice to refer to an empty array. | |
void | remove_prefix (size_t n) |
void | truncate (size_t n) |
Status | check_size (size_t expected_size) const |
std::string | ToString () const |
std::string | ToDebugString (size_t max_len=0) const |
int | compare (const Slice &b) const |
bool | starts_with (const Slice &x) const |
void | relocate (uint8_t *d) |
Friends | |
bool | operator== (const Slice &x, const Slice &y) |
A wrapper around externally allocated data.
Slice is a simple structure containing a pointer into some external storage and a size. The user of a Slice must ensure that the slice is not used after the corresponding external storage has been deallocated.
Multiple threads can invoke const methods on a Slice without external synchronization, but if any of the threads may call a non-const method, all threads accessing the same Slice must use external synchronization.
Slices can be built around faststrings and StringPieces using constructors with implicit casts. Both StringPieces and faststrings depend on a great deal of gutil code.
|
inline |
Create a slice that refers to a uint8_t
byte array.
[in] | d | The input array. |
[in] | n | Number of bytes in the array. |
|
inline |
Create a slice that refers to a char
byte array.
[in] | d | The input array. |
[in] | n | Number of bytes in the array. |
|
inline |
Create a slice that refers to the contents of the given string.
[in] | s | The input string. |
|
inline |
Create a slice that refers to a C-string s[0,strlen(s)-1].
[in] | s | The input C-string. |
Status kudu::Slice::check_size | ( | size_t | expected_size | ) | const |
Check that the slice has the expected size.
[in] | expected_size |
expected_size
|
inline |
Do a three-way comparison of the slice's data.
[in] | b | The other slice to compare with. |
|
inline |
|
inline |
true
iff the length of the referenced data is zero.
|
inline |
|
inline |
[in] | n | The index of the byte. |
|
inline |
Relocate/copy the slice's data into a new location.
[in] | d | The new location for the data. If it's the same location, then no relocation is done. It is assumed that the new location is large enough to fit the data. |
|
inline |
Drop the first "n" bytes from this slice.
[in] | n | Number of bytes that should be dropped from the beginning. |
|
inline |
|
inline |
Check whether the slice starts with the given prefix.
[in] | x | The slice in question. |
true
iff "x" is a prefix of "*this" std::string kudu::Slice::ToDebugString | ( | size_t | max_len = 0 | ) | const |
Get printable representation of the data in the slice.
[in] | max_len | The maximum number of bytes to output in the printable format; 0 means no limit. |
std::string kudu::Slice::ToString | ( | ) | const |
|
inline |
Truncate the slice to the given number of bytes.
[in] | n | The new size of the slice. |
Check whether two slices are identical.
[in] | x | One slice. |
[in] | y | Another slice. |
true
iff two slices contain byte-for-byte identical data.