*str_len = (
str[0]) |
56*str_len = -(*str_len);
59*str_len = (
int)::strlen((
const char*)
str);
63*str_len = -(*str_len);
79 const unsigned char*
str= (
const unsigned char*)
val->data;
81 if(
val->size <= 4) {
83*str_len = (
int)::strlen((
const char*)
str);
107 #ifdef HAVE_UNALIGNED_READS 108v1 = *((
Uint4*) val1->data);
111::memcpy(&v1, val1->data,
sizeof(
Uint4));
112::memcpy(&
v2, val2->data,
sizeof(
Uint4));
114 return(v1 <
v2) ? -1
115: ((
v2< v1) ? 1 : 0);
121 #ifdef HAVE_UNALIGNED_READS 122v1 = *((
Int8*) val1->data);
123 v2= *((
Int8*) val2->data);
125::memcpy(&v1, val1->data,
sizeof(
Int8));
126::memcpy(&
v2, val2->data,
sizeof(
Int8));
128 return(v1 <
v2) ? -1
129: ((
v2< v1) ? 1 : 0);
135 #ifdef HAVE_UNALIGNED_READS 136v1 = *((
Uint8*) val1->data);
139::memcpy(&v1, val1->data,
sizeof(
Uint8));
140::memcpy(&
v2, val2->data,
sizeof(
Uint8));
142 return(v1 <
v2) ? -1
143: ((
v2< v1) ? 1 : 0);
154 #ifdef HAVE_UNALIGNED_READS 155v1 = *((
Int4*) val1->data);
156 v2= *((
Int4*) val2->data);
158::memcpy(&v1, val1->data,
sizeof(
Int4));
159::memcpy(&
v2, val2->data,
sizeof(
Int4));
161 return(v1 <
v2) ? -1
162: ((
v2< v1) ? 1 : 0);
168 #ifdef HAVE_UNALIGNED_READS 169v1 = *((
Int2*) val1->data);
170 v2= *((
Int2*) val2->data);
172::memcpy(&v1, val1->data,
sizeof(
Int2));
173::memcpy(&
v2, val2->data,
sizeof(
Int2));
175 return(v1 <
v2) ? -1
176: ((
v2< v1) ? 1 : 0);
182 #ifdef HAVE_UNALIGNED_READS 183v1 = *((
Uint2*) val1->data);
186::memcpy(&v1, val1->data,
sizeof(
Uint2));
187::memcpy(&
v2, val2->data,
sizeof(
Uint2));
189 return(v1 <
v2) ? -1
190: ((
v2< v1) ? 1 : 0);
195 const char& v1=*
static_cast<char*
>(val1->data);
196 const char&
v2=*
static_cast<char*
>(val2->data);
198 return(v1 <
v2) ? -1
199: ((
v2< v1) ? 1 : 0);
204 const unsigned char& v1=*
static_cast<unsigned char*
>(val1->data);
205 const unsigned char&
v2=*
static_cast<unsigned char*
>(val2->data);
207 return(v1 <
v2) ? -1
208: ((
v2< v1) ? 1 : 0);
214 #ifdef HAVE_UNALIGNED_READS 215v1 = *((
float*) val1->data);
216 v2= *((
float*) val2->data);
218::memcpy(&v1, val1->data,
sizeof(v1));
219::memcpy(&
v2, val2->data,
sizeof(
v2));
221 return(v1 <
v2) ? -1
222: ((
v2< v1) ? 1 : 0);
228 #ifdef HAVE_UNALIGNED_READS 229v1 = *((
double*) val1->data);
230 v2= *((
double*) val2->data);
232::memcpy(&v1, val1->data,
sizeof(v1));
233::memcpy(&
v2, val2->data,
sizeof(
v2));
235 return(v1 <
v2) ? -1
236: ((
v2< v1) ? 1 : 0);
241 return ::strcmp((
const char*)val1->data, (
const char*)val2->data);
246 _ASSERT(val1->size == val2->size);
247 int r= ::memcmp(val1->data, val2->data, val1->size);
260 const unsigned char* str1;
261 const unsigned char* str2;
268 intcmp_len =
min(str_len1, str_len2);
269 int r= ::memcmp(str1, str2, cmp_len);
271 return(str_len1 < str_len2) ? -1
272: ((str_len2 < str_len1) ? 1 : 0);
280 return NStr::strcasecmp((
const char*)val1->data, (
const char*)val2->data);
292 const char* p1 =
static_cast<char*
>(val1->data);
293 const char* p2 =
static_cast<char*
>(val2->data);
296 if(cmp_limit == 0) {
299 _ASSERT(cmp_limit <= fbuf1->FieldCount());
302 for(
unsigned int i= 0;
i< cmp_limit; ++
i) {
304 intret = fld1.
Compare(p1, p2, byte_swapped);
320 const unsigned char*
buf= (
const unsigned char*)bytes;
321 const unsigned char* buf_end =
buf+ length;
325 for(;
buf!= buf_end; ++
buf) {
326ha = ((ha << 4) + ha) + *
buf;
336::memcpy(&ha, bytes, 4);
339 return BDB_Hash(db, bytes, length);
352 unsigned intv1,
v2;
355 return(v1 <
v2) ? -1
356: ((
v2< v1) ? 1 : 0);
364 return(v1 <
v2) ? -1
365: ((
v2< v1) ? 1 : 0);
373 return(v1 <
v2) ? -1
374: ((
v2< v1) ? 1 : 0);
387 return(v1 <
v2) ? -1
388: ((
v2< v1) ? 1 : 0);
396 return(v1 <
v2) ? -1
397: ((
v2< v1) ? 1 : 0);
405 return(v1 <
v2) ? -1
406: ((
v2< v1) ? 1 : 0);
415 return(v1 <
v2) ? -1
416: ((
v2< v1) ? 1 : 0);
425 return(v1 <
v2) ? -1
426: ((
v2< v1) ? 1 : 0);
448: m_BufferManager(0),
482m_ByteSwapped(
false),
486m_LegacyString(
false),
487m_OwnFields(
false),
488m_PackOptComputed(
false),
489m_FirstVarFieldIdx(0),
490m_FirstVarFieldIdxOffs(0)
511 unsignedfield_idx = (unsigned)(
m_Fields.size() - 1);
527 const string& fname = field.
GetName();
554 stringmessage(
"NULL field in database operation.");
555 const string& field_name = fld.
GetName();
556 if( !field_name.empty() ) {
557message.append(
"(Field:");
558message.append(field_name);
559message.append(
")");
584 char* buf_ptr = (
char*)
m_Buffer;
591 df.SetBufferManager(
this);
592 df.SetBuffer(buf_ptr);
594buf_ptr +=
df.GetBufferSize();
607 return m_Fields[0]->GetCompareFunction(byte_swapped);
633 df.SetBuffer(buf_ptr);
634 size_t len=
df.GetDataLength(buf_ptr);
645 for(TFieldVector::size_type
i= 0;
i<
m_Fields.size(); ++
i) {
648 if(
df.IsVariableLength()) {
679 size_tactual_len =
df.GetLength();
682 if(new_ptr != old_ptr) {
683 ::memmove(new_ptr, old_ptr, actual_len);
684 df.SetBuffer(new_ptr);
694new_ptr += actual_len;
716 for(
size_t i=
m_Fields.size() - 1;
true; --
i) {
718 size_tactual_len =
df.GetLength();
720 const void* old_ptr =
df.GetBuffer();
721 if(new_ptr != old_ptr) {
722 ::memmove(new_ptr, old_ptr, actual_len);
723 df.SetBuffer(new_ptr);
744dbt->flags = DB_DBT_USERMEM;
752dbt->flags = DB_DBT_USERMEM;
757 unsigned intfield_count)
const 759 if( !field_count ) {
764 for(
unsigned int i= 0;
i< field_count; ++
i) {
780 for(
unsigned int i= 0;
i< buf_mgr.
FieldCount(); ++
i) {
784unique_ptr<CBDB_Field> dst_fld(src_fld.
Construct(0));
786dst_fld->SetName(src_fld.
GetName().c_str());
787 Bind(dst_fld.get());
829 BDB_THROW(eOverflow,
"Fixed string field overflow.");
834 if(
str.IsNull() ) {
864 const unsigned char*
871 if(DBT_size > 0 && DBT_size <= 4) {
873*str_len = (
int)::strlen((
const char*)
str);
916 BDB_THROW(eOverflow,
"String field overflow.");
921 if(
str.IsNull() ) {
936 size_tnew_len =
size;
940 if(new_len > eff_buffer_size) {
942new_len = eff_buffer_size;
944 stringmessage(
"String field overflow. Max length is ");
946message +=
", requested length is ";
952 unsigned char* str_buf = (
unsigned char*)
GetBuffer();
954 ints_len = -(
int)new_len;
955str_buf[0] = (
unsignedchar) (s_len);
956str_buf[1] = (
unsignedchar) (s_len >> 8);
957str_buf[2] = (
unsignedchar) (s_len >> 16);
958str_buf[3] = (
unsignedchar) (s_len >> 24);
962::memcpy(str_buf,
str, new_len);
973this->
Set(str, ::strlen(
str), if_overflow);
990 const unsigned char* str1;
991 const unsigned char* str2;
995str1 =
GetLString((
const unsigned char*)p1, check_legacy, &str_len1);
996str2 =
GetLString((
const unsigned char*)p2, check_legacy, &str_len2);
998 intcmp_len =
min(str_len1, str_len2);
999 int r= ::memcmp(str1, str2, cmp_len);
1001 return(str_len1 < str_len2) ? -1
1002: ((str_len2 < str_len1) ? 1 : 0);
1019::memset(
buf, 0x7F, buf_size);
1020((
char*)
buf)[buf_size - 1] =
'\0';
1022 ints_len = -((
int)buf_size - 4);
1023 unsigned char* str_buf = (
unsigned char*)
buf;
1025str_buf[0] = (
unsignedchar) (s_len);
1026str_buf[1] = (
unsignedchar) (s_len >> 8);
1027str_buf[2] = (
unsignedchar) (s_len >> 16);
1028str_buf[3] = (
unsignedchar) (s_len >> 24);
1036 const unsigned char*
str= (
const unsigned char*)
GetBuffer();
1042 return(str_len == 0);
1047 const unsigned char*
str= (
const unsigned char*)
GetBuffer();
1053 for(
int i= 0;
i< str_len; ++
i) {
1064 const unsigned char*
str= (
const unsigned char*)
buf;
1069 if(
str!= (
const unsigned char*)
buf)
1094 const unsigned char*
buf= (
const unsigned char*)
GetBuffer();
1097 const unsigned char*
str;
1104 stringret((
const char*)
str, str_len);
1110 const unsigned char*
buf= (
const unsigned char*)
GetBuffer();
1113 const unsigned char*
str;
1122ostr.append((
const char*)
str, str_len);
1127 size_tstr_len =
str.length();
1135 if(str_len > eff_buffer_size) {
1136 stringmessage(
"String field overflow. Max length is ");
1138message +=
", requested length is ";
1143 const char* str_data =
str.data();
1145 unsigned char* str_buf = (
unsigned char*)
Unpack();
1147 ints_len = -(
int)str_len;
1148str_buf[0] = (
unsignedchar) (s_len);
1149str_buf[1] = (
unsignedchar) (s_len >> 8);
1150str_buf[2] = (
unsignedchar) (s_len >> 16);
1151str_buf[3] = (
unsignedchar) (s_len >> 24);
1154::memcpy(str_buf, str_data, str_len);
1231 BDB_THROW(eInvalidType,
"Type is not supported.");
static const unsigned char * s_GetLString(const unsigned char *str, bool check_legacy, int *str_len)
unsigned int(* BDB_HashFunction)(DB *, const void *bytes, unsigned length)
int(* BDB_CompareFunction)(DB *, const DBT *, const DBT *)
BDB Data Field Buffer manager class.
Double precision floating point field type.
Length prefised string field type.
String field type designed to work with C-strings (ASCIIZ)
Base class for constructing BDB fields.
static Int8 GetInt8(const unsigned char *ptr)
static double GetDouble(const unsigned char *ptr)
static Int2 GetInt2(const unsigned char *ptr)
static Int4 GetInt4(const unsigned char *ptr)
static float GetFloat(const unsigned char *ptr)
static const char * str(char *buf, int n)
ENullable
Whether a value is nullable.
@ eNullable
Value can be null.
virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const
Return address to the type specific comparison function By default it's universal BDB_Compare.
void SetDBT_Size(size_t size)
CBDB_FieldFixedByteString & operator=(const CBDB_FieldFixedByteString &str)
void CopyFrom(const CBDB_BufferManager &bman)
Copy all fields from another manager with the same(a must!) structure.
virtual CBDB_Field * Construct(size_t buf_size) const
Virtual constructor - class factory for BDB fields.
int BDB_LStringCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented length prefixed string keys.
unsigned int BDB_Hash(DB *, const void *bytes, unsigned length)
String hash function taken from SStringHash (algo/text/text_util)
bool m_LegacyString
Flag to check for legacy string compatibility.
virtual void SetMaxVal()
Set maximum possible value for the field type.
int BDB_CharCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "char" keys.
int BDB_FloatCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "float" keys.
bool IsNull() const
Return TRUE if field is NULL.
int BDB_IntCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "int" keys.
EType GetType(const string &type) const
Return type enumerator by string type (case insensitive)
void SetNotNull()
Set "is NULL" flag to FALSE.
virtual int Compare(const void *p1, const void *p2, bool byte_swapped) const =0
Comparison function.
int BDB_Uint2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned short int" keys.
bool IsLegacyStrings() const
Return TRUE if buffer l-strings should check about legacy c-str compatibility.
unsigned int m_FirstVarFieldIdx
Index of first variable length field.
struct CBDB_Field::@104 m_Flags
unsigned int BDB_Uint4Hash(DB *db, const void *bytes, unsigned length)
Hash method for databases with a single (unique) UInt4 key.
void CheckNullConstraint() const
Check if all NOT NULLABLE fields were assigned.
void Set(const char *str, EOverflowAction if_overflow=eThrowOnOverflow)
CBDB_Field(ELengthType length_type=eFixedLength)
void PrepareDBT_ForWrite(DBT *dbt)
Pack the buffer and initialize DBT structure for write operation.
void SetBufferSize(size_t size)
Set the buffer size.
int BDB_ByteSwap_Int4Compare(DB *, const DBT *val1, const DBT *val2)
int BDB_UCharCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned char" keys.
int BDB_ByteSwap_Int2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "short int" keys Used when the data...
BDB_HashFunction GetHashFunction() const
Return buffer hash function.
bool IsByteSwapped() const
Return TRUE if buffer is in a non-native byte order.
unsigned int FieldCount() const
Return number of fields attached using function Bind.
ELengthType
Length based classificator for fields (fixed-variable)
int BDB_Uint8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Uint8" keys.
void * Unpack()
Unpack the buffer which contains this field (using CBDB_BufferManager).
int BDB_Uint4Compare(DB *, const DBT *val1, const DBT *val2)
bool IsNullable() const
Return TRUE if field can be NULL.
void Construct()
Create internal data buffer, assign places in this buffer to the fields.
bool IsNullable() const
Return TRUE if buffer can carry NULL fields.
bool TestNullBit(unsigned int idx) const
CBDB_Field * Create(EType type) const
int BDB_UintCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned int" keys.
int BDB_ByteSwap_Uint4Compare(DB *, const DBT *val1, const DBT *val2)
virtual size_t GetDataLength(const void *buf) const =0
Return current effective size of the buffer.
virtual int Compare(const void *p1, const void *p2, bool) const
Comparison function.
int BDB_ByteSwap_Uint2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned short int" keys Used when...
virtual void ToString(string &str) const
int BDB_ByteSwap_UintCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned int" keys.
int Compare(const CBDB_BufferManager &buf_mgr, unsigned int n_fields=0) const
Compare fields of this buffer with those of 'buf_mgr' using CBDB_Field::CompareWith().
void DuplicateStructureFrom(const CBDB_BufferManager &buf_mgr)
Duplicate (dynamic allocation is used) all fields from 'buf_mgr' and bind them to the this buffer man...
virtual void SetString(const char *)
const CBDB_Field & GetField(unsigned int idx) const
bool m_OwnFields
Field ownership flag.
CBDB_FieldFixedByteString()
virtual void SetStdString(const string &str)
const string & GetName() const
Return symbolic name for the field.
int BDB_Compare(DB *db, const DBT *val1, const DBT *val2)
General purpose DBD comparison function.
int BDB_ByteSwap_Uint8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Uint8" keys Used when the data fil...
vector< void * > m_Ptrs
Array of pointers to the fields' data.
int BDB_ByteSwap_Int8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Int8" keys Used when the data file...
bool IsPackable() const
Return TRUE if any field bound to this buffer manager has variable length (i.e.
virtual size_t GetExtraDataLength()
Hook for defining extra data length.
void SetNull()
Assign field value to NULL.
bool m_PackOptComputed
Pack optimization flag (turns TRUE on first Pack call)
unsigned int m_FirstVarFieldIdxOffs
Buffer offset of first variable length field.
int BDB_StringCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "C string" keys.
int BDB_Int8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Int8" keys.
int CompareWith(const CBDB_Field &field) const
Field comparison function.
unsigned int GetFieldCompareLimit() const
Get number of fields in comparison.
int BDB_StringCaseCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "case insensitive C string" keys.
int BDB_ByteSwap_IntCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "int" keys Used when the data file ...
void PrepareDBT_ForRead(DBT *dbt)
Initialize DBT structure for read operation.
virtual size_t GetDataLength(const void *buf) const
Return current effective size of the buffer.
void Bind(CBDB_Field *field, ENullable is_nullable=eNotNullable)
Attach 'field' to the buffer.
size_t GetDBT_Size() const
Get DBT.size of the parent file (key or data area) (Set by CBDB_File after read)
CBDB_BufferManager * m_BufferManager
bool IsVariableLength() const
Return TRUE if it is a variable length variable (like string)
size_t ComputeNullSetSize() const
BDB_CompareFunction GetCompareFunction() const
Return buffer compare function.
void CopyPackedFrom(void *data, size_t data_size)
Copy packed data (buffer) from an external source.
size_t m_NullSetSize
size of the 'is NULL' bitset in bytes
size_t GetBufferSize() const
Return maximum possible buffer length.
int BDB_Int2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "short int" keys.
const unsigned char * GetLString(const unsigned char *str, bool check_legacy, int *str_len) const
virtual void SetMinVal()
Set minimal possible value for the field type.
int BDB_FixedByteStringCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented fixed length string keys.
int BDB_ByteSwap_FloatCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "float" keys Used when the data fil...
int BDB_Int4Compare(DB *, const DBT *val1, const DBT *val2)
const void * GetBuffer() const
Get pointer to the data. NULL if not yet attached.
int GetFieldIndex(const string &name) const
Find the field with the specified name.
void SetNullable()
Mark field as "NULL" capable.
void SetBufferIdx(unsigned int idx)
Set field position in the buffer manager.
int BDB_DoubleCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "double" keys.
size_t ComputeBufferSize() const
Calculate buffer size.
CBDB_FieldLString & operator=(const CBDB_FieldLString &str)
void CopyFieldsFrom(const CBDB_BufferManager &buf_mgr)
Copy all field values from the 'buf_mgr'.
virtual CBDB_Field * Construct(size_t buf_size=0) const =0
Virtual constructor - class factory for BDB fields.
virtual size_t GetExtraDataLength()
Hook for defining extra data length.
int BDB_ByteSwap_DoubleCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "double" keys Used when the data fi...
@ eFixedLength
fixed-length (like int)
#define BDB_THROW(errcode, message)
int16_t Int2
2-byte (16-bit) signed integer
int32_t Int4
4-byte (32-bit) signed integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
static int strcasecmp(const char *s1, const char *s2)
Case-insensitive comparison of two zero-terminated strings.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
unsigned int
A callback function used to compare two keys in a database.
if(yy_accept[yy_current_state])
const struct ncbi::grid::netcache::search::fields::SIZE size
int strcmp(const char *str1, const char *str2)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
double df(double x_, const double &y_)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4