|
Zero
0.1.0
|
Key string class which can represent a few special values. More...
#include <w_key.h>
Public Member Functions | |
| w_keystr_t () | |
| w_keystr_t (const w_keystr_t &r) | |
| w_keystr_t & | operator= (const w_keystr_t &r) |
| ~w_keystr_t () | |
| bool | construct_regularkey (const void *nonkeystr, w_keystr_len_t length) |
| bool | construct_neginfkey () |
| bool | construct_posinfkey () |
| bool | construct_from_keystr (const void *keystr, w_keystr_len_t length) |
| bool | construct_from_keystr (const void *keystr_prefix, w_keystr_len_t prefix_length, const void *keystr_suffix, w_keystr_len_t suffix_length) |
| bool | construct_from_keystr_poormkey_16 (const void *keystr_prefix, w_keystr_len_t prefix_length, w_keystr_len_t total_suffix_length, uint16_t poormkey, const void *keystr_suffix) |
| bool | construct_from_vec (const cvec_t &vect) |
| bool | copy_from_vec (const cvec_t &vect) |
| bool | is_constructed () const |
| bool | is_neginf () const |
| bool | is_posinf () const |
| bool | is_regular () const |
| w_keystr_len_t | common_leading_bytes (const w_keystr_t &r) const |
| w_keystr_len_t | common_leading_bytes (const unsigned char *str, w_keystr_len_t len) const |
| int | compare (const w_keystr_t &r) const |
| int | compare_keystr (const void *keystr, w_keystr_len_t length) const |
| int | compare_nonkeystr (const void *nonkeystr, w_keystr_len_t length) const |
| bool | operator== (const w_keystr_t &r) const |
| bool | operator!= (const w_keystr_t &r) const |
| bool | operator< (const w_keystr_t &r) const |
| bool | operator> (const w_keystr_t &r) const |
| bool | operator<= (const w_keystr_t &r) const |
| bool | operator>= (const w_keystr_t &r) const |
| void | serialize_as_nonkeystr (void *buffer) const |
| std::basic_string< unsigned char > | serialize_as_nonkeystr () const |
| w_keystr_len_t | get_length_as_nonkeystr () const |
| void | serialize_as_keystr (void *buffer) const |
| const void * | buffer_as_keystr () const |
| w_keystr_len_t | get_length_as_keystr () const |
| void | clear () |
Static Public Member Functions | |
| static w_keystr_len_t | common_leading_bytes (const unsigned char *str1, w_keystr_len_t len1, const unsigned char *str2, w_keystr_len_t len2) |
| static int | compare_bin_str (const void *str1, int len1, const void *str2, int len2) |
Private Member Functions | |
| void | _assure (w_keystr_len_t required_len) |
Private Attributes | |
| unsigned char * | _data |
| uint32_t | _strlen |
| uint32_t | _memlen |
Friends | |
| class | w_keystr_t_test |
| std::ostream & | operator<< (std::ostream &, const w_keystr_t &v) |
Key string class which can represent a few special values.
This class differs from vec_t/cvec_t mainly for two points.
First, w_keystr_t keeps its copy of string data like std::string. vec_t/cvec_t just keeps pointers to original data, which is efficient but cannot be used for some cases. For example, when the original data is being changed.
Second, w_keystr_t represents a few special values, NULL, Infimum and Supremum both as on-memory data and on-disk data. vec_t/cvec_t loses neg_inf/pos_inf information when it's written out to disk. As we need to store infimum/supremum in B+Tree fence keys, we need a new class to store key data.
In sum, when you just want on-memory data representation, use vec_t/cvec_t. When you need to represent a key to be stored on disk, or to be compared with other keys on disk, use this class.
This is a tiny header-only class. All functions are defined here.
|
inline |
This class provides only this empty constructor and copy constructor from another w_keystr_t. This is by design to prohibit incorrect use. Explicitly use construct_regularkey()/construct_from_keystr() to make sure if the input already has sign bytes.
|
inline |
|
inline |
|
inlineprivate |
re-allocate _data for required length if needed.
|
inline |
Returns the internal content WITH sign byte of this key string.
|
inline |
discards all data and releases all resources.
|
inline |
Returns the count of common leading bytes with the given key string.
|
inline |
Returns the count of common leading bytes with the given key string.
|
inlinestatic |
Returns the count of common leading bytes in the two given strings.
|
inline |
Compares this string with another w_keystr_t object.
| [in] | r | another string to compare with |
|
inlinestatic |
Compares two strings.
|
inline |
Compares this string with a string data WITH sign byte which should be a serialized w_keystr_t.
| [in] | keystr | another string data WITH sign byte to compare with |
| [in] | length | length of the keystr |
|
inline |
Compares this string with a string data WITH sign byte which should be a serialized w_keystr_t. Note that non-key string can't represent infinity.
| [in] | nonkeystr | another non-key string data WITH sign byte to compare with |
| [in] | length | length of the nonkeystr |
|
inline |
Constructs from a key string WITH sign byte.
| keystr | The string WITH sign byte. |
| length | The length WITH sign byte. |
|
inline |
Used when the key string consists of prefix and suffix.
|
inline |
Used when the key string consists of prefix, poor-man's key and suffix.
| total_suffix_length | key length including poorman's key and suffix. Note that this might be smaller than sizeof(poormkey)! E.g., total_suffix_length=1: returns prefix and only the first byte of poormkey. |
| bool w_keystr_t::construct_from_vec | ( | const cvec_t & | vect | ) |
|
inline |
Creates an object that represents negative infinity.
|
inline |
Creates an object that represents positive infinity.
|
inline |
Constructs from a general string without sign byte. Use this method to convert user inputs to a keystr object. Do NOT use this method to copy from other keystr object. You will duplicate the sign byte and mess up all comparisons! To copy from existing keystr object, just use copy constructor or assignment operator.
Usage Example:
w_keystr_t str1;
str1.construct_regularkey ("your_key", 8); | nonkeystr | The string WITHOUT sign byte. |
| length | The length WITHOUT sign byte. |
| bool w_keystr_t::copy_from_vec | ( | const cvec_t & | vect | ) |
|
inline |
length of this string WITH sign byte.
|
inline |
length of this string WITHOUT sign byte.
|
inline |
This class does NOT throw exceptions on out-of-memory. Use this function to check if it's constructed.
|
inline |
Returns if this object represents negative infinity.
|
inline |
Returns if this object represents positive infinity.
|
inline |
Returns if this object represents non-inifinity value.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
operator overloads.
|
inline |
|
inline |
|
inline |
Copy the string data of this object to the given buffer WITH sign byte.
|
inline |
Copy the string data of this object to the given buffer WITHOUT sign byte.
|
inline |
For convenience. Returns std::string object.
|
friend |
|
friend |
|
private |
raw data. this internal data starts with a sign byte.
|
private |
allocated length of _data, which could be larger than _strlen.
|
private |
length of _data, which is 1 byte longer than the actual data.
1.8.12