kudu::Slice Class Reference

A wrapper around externally allocated data. More...

#include <slice.h>

List of all members.

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)

Detailed Description

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.


Constructor & Destructor Documentation

kudu::Slice::Slice ( const uint8_t *  d,
size_t  n 
) [inline]

Create a slice that refers to a uint8_t byte array.

Parameters:
[in] d The input array.
[in] n Number of bytes in the array.
kudu::Slice::Slice ( const char *  d,
size_t  n 
) [inline]

Create a slice that refers to a char byte array.

Parameters:
[in] d The input array.
[in] n Number of bytes in the array.
kudu::Slice::Slice ( const std::string &  s  )  [inline]

Create a slice that refers to the contents of the given string.

Parameters:
[in] s The input string.
kudu::Slice::Slice ( const char *  s  )  [inline]

Create a slice that refers to a C-string s[0,strlen(s)-1].

Parameters:
[in] s The input C-string.

Member Function Documentation

Status kudu::Slice::check_size ( size_t  expected_size  )  const

Check that the slice has the expected size.

Parameters:
[in] expected_size 
Returns:
Status::Corruption() iff size() != expected_size
int kudu::Slice::compare ( const Slice b  )  const [inline]

Do a three-way comparison of the slice's data.

Parameters:
[in] b The other slice to compare with.
Returns:
Values are
  • < 0 iff "*this" < "b"
  • == 0 iff "*this" == "b"
  • > 0 iff "*this" > "b"
const uint8_t* kudu::Slice::data (  )  const [inline]
Returns:
A pointer to the beginning of the referenced data.
bool kudu::Slice::empty (  )  const [inline]
Returns:
true iff the length of the referenced data is zero.
uint8_t* kudu::Slice::mutable_data (  )  [inline]
Returns:
A mutable pointer to the beginning of the referenced data.
const uint8_t& kudu::Slice::operator[] ( size_t  n  )  const [inline]
Precondition:
n < size()
Parameters:
[in] n The index of the byte.
Returns:
the n-th byte in the referenced data.
void kudu::Slice::relocate ( uint8_t *  d  )  [inline]

Relocate/copy the slice's data into a new location.

Parameters:
[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.
void kudu::Slice::remove_prefix ( size_t  n  )  [inline]

Drop the first "n" bytes from this slice.

Precondition:
n <= size()
Note:
Only the base and bounds of the slice are changed; the data is not modified.
Parameters:
[in] n Number of bytes that should be dropped from the beginning.
size_t kudu::Slice::size (  )  const [inline]
Returns:
The length (in bytes) of the referenced data.
bool kudu::Slice::starts_with ( const Slice x  )  const [inline]

Check whether the slice starts with the given prefix.

Parameters:
[in] x The slice in question.
Returns:
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.

Parameters:
[in] max_len The maximum number of bytes to output in the printable format; 0 means no limit.
Returns:
A string with printable representation of the data.
std::string kudu::Slice::ToString (  )  const
Returns:
A string that contains a copy of the referenced data.
void kudu::Slice::truncate ( size_t  n  )  [inline]

Truncate the slice to the given number of bytes.

Precondition:
n <= size()
Note:
Only the base and bounds of the slice are changed; the data is not modified.
Parameters:
[in] n The new size of the slice.

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines