id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
17,222
|
charset_definition_parser.h
|
manticoresoftware_manticoresearch/src/tokenizer/charset_definition_parser.h
|
//
// Copyright (c) 2008-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "sphinxstd.h"
#include "remap_range.h"
struct CharsetAlias_t
{
CSphString m_sName;
int m_iNameLen;
CSphVector<CSphRemapRange> m_dRemaps;
};
// used in ICU
const CSphVector<CharsetAlias_t>& GetCharsetAliases();
bool sphInitCharsetAliasTable ( CSphString& sError );
/// parse charset table
bool sphParseCharset ( const char* szCharset, CSphVector<CSphRemapRange>& dRemaps, CSphString* pError = nullptr );
| 909
|
C++
|
.h
| 25
| 35
| 114
| 0.77221
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,223
|
lowercaser_impl.h
|
manticoresoftware_manticoresearch/src/tokenizer/lowercaser_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "lowercaser.h"
#include "sphinxstd.h"
enum : DWORD {
MASK_CODEPOINT = 0x00ffffffUL, // mask off codepoint flags
MASK_FLAGS = 0xff000000UL, // mask off codepoint value
FLAG_CODEPOINT_SPECIAL = 0x01000000UL, // this codepoint is special
FLAG_CODEPOINT_DUAL = 0x02000000UL, // this codepoint is special but also a valid word part
FLAG_CODEPOINT_NGRAM = 0x04000000UL, // this codepoint is n-gram indexed
FLAG_CODEPOINT_BOUNDARY = 0x10000000UL, // this codepoint is phrase boundary
FLAG_CODEPOINT_IGNORE = 0x20000000UL, // this codepoint is ignored
FLAG_CODEPOINT_BLEND = 0x40000000UL // this codepoint is "blended" (indexed both as a character, and as a separator)
};
| 1,181
|
C++
|
.h
| 24
| 47.708333
| 118
| 0.761492
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,224
|
exceptions_trie.h
|
manticoresoftware_manticoresearch/src/tokenizer/exceptions_trie.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "sphinxstd.h"
class Writer_i;
class JsonEscapedBuilder;
class ExceptionsTrie_c
{
int m_dFirst[256]; ///< table to speedup 1st byte lookup
CSphVector<BYTE> m_dData; ///< data blob
int m_iCount; ///< number of exceptions
int m_iMappings; ///< offset where the nodes end, and output mappings start
friend class ExceptionsTrieGen_c;
public:
const BYTE* GetMapping ( int i ) const
{
assert ( i >= 0 && i < m_iMappings );
int p = *(int*)&m_dData[i];
if ( !p )
return nullptr;
assert ( p >= m_iMappings && p < m_dData.GetLength() );
return &m_dData[p];
}
int GetFirst ( BYTE v ) const
{
return m_dFirst[v];
}
int GetNext ( int i, BYTE v ) const
{
assert ( i >= 0 && i < m_iMappings );
if ( i == 0 )
return m_dFirst[v];
BYTE* p = &m_dData[i];
int n = p[4];
p += 5;
for ( i = 0; i < n; i++ )
if ( p[i] == v )
return *(int*)&p[n + 4 * i]; // FIXME? unaligned
return -1;
}
void Export ( Writer_i & w ) const;
void Export ( JsonEscapedBuilder& tOut ) const;
};
/// exceptions trie builder
/// plain old text mappings in, nice useful trie out
class ExceptionsTrieGen_c
{
class Impl_c;
Impl_c* m_pImpl = nullptr;
friend class ExceptionsTrie_c;
public:
ExceptionsTrieGen_c();
~ExceptionsTrieGen_c();
void FoldSpace ( char* s ) const;
bool ParseLine ( char* sBuffer, CSphString& sError );
ExceptionsTrie_c* Build();
};
| 1,885
|
C++
|
.h
| 66
| 26.439394
| 80
| 0.678097
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,225
|
token_filter.h
|
manticoresoftware_manticoresearch/src/tokenizer/token_filter.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "tokenizer.h"
//////////////////////////////////////////////////////////////////////////
// TOKEN FILTER
//////////////////////////////////////////////////////////////////////////
/// token filter base (boring proxy stuff)
class CSphTokenFilter : public ISphTokenizer
{
public:
explicit CSphTokenFilter ( TokenizerRefPtr_c pTokenizer ) : m_pTokenizer { std::move ( pTokenizer ) } {}
bool SetCaseFolding ( const char * sConfig, CSphString & sError ) override { return m_pTokenizer->SetCaseFolding ( sConfig, sError ); }
void AddPlainChars ( const char * szChars ) override { m_pTokenizer->AddPlainChars ( szChars ); }
void AddSpecials ( const char * sSpecials ) override { m_pTokenizer->AddSpecials ( sSpecials ); }
bool SetIgnoreChars ( const char * sIgnored, CSphString & sError ) override { return m_pTokenizer->SetIgnoreChars ( sIgnored, sError ); }
bool SetNgramChars ( const char * sConfig, CSphString & sError ) override { return m_pTokenizer->SetNgramChars ( sConfig, sError ); }
void SetNgramLen ( int iLen ) override { m_pTokenizer->SetNgramLen ( iLen ); }
bool LoadSynonyms ( const char * sFilename, const CSphEmbeddedFiles * pFiles, StrVec_t & dWarnings, CSphString & sError ) override { return m_pTokenizer->LoadSynonyms ( sFilename, pFiles, dWarnings, sError ); }
void WriteSynonyms ( Writer_i & tWriter ) const final { return m_pTokenizer->WriteSynonyms ( tWriter ); }
void WriteSynonyms ( JsonEscapedBuilder & tOut ) const final { return m_pTokenizer->WriteSynonyms ( tOut ); }
bool SetBoundary ( const char * sConfig, CSphString & sError ) override { return m_pTokenizer->SetBoundary ( sConfig, sError ); }
void Setup ( const CSphTokenizerSettings & tSettings ) override { m_pTokenizer->Setup ( tSettings ); }
const CSphTokenizerSettings & GetSettings () const override { return m_pTokenizer->GetSettings (); }
const CSphSavedFile & GetSynFileInfo () const override { return m_pTokenizer->GetSynFileInfo (); }
bool EnableSentenceIndexing ( CSphString & sError ) override { return m_pTokenizer->EnableSentenceIndexing ( sError ); }
bool EnableZoneIndexing ( CSphString & sError ) override { return m_pTokenizer->EnableZoneIndexing ( sError ); }
int SkipBlended () override { return m_pTokenizer->SkipBlended(); }
bool IsQueryTok() const noexcept override { return m_pTokenizer->IsQueryTok(); }
void SetPhraseMode ( bool bPhrase ) override { m_pTokenizer->SetPhraseMode ( bPhrase ); }
bool IsPhraseMode () const noexcept override { return m_pTokenizer->IsPhraseMode(); }
int GetCodepointLength ( int iCode ) const noexcept final { return m_pTokenizer->GetCodepointLength ( iCode ); }
int GetMaxCodepointLength () const noexcept final { return m_pTokenizer->GetMaxCodepointLength(); }
const char * GetTokenStart () const noexcept override { return m_pTokenizer->GetTokenStart(); }
const char * GetTokenEnd () const noexcept override { return m_pTokenizer->GetTokenEnd(); }
const char * GetBufferPtr () const noexcept override { return m_pTokenizer->GetBufferPtr(); }
const char * GetBufferEnd () const noexcept final { return m_pTokenizer->GetBufferEnd (); }
void SetBufferPtr ( const char * sNewPtr ) override { m_pTokenizer->SetBufferPtr ( sNewPtr ); }
uint64_t GetSettingsFNV () const noexcept override { return m_pTokenizer->GetSettingsFNV(); }
void SetBuffer ( const BYTE * sBuffer, int iLength ) override { m_pTokenizer->SetBuffer ( sBuffer, iLength ); }
BYTE * GetToken () override { return m_pTokenizer->GetToken(); }
bool WasTokenMultiformDestination ( bool & bHead, int & iDestCount ) const noexcept override { return m_pTokenizer->WasTokenMultiformDestination ( bHead, iDestCount ); }
protected:
TokenizerRefPtr_c m_pTokenizer;
};
| 4,421
|
C++
|
.h
| 54
| 80.037037
| 215
| 0.691089
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,226
|
source_pgsql.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_pgsql.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "source_sql.h"
/// PgSQL specific source params
struct CSphSourceParams_PgSQL : CSphSourceParams_SQL
{
CSphString m_sClientEncoding;
CSphSourceParams_PgSQL ();
};
/// PostgreSQL source implementation
CSphSource * CreateSourcePGSQL ( const CSphSourceParams_PgSQL & tParams, const char * sSourceName );
| 806
|
C++
|
.h
| 21
| 37.095238
| 100
| 0.772087
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,227
|
source_document.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_document.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "sphinxstd.h"
#include "indexsettings.h"
#include "sphinxdefs.h"
#include "source_stats.h"
#include "match.h"
#include "schema/schema.h"
#include "std/openhash.h"
class CSphHTMLStripper;
class CSphDict;
using DictRefPtr_c = CSphRefcountedPtr<CSphDict>;
class ISphFieldFilter;
class ISphTokenizer;
class CSphAutofile;
using TokenizerRefPtr_c = CSphRefcountedPtr<ISphTokenizer>;
/// how to handle IO errors in file fields
enum ESphOnFileFieldError
{
FFE_IGNORE_FIELD,
FFE_SKIP_DOCUMENT,
FFE_FAIL_INDEX
};
struct IDPair_t
{
DocID_t m_tDocID;
RowID_t m_tRowID;
};
constexpr int MAX_SOURCE_HITS = 32768;
class AttrSource_i
{
public:
virtual ~AttrSource_i () {}
/// returns value of a given attribute
virtual SphAttr_t GetAttr ( int iAttr ) = 0;
/// returns mva values for a given attribute (mva must be stored in a field)
virtual CSphVector<int64_t> * GetFieldMVA ( int iAttr ) = 0;
/// returns string attributes for a given attribute
virtual const CSphString & GetStrAttr ( int iAttr ) = 0;
};
/// generic document source
/// provides multi-field support and generic tokenizer
class CSphSource : public CSphSourceSettings, public AttrSource_i
{
public:
CSphMatch m_tDocInfo; ///< current document info
/// ctor
explicit CSphSource ( const char * sName );
/// dtor
~CSphSource () override;
/// set dictionary
void SetDict ( const DictRefPtr_c& dict );
/// set HTML stripping mode
///
/// sExtractAttrs defines what attributes to store. format is "img=alt; a=alt,title".
/// empty string means to strip all tags; NULL means to disable stripping.
///
/// sRemoveElements defines what elements to cleanup. format is "style, script"
///
/// on failure, returns false and fills sError
bool SetStripHTML ( const char * sExtractAttrs, const char * sRemoveElements, bool bDetectParagraphs, const char * sZones, CSphString & sError );
/// set field filter
virtual void SetFieldFilter ( std::unique_ptr<ISphFieldFilter> pFilter );
/// set tokenizer
void SetTokenizer ( TokenizerRefPtr_c pTokenizer );
/// set rows dump file
virtual void SetDumpRows ( FILE * fpDumpRows ) { m_fpDumpRows = fpDumpRows; }
/// get stats
virtual const CSphSourceStats & GetStats ();
/// updates schema fields and attributes
/// updates pInfo if it's empty; checks for match if it's not
/// must be called after IterateStart(); will always fail otherwise
virtual bool UpdateSchema ( CSphSchema * pInfo, CSphString & sError );
/// setup misc indexing settings (prefix/infix/exact-word indexing, position steps)
virtual void Setup ( const CSphSourceSettings & tSettings, StrVec_t * pWarnings );
bool SetupMorphFields ( CSphString & sError );
/// connect to the source (eg. to the database)
/// connection settings are specific for each source type and as such
/// are implemented in specific descendants
virtual bool Connect ( CSphString & sError ) = 0;
/// disconnect from the source
virtual void Disconnect () = 0;
/// check if there are any joined fields
virtual bool HasJoinedFields () { return m_iPlainFieldsLength!=m_tSchema.GetFieldsCount(); }
/// begin indexing this source
/// to be implemented by descendants
virtual bool IterateStart ( CSphString & sError ) = 0;
/// get next document
/// to be implemented by descendants
/// returns false on error
/// returns true and sets bEOF
virtual bool IterateDocument ( bool & bEOF, CSphString & sError );
/// get next hits chunk for current document
/// to be implemented by descendants
/// returns NULL when there are no more hits
/// returns pointer to hit vector (with at most MAX_SOURCE_HITS) on success
/// fills out-string with error message on failure
virtual ISphHits * IterateHits ( CSphString & sError );
/// get joined hits from joined fields (w/o attached docinfos)
/// returns false and fills out-string with error message on failure
/// returns true and sets m_tDocInfo.m_uDocID to 0 on eof
/// returns true and sets m_tDocInfo.m_uDocID to non-0 on success
virtual ISphHits * IterateJoinedHits ( CSphReader & tReader, CSphString & sError );
/// get fields and store them in a file
/// dJoinedOffsets holds per-field offsets to data in that file
virtual bool FetchJoinedFields ( CSphAutofile & tFile, CSphVector<std::unique_ptr<OpenHashTable_T<uint64_t, uint64_t>>> & dJoinedOffsets, CSphString & sError ) { return false; }
/// begin iterating values of out-of-document multi-valued attribute iAttr
/// will fail if iAttr is out of range, or is not multi-valued
/// can also fail if configured settings are invalid (eg. SQL query can not be executed)
virtual bool IterateMultivaluedStart ( int iAttr, CSphString & sError ) = 0;
/// fetch next multi-valued attribute value
virtual bool IterateMultivaluedNext ( int64_t & iDocID, int64_t & iMvaValue ) = 0;
/// notification that a rowid was assigned to a specific docid (used by joined fields)
virtual void RowIDAssigned ( DocID_t tDocID, RowID_t tRowID );
/// fetch fields for a current document
virtual void GetDocFields ( CSphVector<VecTraits_T<BYTE>> & dFields );
/// begin iterating kill list
virtual bool IterateKillListStart ( CSphString & sError ) = 0;
/// get next kill list doc id
virtual bool IterateKillListNext ( DocID_t & uDocId ) = 0;
/// post-index callback
/// gets called when the indexing is succesfully (!) over
virtual void PostIndex () {}
// returns false when there are no more documents
void BuildHits ( CSphString & sError, bool bSkipEndMarker );
/// field data getter
/// to be implemented by descendants
virtual BYTE ** NextDocument ( bool & bEOF, CSphString & sError ) = 0;
virtual const int * GetFieldLengths () const = 0;
CSphVector<int64_t> * GetFieldMVA ( int iAttr ) override;
const CSphString & GetStrAttr ( int iAttr ) override;
SphAttr_t GetAttr ( int iAttr ) override;
protected:
void ParseFieldMVA ( int iAttr, const char * szValue );
bool CheckFileField ( const BYTE * sField );
int LoadFileField ( BYTE ** ppField, CSphString & sError );
bool BuildZoneHits ( RowID_t tRowID, BYTE uCode );
void BuildSubstringHits ( RowID_t tRowID, bool bPayload, ESphWordpart eWordpart, int & iBlendedHitsStart );
void BuildRegularHits ( RowID_t tRowID, bool bPayload, int & iBlendedHitsStart );
/// register autocomputed attributes such as field lengths (see index_field_lengths)
bool AddAutoAttrs ( CSphString & sError, StrVec_t * pDefaults = nullptr );
/// allocate m_tDocInfo storage, do post-alloc magic (compute pointer to field lengths, etc)
void AllocDocinfo ();
protected:
ISphHits m_tHits; ///< my hitvector
protected:
char * m_pReadFileBuffer = nullptr;
int m_iReadFileBufferSize = 256*1024; ///< size of read buffer for the 'sql_file_field' fields
int m_iMaxFileBufferSize = 2*1024*1024; ///< max size of read buffer for the 'sql_file_field' fields
ESphOnFileFieldError m_eOnFileFieldError = FFE_IGNORE_FIELD;
FILE * m_fpDumpRows = nullptr;
int m_iPlainFieldsLength = 0;
DWORD * m_pFieldLengthAttrs = nullptr; ///< pointer into the part of m_tDocInfo where field lengths are stored
CSphVector<IDPair_t> m_dAllIds; ///< used for joined fields FIXME! unlimited RAM use
bool m_bIdsSorted = false; ///< we sort array to use binary search
protected:
struct CSphBuildHitsState_t
{
bool m_bProcessingHits;
bool m_bDocumentDone;
BYTE ** m_dFields;
CSphVector<int> m_dFieldLengths;
CSphVector<BYTE*> m_dTmpFieldStorage;
CSphVector<BYTE*> m_dTmpFieldPtrs;
CSphVector<BYTE> m_dFiltered;
int m_iStartPos;
Hitpos_t m_iHitPos;
int m_iField;
int m_iStartField;
int m_iEndField;
int m_iBuildLastStep;
CSphBuildHitsState_t ();
~CSphBuildHitsState_t ();
void Reset ();
};
CSphBuildHitsState_t m_tState;
int m_iMaxHits;
CSphVector<CSphVector<BYTE>> m_dDocFields;
protected:
StrVec_t m_dStrAttrs; ///< current document string attrs
CSphVector<CSphVector<int64_t>> m_dMvas; ///< per-attribute MVA storage
CSphVector<SphAttr_t> m_dAttrs;
TokenizerRefPtr_c m_pTokenizer; ///< my tokenizer
DictRefPtr_c m_pDict; ///< my dict
std::unique_ptr<ISphFieldFilter> m_pFieldFilter; ///< my field filter
CSphSourceStats m_tStats; ///< my stats
CSphSchema m_tSchema; ///< my schema
CSphHTMLStripper * m_pStripper = nullptr; ///< my HTML stripper
CSphBitvec m_tMorphFields;
};
| 8,984
|
C++
|
.h
| 200
| 42.755
| 180
| 0.73613
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,228
|
schema_configurator.h
|
manticoresoftware_manticoresearch/src/indexing_sources/schema_configurator.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
template < typename T >
struct CSphSchemaConfigurator
{
bool ConfigureAttrs ( const CSphVariant * pHead, ESphAttr eAttrType, CSphSchema & tSchema, CSphString & sError ) const
{
for ( const CSphVariant * pCur = pHead; pCur; pCur= pCur->m_pNext )
{
CSphColumnInfo tCol ( pCur->strval().cstr(), eAttrType );
char * pColon = strchr ( const_cast<char*> ( tCol.m_sName.cstr() ), ':' );
if ( pColon )
{
*pColon = '\0';
if ( eAttrType==SPH_ATTR_INTEGER )
{
int iBits = strtol ( pColon+1, NULL, 10 );
if ( iBits<=0 || iBits>ROWITEM_BITS )
{
sphWarn ( "%s", ((T*)const_cast<CSphSchemaConfigurator*>(this))->DecorateMessage ( "attribute '%s': invalid bitcount=%d (bitcount ignored)", tCol.m_sName.cstr(), iBits ) );
iBits = -1;
}
tCol.m_tLocator.m_iBitCount = iBits;
}
else
sphWarn ( "%s", ((T*)const_cast<CSphSchemaConfigurator*>(this))->DecorateMessage ( "attribute '%s': bitcount is only supported for integer types", tCol.m_sName.cstr() ) );
}
tCol.m_iIndex = tSchema.GetAttrsCount ();
if ( eAttrType==SPH_ATTR_UINT32SET || eAttrType==SPH_ATTR_INT64SET )
{
tCol.m_eAttrType = eAttrType;
tCol.m_eSrc = SPH_ATTRSRC_FIELD;
}
if ( !SchemaConfigureCheckAttribute ( tSchema, tCol, sError ) )
return false;
tSchema.AddAttr ( tCol, true ); // all attributes are dynamic at indexing time
}
return true;
}
void ConfigureFields ( const CSphVariant * pHead, bool bWordDict, CSphSchema & tSchema ) const
{
for ( const CSphVariant * pCur = pHead; pCur; pCur= pCur->m_pNext )
{
const char * sFieldName = pCur->strval().cstr();
bool bFound = false;
for ( int i = 0; i < tSchema.GetFieldsCount() && !bFound; i++ )
bFound = !strcmp ( tSchema.GetFieldName(i), sFieldName );
if ( bFound )
sphWarn ( "%s", ((T*)const_cast<CSphSchemaConfigurator*>(this))->DecorateMessage ( "duplicate field '%s'", sFieldName ) );
else
AddFieldToSchema ( sFieldName, bWordDict, tSchema );
}
}
void AddFieldToSchema ( const char * sFieldName, bool bWordDict, CSphSchema & tSchema ) const
{
CSphColumnInfo tCol ( sFieldName );
tCol.m_eWordpart = ((T*)const_cast<CSphSchemaConfigurator*>(this))->GetWordpart ( tCol.m_sName.cstr(), bWordDict );
tSchema.AddField ( tCol );
}
};
| 2,792
|
C++
|
.h
| 70
| 36.371429
| 178
| 0.680694
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,229
|
source_stats.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_stats.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
/// source statistics
struct CSphSourceStats
{
int64_t m_iTotalDocuments = 0; ///< how many documents
int64_t m_iTotalBytes = 0; ///< how many bytes
/// reset
void Reset()
{
m_iTotalDocuments = 0;
m_iTotalBytes = 0;
}
};
| 726
|
C++
|
.h
| 24
| 28.708333
| 80
| 0.728183
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,230
|
source_xmlpipe2.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_xmlpipe2.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "source_document.h"
#include "sphinxutils.h"
/// XMLPipe2 source fabric
CSphSource * sphCreateSourceXmlpipe2 ( const CSphConfigSection * pSource, FILE * pPipe, const char * szSourceName, int iMaxFieldLen, CSphString & sError );
| 729
|
C++
|
.h
| 16
| 44.375
| 155
| 0.76338
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,231
|
source_odbc.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_odbc.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
// source_odbc supports indexing both MSSQL (on windows), and ODBC (on others) via UnixODBC/iODBC library
#pragma once
#include "source_sql.h"
struct CSphSourceParams_ODBC: CSphSourceParams_SQL
{
CSphString m_sOdbcDSN; ///< ODBC DSN
CSphString m_sColBuffers; ///< column buffer sizes (eg "col1=2M, col2=4M")
bool m_bWinAuth = false; ///< auth type (MS SQL only)
};
/// ODBC source implementation
CSphSource * CreateSourceODBC ( const CSphSourceParams_ODBC & tParams, const char * sSourceName );
CSphSource * CreateSourceMSSQL ( const CSphSourceParams_ODBC & tParams, const char * sSourceName );
| 1,082
|
C++
|
.h
| 23
| 45.73913
| 105
| 0.75545
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,232
|
source_svpipe.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_svpipe.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "source_document.h"
#include "sphinxutils.h"
/// CSV/TSV pipe source fabric
CSphSource * sphCreateSourceTSVpipe ( const CSphConfigSection * pSource, FILE * pPipe, const char * sSourceName );
CSphSource * sphCreateSourceCSVpipe ( const CSphConfigSection * pSource, FILE * pPipe, const char * sSourceName );
| 807
|
C++
|
.h
| 17
| 46.294118
| 114
| 0.763659
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,233
|
source_mysql.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_mysql.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "source_sql.h"
/// MySQL source params
struct CSphSourceParams_MySQL : CSphSourceParams_SQL
{
CSphString m_sUsock; ///< UNIX socket
int m_iFlags; ///< connection flags
CSphString m_sSslKey;
CSphString m_sSslCert;
CSphString m_sSslCA;
CSphSourceParams_MySQL (); ///< ctor. sets defaults
};
/// MysqlSQL source implementation
CSphSource * CreateSourceMysql ( const CSphSourceParams_MySQL & tParams, const char * sSourceName );
| 944
|
C++
|
.h
| 25
| 36.32
| 100
| 0.753829
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,234
|
source_sql.h
|
manticoresoftware_manticoresearch/src/indexing_sources/source_sql.h
|
//
// Copyright (c) 2021-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "source_document.h"
#include "sphinxstd.h"
#include "tokenizer/tokenizer.h"
#include "sphinxdefs.h"
/// column unpack format
enum ESphUnpackFormat
{
SPH_UNPACK_NONE = 0,
SPH_UNPACK_ZLIB = 1,
SPH_UNPACK_MYSQL_COMPRESS = 2
};
using SqlEscapedBuilder_c = EscapedStringBuilder_T<BaseQuotation_T<SqlQuotator_t>>;
struct CSphUnpackInfo
{
ESphUnpackFormat m_eFormat;
CSphString m_sName;
};
struct CSphJoinedField
{
CSphString m_sName;
CSphString m_sQuery;
CSphString m_sRanged;
bool m_bPayload;
bool m_bRangedMain;
};
/// generic SQL source params
struct CSphSourceParams_SQL
{
// query params
CSphString m_sQuery;
CSphString m_sQueryRange;
CSphString m_sQueryKilllist;
int64_t m_iRangeStep = 1024;
int64_t m_iRefRangeStep = 1024;
bool m_bPrintQueries = false;
bool m_bPrintRTQueries = false;
CSphString m_sDumpRTIndex;
StrVec_t m_dQueryPre;
StrVec_t m_dQueryPreAll;
StrVec_t m_dQueryPost;
StrVec_t m_dQueryPostIndex;
CSphVector<CSphColumnInfo> m_dAttrs;
StrVec_t m_dFileFields;
int m_iRangedThrottleMs = 0;
int m_iMaxFileBufferSize = 0;
ESphOnFileFieldError m_eOnFileFieldError {FFE_IGNORE_FIELD};
CSphVector<CSphUnpackInfo> m_dUnpack;
DWORD m_uUnpackMemoryLimit = 0;
CSphVector<CSphJoinedField> m_dJoinedFields;
// connection params
CSphString m_sHost;
CSphString m_sUser;
CSphString m_sPass;
CSphString m_sDB;
unsigned int m_uPort = 0;
// hooks
CSphString m_sHookConnect;
CSphString m_sHookQueryRange;
CSphString m_sHookPostIndex;
};
/// generic SQL source
/// multi-field plain-text documents fetched from given query
struct CSphSource_SQL : CSphSource
{
explicit CSphSource_SQL ( const char * sName );
~CSphSource_SQL () override = default;
bool SetupSQL ( const CSphSourceParams_SQL & pParams );
bool Connect ( CSphString & sError ) override;
void Disconnect () override;
bool IterateStart ( CSphString & sError ) override;
BYTE ** NextDocument ( bool & bEOF, CSphString & sError ) override;
const int * GetFieldLengths () const override;
void PostIndex () override;
ISphHits * IterateJoinedHits ( CSphReader & tReader, CSphString & sError ) override;
bool FetchJoinedFields ( CSphAutofile & tFile, CSphVector<std::unique_ptr<OpenHashTable_T<uint64_t, uint64_t>>> & dJoinedOffsets, CSphString & sError ) override;
bool IterateMultivaluedStart ( int iAttr, CSphString & sError ) override;
bool IterateMultivaluedNext ( int64_t & iDocID, int64_t & iMvaValue ) override;
bool IterateKillListStart ( CSphString & sError ) override;
bool IterateKillListNext ( DocID_t & tDocId ) override;
protected:
static const int MACRO_COUNT = 2;
static const char * const MACRO_VALUES [ MACRO_COUNT ];
/// by what reason the internal SetupRanges called
enum ERangesReason
{
SRE_DOCS,
SRE_MVA,
SRE_JOINEDHITS
};
CSphString m_sSqlDSN;
BYTE * m_dFields [ SPH_MAX_FIELDS ] { nullptr };
int m_dFieldLengths [ SPH_MAX_FIELDS ];
ESphUnpackFormat m_dUnpack [ SPH_MAX_FIELDS ] { SPH_UNPACK_NONE };
DocID_t m_tMinID = 0; ///< grand min ID
DocID_t m_tMaxID = 0; ///< grand max ID
DocID_t m_tCurrentID = 0; ///< current min ID
DocID_t m_tMaxFetchedID = 0; ///< max actually fetched ID
int m_iMultiAttr = -1; ///< multi-valued attr being currently fetched
int m_iSqlFields = 0; ///< field count (for row dumper)
CSphSourceParams_SQL m_tParams;
bool m_bCanUnpack = false;
bool m_bUnpackFailed = false;
bool m_bUnpackOverflow = false;
CSphVector<char> m_dUnpackBuffers [ SPH_MAX_FIELDS ];
int m_iJoinedHitField = -1; ///< currently pulling joined hits from this field (index into schema; -1 if not pulling)
DocID_t m_iJoinedHitID = 0; ///< last document id
int m_iJoinedHitPos = 0; ///< last hit position
CSphVector<BYTE> m_dJoinedField;
BYTE * m_pJoinedFields = nullptr;
SphOffset_t m_iJoinedFileSize = 0;
using TinyCol_t = std::pair<int,bool>; // int idx in sql resultset; bool whether it is string
CSphVector<TinyCol_t> m_dDumpMap;
SqlEscapedBuilder_c m_sCollectDump;
int m_iCutoutDumpSize = 100*1024;
protected:
bool SetupRanges ( const char * sRangeQuery, const char * sQuery, const char * sPrefix, CSphString & sError, ERangesReason iReason );
bool RunQueryStep ( const char * sQuery, CSphString & sError );
virtual void SqlDismissResult () = 0;
virtual bool SqlQuery ( const char * sQuery ) = 0;
virtual bool SqlIsError () = 0;
virtual const char * SqlError () = 0;
virtual bool SqlConnect () = 0;
virtual void SqlDisconnect () = 0;
virtual int SqlNumFields() = 0;
virtual bool SqlFetchRow() = 0;
virtual DWORD SqlColumnLength ( int iIndex ) = 0;
virtual const char * SqlColumn ( int iIndex ) = 0;
virtual const char * SqlFieldName ( int iIndex ) = 0;
virtual Str_t SqlCompressedColumnStream ( int iFieldIndex );
virtual void SqlCompressedColumnReleaseStream ( Str_t tStream );
Str_t SqlColumnStream ( int iFieldIndex );
Str_t SqlUnpackColumn ( int iFieldIndex, ESphUnpackFormat eFormat );
void ReportUnpackError ( int iIndex, int iError );
void DumpRowsHeader();
void DumpRowsHeaderSphinxql();
void DumpDocument();
void DumpDocumentSphinxql();
bool QueryPreAll ( CSphString& sError) ;
private:
bool m_bSqlConnected = false; ///< am i connected?
bool StoreAttribute ( int iAttr );
};
| 6,049
|
C++
|
.h
| 154
| 37.233766
| 165
| 0.71692
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,235
|
aggregate_hit.h
|
manticoresoftware_manticoresearch/src/dict/aggregate_hit.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "sphinxdefs.h"
#include "sphinx.h"
/// aggregated hit info
struct AggregateHit_t
{
RowID_t m_tRowID { INVALID_ROWID }; ///< document ID
SphWordID_t m_uWordID { 0 }; ///< word ID in current dictionary
const BYTE* m_szKeyword { nullptr }; ///< word itself (in keywords dictionary case only)
Hitpos_t m_iWordPos { 0 }; ///< word position in current document, or hit count in case of aggregate hit
FieldMask_t m_dFieldMask; ///< mask of fields containing this word, 0 for regular hits, non-0 for aggregate hits
int GetAggrCount() const
{
assert ( !m_dFieldMask.TestAll ( false ) );
return m_iWordPos;
}
void SetAggrCount ( int iVal )
{
m_iWordPos = iVal;
}
};
| 1,180
|
C++
|
.h
| 32
| 35.1875
| 115
| 0.727034
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,236
|
dict_base.h
|
manticoresoftware_manticoresearch/src/dict/dict_base.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "sphinxstd.h"
#include "sphinxdefs.h"
#include "fileio.h"
#include "indexsettings.h"
class CSphWriter;
class JsonEscapedBuilder;
struct CSphEmbeddedFiles;
struct CSphWordforms;
struct CSphMultiformContainer;
struct DictHeader_t;
struct DictEntry_t;
extern CSphString g_sLemmatizerBase;
/////////////////////////////////////////////////////////////////////////////
// DICTIONARIES
/////////////////////////////////////////////////////////////////////////////
/// abstract word dictionary interface
class CSphDict: public ISphRefcountedMT
{
public:
enum ST_E : int {
ST_OK = 0,
ST_ERROR = 1,
ST_WARNING = 2,
};
public:
/// Get word ID by word, "text" version
/// may apply stemming and modify word inplace
/// modified word may become bigger than the original one, so make sure you have enough space in buffer which is pointer by pWord
/// a general practice is to use char[3*SPH_MAX_WORD_LEN+4] as a buffer
/// returns 0 for stopwords
virtual SphWordID_t GetWordID ( BYTE* pWord ) = 0;
/// get word ID by word, "text" version
/// may apply stemming and modify word inplace
/// accepts words with already prepended MAGIC_WORD_HEAD
/// appends MAGIC_WORD_TAIL
/// returns 0 for stopwords
virtual SphWordID_t GetWordIDWithMarkers ( BYTE* pWord ) { return GetWordID ( pWord ); }
/// get word ID by word, "text" version
/// does NOT apply stemming
/// accepts words with already prepended MAGIC_WORD_HEAD_NONSTEMMED
/// returns 0 for stopwords
virtual SphWordID_t GetWordIDNonStemmed ( BYTE* pWord ) { return GetWordID ( pWord ); }
/// get word ID by word, "binary" version
/// only used with prefix/infix indexing
/// must not apply stemming and modify anything
/// filters stopwords on request
virtual SphWordID_t GetWordID ( const BYTE* pWord, int iLen, bool bFilterStops ) = 0;
/// apply stemmers to the given word
virtual void ApplyStemmers ( BYTE* ) const {}
/// load stopwords from given files
virtual void LoadStopwords ( const char * sFiles, FilenameBuilder_i * pFilenameBuilder, const TokenizerRefPtr_c & pTokenizer, bool bStripFile ) = 0;
/// load stopwords from an array
virtual void LoadStopwords ( const CSphVector<SphWordID_t>& dStopwords ) = 0;
/// write stopwords to a file
virtual void WriteStopwords ( Writer_i & tWriter ) const = 0;
virtual void WriteStopwords ( JsonEscapedBuilder& tOut ) const = 0;
/// load wordforms from a given list of files
virtual bool LoadWordforms ( const StrVec_t&, const CSphEmbeddedFiles* pEmbedded, const TokenizerRefPtr_c& pTokenizer, const char* szIndex ) = 0;
/// write wordforms to a file
virtual void WriteWordforms ( Writer_i & tWriter ) const = 0;
virtual void WriteWordforms ( JsonEscapedBuilder& tOut ) const = 0;
/// get wordforms
virtual const CSphWordforms* GetWordforms() { return nullptr; }
/// disable wordforms processing
virtual void DisableWordforms() {}
/// set morphology
/// returns 0 on success, 1 on hard error, 2 on a warning (see ST_xxx constants)
virtual int SetMorphology ( const char* szMorph, CSphString& sMessage ) = 0;
/// are there any morphological processors?
virtual bool HasMorphology() const { return false; }
/// morphological data fingerprint (lemmatizer filenames and crc32s)
virtual const CSphString& GetMorphDataFingerprint() const { return m_sMorphFingerprint; }
/// setup dictionary using settings
virtual void Setup ( const CSphDictSettings& tSettings ) = 0;
/// get dictionary settings
virtual const CSphDictSettings& GetSettings() const = 0;
/// stopwords file infos
virtual const CSphVector<CSphSavedFile>& GetStopwordsFileInfos() const = 0;
/// wordforms file infos
virtual const CSphVector<CSphSavedFile>& GetWordformsFileInfos() const = 0;
/// get multiwordforms
virtual const CSphMultiformContainer* GetMultiWordforms() const = 0;
/// check what given word is stopword
virtual bool IsStopWord ( const BYTE* pWord ) const = 0;
public:
virtual void SetSkiplistBlockSize ( int iSize ) {}
/// enable actually collecting keywords (needed for stopwords/wordforms loading)
virtual void HitblockBegin() {}
/// callback to let dictionary do hit block post-processing
virtual void HitblockPatch ( CSphWordHit*, int ) const {}
/// resolve temporary hit block wide wordid (!) back to keyword
virtual const char* HitblockGetKeyword ( SphWordID_t ) { return nullptr; }
/// check current memory usage
virtual int HitblockGetMemUse() { return 0; }
/// hit block dismissed
virtual void HitblockReset() {}
public:
/// begin creating dictionary file, setup any needed internal structures
virtual void DictBegin ( CSphAutofile& tTempDict, CSphAutofile& tDict, int iDictLimit );
/// begin creating dictionary file, assuming sorted entries came (when processing ready dicts like merge, add/delete field, etc.)
virtual void SortedDictBegin ( CSphAutofile& tDict, int iDictLimit, int iInfixCodepointBytes );
/// add next keyword entry to final dict
virtual void DictEntry ( const DictEntry_t& tEntry );
/// flush last entry
virtual void DictEndEntries ( SphOffset_t iDoclistOffset );
/// end indexing, store dictionary and checkpoints
virtual bool DictEnd ( DictHeader_t* pHeader, int iMemLimit, CSphString& sError );
/// check whether there were any errors during indexing
virtual bool DictIsError() const;
public:
/// check whether this dict is stateful (when it comes to lookups)
virtual bool HasState() const { return false; }
/// make a clone
virtual DictRefPtr_c Clone() const { return nullptr; }
/// get settings hash
virtual uint64_t GetSettingsFNV() const = 0;
protected:
CSphString m_sMorphFingerprint;
};
using DictRefPtr_c = CSphRefcountedPtr<CSphDict>;
class DictStub_c: public CSphDict
{
protected:
CSphVector<CSphSavedFile> m_dSWFileInfos;
CSphVector<CSphSavedFile> m_dWFFileInfos;
CSphDictSettings m_tSettings;
public:
SphWordID_t GetWordID ( BYTE* ) override { return 0; }
SphWordID_t GetWordID ( const BYTE*, int, bool ) override { return 0; };
void LoadStopwords ( const char * , FilenameBuilder_i * , const TokenizerRefPtr_c& , bool ) override {};
void LoadStopwords ( const CSphVector<SphWordID_t>& ) override {};
void WriteStopwords ( Writer_i & ) const override {};
void WriteStopwords ( JsonEscapedBuilder& ) const override {};
bool LoadWordforms ( const StrVec_t&, const CSphEmbeddedFiles*, const TokenizerRefPtr_c&, const char* ) override { return false; };
void WriteWordforms ( Writer_i & ) const override {};
void WriteWordforms ( JsonEscapedBuilder& ) const override {};
int SetMorphology ( const char*, CSphString& ) override { return ST_OK; }
void Setup ( const CSphDictSettings& tSettings ) override { m_tSettings = tSettings; };
const CSphDictSettings& GetSettings() const override { return m_tSettings; }
const CSphVector<CSphSavedFile>& GetStopwordsFileInfos() const override { return m_dSWFileInfos; }
const CSphVector<CSphSavedFile>& GetWordformsFileInfos() const override { return m_dWFFileInfos; }
const CSphMultiformContainer* GetMultiWordforms() const override { return nullptr; };
bool IsStopWord ( const BYTE* ) const override { return false; };
uint64_t GetSettingsFNV() const override { return 0; };
};
void SetupDictionary ( DictRefPtr_c& pDict, const CSphDictSettings& tSettings, const CSphEmbeddedFiles* pFiles, const TokenizerRefPtr_c& pTokenizer, const char* szIndex, bool bStripFile, FilenameBuilder_i* pFilenameBuilder, CSphString& sError );
/// returns pDict, if stateless. Or it's clone, if not
DictRefPtr_c GetStatelessDict ( const DictRefPtr_c& pDict );
/// CRC32/FNV64 dictionary factory
DictRefPtr_c sphCreateDictionaryCRC ( const CSphDictSettings& tSettings, const CSphEmbeddedFiles* pFiles, const TokenizerRefPtr_c& pTokenizer, const char* szIndex, bool bStripFile, int iSkiplistBlockSize, FilenameBuilder_i* pFilenameBuilder, CSphString& sError );
/// keyword-storing dictionary factory
DictRefPtr_c sphCreateDictionaryKeywords ( const CSphDictSettings& tSettings, const CSphEmbeddedFiles* pFiles, const TokenizerRefPtr_c& pTokenizer, const char* szIndex, bool bStripFile, int iSkiplistBlockSize, FilenameBuilder_i* pFilenameBuilder, CSphString& sError );
/// exact dict
void SetupExactDict ( DictRefPtr_c& pDict );
/// star dict old format (pre v8)
void SetupStarDictOld ( DictRefPtr_c& pDict );
/// star dict v8
void SetupStarDictV8 ( DictRefPtr_c& pDict, bool bInfixes = true );
/// clear wordform cache
void sphShutdownWordforms();
void SetupLemmatizerBase();
| 8,968
|
C++
|
.h
| 173
| 49.83815
| 268
| 0.756952
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,237
|
dict_entry.h
|
manticoresoftware_manticoresearch/src/dict/dict_entry.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "sphinxstd.h"
/// dictionary entry
/// some of the fields might be unused depending on specific dictionary type
struct DictEntry_t
{
SphWordID_t m_uWordID = 0; ///< keyword id (for dict=crc)
const BYTE* m_szKeyword = nullptr; ///< keyword text (for dict=keywords)
int m_iDocs = 0; ///< number of matching documents
int m_iHits = 0; ///< number of occurrences
SphOffset_t m_iDoclistOffset = 0; ///< absolute document list offset (into .spd)
SphOffset_t m_iDoclistLength = 0; ///< document list length in bytes
SphOffset_t m_iSkiplistOffset = 0; ///< absolute skiplist offset (into .spe)
int m_iDoclistHint = 0; ///< raw document list length hint value (0..255 range, 1 byte)
};
| 1,207
|
C++
|
.h
| 26
| 45.038462
| 93
| 0.719254
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,238
|
template_dict_traits.h
|
manticoresoftware_manticoresearch/src/dict/template_dict_traits.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "dict_base.h"
class LemmatizerTrait_i;
struct TemplateDictTraits_c: DictStub_c
{
TemplateDictTraits_c();
protected:
~TemplateDictTraits_c() override;
public:
void LoadStopwords ( const char * sFiles, FilenameBuilder_i * pFilenameBuilder, const TokenizerRefPtr_c & pTokenizer, bool bStripFile ) final;
void LoadStopwords ( const CSphVector<SphWordID_t>& dStopwords ) final;
void WriteStopwords ( Writer_i & tWriter ) const final;
void WriteStopwords ( JsonEscapedBuilder& tOut ) const final;
bool LoadWordforms ( const StrVec_t& dFiles, const CSphEmbeddedFiles* pEmbedded, const TokenizerRefPtr_c& pTokenizer, const char* szIndex ) final;
void WriteWordforms ( Writer_i & tWriter ) const final;
void WriteWordforms ( JsonEscapedBuilder& tOut ) const final;
const CSphWordforms* GetWordforms() final { return m_pWordforms; }
void DisableWordforms() final { m_bDisableWordforms = true; }
int SetMorphology ( const char* szMorph, CSphString& sMessage ) final;
bool HasMorphology() const final;
void ApplyStemmers ( BYTE* pWord ) const final;
const CSphMultiformContainer* GetMultiWordforms() const final;
uint64_t GetSettingsFNV() const final;
static void SweepWordformContainers ( const CSphVector<CSphSavedFile>& dFiles );
protected:
CSphVector<int> m_dMorph;
#if WITH_STEMMER
CSphVector<void*> m_dStemmers; // avoid to poison namespace with sb_stemmer*, use void*
StrVec_t m_dDescStemmers;
#endif
std::unique_ptr<LemmatizerTrait_i> m_tLemmatizer;
int m_iStopwords = 0; ///< stopwords count
SphWordID_t* m_pStopwords = nullptr; ///< stopwords ID list
CSphFixedVector<SphWordID_t> m_dStopwordContainer {0};
protected:
int ParseMorphology ( const char* szMorph, CSphString& sError );
SphWordID_t FilterStopword ( SphWordID_t uID ) const; ///< filter ID against stopwords list
DictRefPtr_c CloneBase ( TemplateDictTraits_c* pDict ) const;
bool HasState() const final;
bool m_bDisableWordforms = false;
private:
CSphWordforms* m_pWordforms = nullptr;
static CSphVector<CSphWordforms*> m_dWordformContainers;
CSphWordforms* GetWordformContainer ( const CSphVector<CSphSavedFile>& dFileInfos, const StrVec_t* pEmbeddedWordforms, const TokenizerRefPtr_c& pTokenizer, const char* szIndex );
CSphWordforms* LoadWordformContainer ( const CSphVector<CSphSavedFile>& dFileInfos, const StrVec_t* pEmbeddedWordforms, const TokenizerRefPtr_c& pTokenizer, const char* szIndex );
int InitMorph ( const char* szMorph, int iLength, CSphString& sError );
int AddMorph ( int iMorph ); ///< helper that always returns ST_OK
bool StemById ( BYTE* pWord, int iStemmer ) const;
void AddWordform ( CSphWordforms* pContainer, char* sBuffer, int iLen, const TokenizerRefPtr_c& pTokenizer, const char* szFile, const CSphVector<int>& dBlended, int iFileId );
};
| 3,280
|
C++
|
.h
| 61
| 51.967213
| 180
| 0.782663
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,239
|
dict_crc_impl.h
|
manticoresoftware_manticoresearch/src/dict/dict_crc_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
//////////////////////////////////////////////////////////////////////////
template<CRCALGO ALGO>
SphWordID_t CSphDictCRC<ALGO>::GetWordID ( BYTE* pWord )
{
// apply stopword filter before stemmers
if ( GetSettings().m_bStopwordsUnstemmed && !FilterStopword ( tHASH::DoCrc ( pWord ) ) )
return 0;
// skip stemmers for magic words
if ( pWord[0] >= 0x20 )
ApplyStemmers ( pWord );
// stemmer might squeeze out the word
if ( !pWord[0] )
return 0;
return GetSettings().m_bStopwordsUnstemmed
? tHASH::DoCrc ( pWord )
: FilterStopword ( tHASH::DoCrc ( pWord ) );
}
template<CRCALGO ALGO>
SphWordID_t CSphDictCRC<ALGO>::GetWordID ( const BYTE* pWord, int iLen, bool bFilterStops )
{
SphWordID_t uId = tHASH::DoCrc ( pWord, iLen );
return bFilterStops ? FilterStopword ( uId ) : uId;
}
template<CRCALGO ALGO>
SphWordID_t CSphDictCRC<ALGO>::GetWordIDWithMarkers ( BYTE* pWord )
{
ApplyStemmers ( pWord + 1 );
SphWordID_t uWordId = tHASH::DoCrc ( pWord + 1 );
auto iLength = strlen ( (const char*)( pWord + 1 ) );
pWord[iLength + 1] = MAGIC_WORD_TAIL;
pWord[iLength + 2] = '\0';
return FilterStopword ( uWordId ) ? tHASH::DoCrc ( pWord ) : 0;
}
template<CRCALGO ALGO>
SphWordID_t CSphDictCRC<ALGO>::GetWordIDNonStemmed ( BYTE* pWord )
{
// this method can generally receive both '=stopword' with a marker and 'stopword' without it
// so for filtering stopwords, let's handle both
int iOff = ( pWord[0] < ' ' );
SphWordID_t uWordId = tHASH::DoCrc ( pWord + iOff );
if ( !FilterStopword ( uWordId ) )
return 0;
return tHASH::DoCrc ( pWord );
}
template<CRCALGO ALGO>
bool CSphDictCRC<ALGO>::IsStopWord ( const BYTE* pWord ) const
{
return FilterStopword ( tHASH::DoCrc ( pWord ) ) == 0;
}
| 2,219
|
C++
|
.h
| 61
| 34.491803
| 94
| 0.693744
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,240
|
word_forms.h
|
manticoresoftware_manticoresearch/src/dict/word_forms.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "fileutils.h"
#include "sphinxstd.h"
struct CSphMultiformContainer;
struct CSphStoredNF
{
CSphString m_sWord;
bool m_bAfterMorphology;
};
/// wordforms container
struct CSphWordforms
{
int m_iRefCount = 0;
CSphVector<CSphSavedFile> m_dFiles;
uint64_t m_uTokenizerFNV = 0;
CSphString m_sIndexName;
bool m_bHavePostMorphNF = false;
CSphVector<CSphStoredNF> m_dNormalForms;
std::unique_ptr<CSphMultiformContainer> m_pMultiWordforms;
CSphOrderedHash<int, CSphString, CSphStrHashFunc, 1048576> m_hHash;
~CSphWordforms();
bool IsEqual ( const CSphVector<CSphSavedFile>& dFiles );
bool ToNormalForm ( BYTE* pWord, bool bBefore, bool bOnlyCheck ) const;
};
| 1,165
|
C++
|
.h
| 35
| 31.742857
| 80
| 0.782028
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,241
|
dict_proxy.h
|
manticoresoftware_manticoresearch/src/dict/dict_proxy.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "dict_base.h"
/// dict traits
class DictProxy_c: public CSphDict
{
public:
explicit DictProxy_c ( DictRefPtr_c pDict )
: m_pDict { std::move ( pDict ) }
{}
// that is only one should be overridden
SphWordID_t GetWordID ( BYTE* pWord ) override { return m_pDict->GetWordID ( pWord ); }
SphWordID_t GetWordIDWithMarkers ( BYTE* pWord ) final { return m_pDict->GetWordIDWithMarkers ( pWord ); }
SphWordID_t GetWordIDNonStemmed ( BYTE* pWord ) final { return m_pDict->GetWordIDNonStemmed ( pWord ); }
SphWordID_t GetWordID ( const BYTE* pWord, int iLen, bool bFilterStops ) final { return m_pDict->GetWordID ( pWord, iLen, bFilterStops ); }
void ApplyStemmers ( BYTE* pWord ) const final { m_pDict->ApplyStemmers ( pWord ); }
void LoadStopwords ( const char * sFiles, FilenameBuilder_i * pFilenameBuilder, const TokenizerRefPtr_c& pTokenizer, bool bStripFile ) final { m_pDict->LoadStopwords ( sFiles, pFilenameBuilder, pTokenizer, bStripFile ); }
void LoadStopwords ( const CSphVector<SphWordID_t>& dStopwords ) final { m_pDict->LoadStopwords ( dStopwords ); }
void WriteStopwords ( Writer_i & tWriter ) const final { m_pDict->WriteStopwords ( tWriter ); }
void WriteStopwords ( JsonEscapedBuilder& tOut ) const final { m_pDict->WriteStopwords ( tOut ); }
bool LoadWordforms ( const StrVec_t& dFiles, const CSphEmbeddedFiles* pEmbedded, const TokenizerRefPtr_c& pTokenizer, const char* szIndex ) final { return m_pDict->LoadWordforms ( dFiles, pEmbedded, pTokenizer, szIndex ); }
void WriteWordforms ( Writer_i & tWriter ) const final { m_pDict->WriteWordforms ( tWriter ); }
void WriteWordforms ( JsonEscapedBuilder& tOut ) const final { m_pDict->WriteWordforms ( tOut ); }
const CSphWordforms* GetWordforms() final { return m_pDict->GetWordforms(); }
void DisableWordforms() final { m_pDict->DisableWordforms(); }
int SetMorphology ( const char* szMorph, CSphString& sMessage ) final { return m_pDict->SetMorphology ( szMorph, sMessage ); }
bool HasMorphology() const override{ return m_pDict->HasMorphology(); }
const CSphString& GetMorphDataFingerprint() const override { return m_pDict->GetMorphDataFingerprint(); }
void Setup ( const CSphDictSettings& ) final {} /// notice!
const CSphDictSettings& GetSettings() const final { return m_pDict->GetSettings(); }
const CSphVector<CSphSavedFile>& GetStopwordsFileInfos() const final { return m_pDict->GetStopwordsFileInfos(); }
const CSphVector<CSphSavedFile>& GetWordformsFileInfos() const final { return m_pDict->GetWordformsFileInfos(); }
const CSphMultiformContainer* GetMultiWordforms() const final { return m_pDict->GetMultiWordforms(); }
bool IsStopWord ( const BYTE* pWord ) const final { return m_pDict->IsStopWord ( pWord ); }
public:
void SetSkiplistBlockSize ( int iSize ) final { m_pDict->SetSkiplistBlockSize ( iSize ); }
void HitblockBegin() final { m_pDict->HitblockBegin(); }
void HitblockPatch ( CSphWordHit* pHits, int iHits ) const final { m_pDict->HitblockPatch ( pHits, iHits ); }
const char* HitblockGetKeyword ( SphWordID_t tWordID ) final { return m_pDict->HitblockGetKeyword ( tWordID ); }
int HitblockGetMemUse() final { return m_pDict->HitblockGetMemUse(); }
void HitblockReset() final { m_pDict->HitblockReset(); }
public:
void DictBegin ( CSphAutofile& tTempDict, CSphAutofile& tDict, int iDictLimit ) final { m_pDict->DictBegin ( tTempDict, tDict, iDictLimit ); };
void SortedDictBegin ( CSphAutofile& tDict, int iDictLimit, int iInfixCodepointBytes ) final { m_pDict->SortedDictBegin ( tDict, iDictLimit, iInfixCodepointBytes ); };
void DictEntry ( const DictEntry_t& tEntry ) final { m_pDict->DictEntry ( tEntry ); };
void DictEndEntries ( SphOffset_t iDoclistOffset ) final { m_pDict->DictEndEntries ( iDoclistOffset ); };
bool DictEnd ( DictHeader_t* pHeader, int iMemLimit, CSphString& sError ) final { return m_pDict->DictEnd ( pHeader, iMemLimit, sError ); };
bool DictIsError() const final { return m_pDict->DictIsError(); };
public:
bool HasState() const final {
return m_pDict->HasState();
}
DictRefPtr_c Clone() const final {
return DictRefPtr_c { new DictProxy_c ( m_pDict->Clone() ) };
}
uint64_t GetSettingsFNV() const final { return m_pDict->GetSettingsFNV(); }
protected:
DictRefPtr_c m_pDict;
};
| 4,748
|
C++
|
.h
| 69
| 66.971014
| 224
| 0.749732
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,242
|
dict_crc.h
|
manticoresoftware_manticoresearch/src/dict/dict_crc.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "template_dict_traits.h"
#include "crc_engine.h"
#include "indexformat.h"
/////////////////////////////////////////////////////////////////////////////
// CRC32/64 DICTIONARIES
/////////////////////////////////////////////////////////////////////////////
/// common CRC32/64 dictionary stuff
struct DiskDictTraits_c: TemplateDictTraits_c
{
void DictBegin ( CSphAutofile& tTempDict, CSphAutofile& tDict, int iDictLimit ) override;
void SortedDictBegin ( CSphAutofile& tDict, int iDictLimit, int iInfixCodepointBytes ) override;
void DictEntry ( const DictEntry_t& tEntry ) override;
void DictEndEntries ( SphOffset_t iDoclistOffset ) override;
bool DictEnd ( DictHeader_t* pHeader, int iMemLimit, CSphString& sError ) override;
bool DictIsError() const final { return m_wrDict.IsError(); }
void SetSkiplistBlockSize ( int iSize ) final { m_iSkiplistBlockSize = iSize; }
protected:
~DiskDictTraits_c() override = default; // fixme! remove
protected:
CSphTightVector<CSphWordlistCheckpoint> m_dCheckpoints; ///< checkpoint offsets
CSphWriter m_wrDict; ///< final dict file writer
CSphString m_sWriterError; ///< writer error message storage
int m_iEntries = 0; ///< dictionary entries stored
SphOffset_t m_iLastDoclistPos = 0;
SphWordID_t m_iLastWordID = 0;
int m_iSkiplistBlockSize = 0;
};
/// specialized CRC32/64 implementations
template<CRCALGO ALGO>
struct CSphDictCRC: public DiskDictTraits_c
, CCRCEngine<ALGO>
{
typedef CCRCEngine<ALGO> tHASH;
SphWordID_t GetWordID ( BYTE* pWord ) override;
SphWordID_t GetWordID ( const BYTE* pWord, int iLen, bool bFilterStops ) override;
SphWordID_t GetWordIDWithMarkers ( BYTE* pWord ) override;
SphWordID_t GetWordIDNonStemmed ( BYTE* pWord ) override;
bool IsStopWord ( const BYTE* pWord ) const final;
DictRefPtr_c Clone() const override { return CloneBase ( new CSphDictCRC<ALGO>() ); }
protected:
~CSphDictCRC() override = default; // fixme! remove
};
#include "dict_crc_impl.h"
| 2,483
|
C++
|
.h
| 55
| 43.509091
| 97
| 0.71535
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,243
|
bin.h
|
manticoresoftware_manticoresearch/src/dict/bin.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "indexsettings.h"
#include "aggregate_hit.h"
/// possible bin states
enum ESphBinState {
BIN_ERR_READ = -2, ///< bin read error
BIN_ERR_END = -1, ///< bin end
BIN_POS = 0, ///< bin is in "expects pos delta" state
BIN_DOC = 1, ///< bin is in "expects doc delta" state
BIN_WORD = 2 ///< bin is in "expects word delta" state
};
enum ESphBinRead {
BIN_READ_OK, ///< bin read ok
BIN_READ_EOF, ///< bin end
BIN_READ_ERROR, ///< bin read error
BIN_PRECACHE_OK, ///< precache ok
BIN_PRECACHE_ERROR ///< precache failed
};
/// bin, block input buffer
struct CSphBin
{
static const int MIN_SIZE = 8192;
static const int WARN_SIZE = 262144;
protected:
ESphHitless m_eMode;
CSphFixedVector<BYTE> m_dBuffer {0};
BYTE* m_pCurrent = nullptr;
int m_iLeft = 0;
int m_iDone = 0;
ESphBinState m_eState { BIN_POS };
bool m_bWordDict;
bool m_bError = false; // FIXME? sort of redundant, but states are a mess
AggregateHit_t m_tHit; ///< currently decoded hit
std::array<BYTE, MAX_KEYWORD_BYTES> m_sKeyword; ///< currently decoded hit keyword (in keywords dict mode)
#ifndef NDEBUG
SphWordID_t m_iLastWordID = 0;
std::array<BYTE, MAX_KEYWORD_BYTES> m_sLastKeyword;
#endif
int m_iFile = -1; ///< my file
SphOffset_t* m_pFilePos = nullptr; ///< shared current offset in file
public:
SphOffset_t m_iFilePos = 0; ///< my current offset in file
int m_iFileLeft = 0; ///< how much data is still unread from the file
public:
explicit CSphBin ( ESphHitless eMode = SPH_HITLESS_NONE, bool bWordDict = false );
static int CalcBinSize ( int iMemoryLimit, int iBlocks, const char* sPhase );
void Init ( int iFD, SphOffset_t* pSharedOffset, const int iBinSize );
SphWordID_t ReadVLB();
int ReadByte();
ESphBinRead ReadBytes ( void* pDest, int iBytes );
int ReadHit ( AggregateHit_t* pOut );
DWORD UnzipInt();
SphOffset_t UnzipOffset();
bool IsEOF() const;
bool IsDone() const;
bool IsError() const
{
return m_bError;
}
ESphBinRead Precache();
};
| 2,500
|
C++
|
.h
| 72
| 32.875
| 107
| 0.712272
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,244
|
crc_engine_impl.h
|
manticoresoftware_manticoresearch/src/dict/crc_engine_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
/////////////////////////////////////////////////////////////////////////////
#include "sphinx.h"
template<>
inline SphWordID_t CCRCEngine<CRCALGO::CRC32>::DoCrc ( const BYTE* pWord )
{
return sphCRC32 ( pWord );
}
template<>
inline SphWordID_t CCRCEngine<CRCALGO::FNV64>::DoCrc ( const BYTE* pWord )
{
return (SphWordID_t)sphFNV64 ( pWord );
}
template<>
inline SphWordID_t CCRCEngine<CRCALGO::CRC32>::DoCrc ( const BYTE* pWord, int iLen )
{
return sphCRC32 ( pWord, iLen );
}
template<>
inline SphWordID_t CCRCEngine<CRCALGO::FNV64>::DoCrc ( const BYTE* pWord, int iLen )
{
return (SphWordID_t)sphFNV64 ( pWord, iLen );
}
| 1,125
|
C++
|
.h
| 34
| 31.705882
| 84
| 0.693161
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,245
|
crc_engine.h
|
manticoresoftware_manticoresearch/src/dict/crc_engine.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "sphinxdefs.h"
enum class CRCALGO {
CRC32, // true
FNV64 // false
};
template<CRCALGO>
struct CCRCEngine
{
inline static SphWordID_t DoCrc ( const BYTE* pWord );
inline static SphWordID_t DoCrc ( const BYTE* pWord, int iLen );
};
#include "crc_engine_impl.h"
| 766
|
C++
|
.h
| 24
| 30.5
| 80
| 0.75
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,246
|
infix_builder.h
|
manticoresoftware_manticoresearch/src/dict/infix/infix_builder.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/ints.h"
#include "fileio.h"
static constexpr Str_t g_sTagInfixBlocks = FROMS ( "infix-blocks" );
static constexpr Str_t g_sTagInfixEntries = FROMS ( "infix-entries" );
static constexpr Str_t g_sTagDictHeader = FROMS ( "dict-header" );
struct InfixBlock_t
{
union {
const char* m_sInfix;
DWORD m_iInfixOffset;
};
DWORD m_iOffset;
};
/// infix hash builder
class ISphInfixBuilder
{
public:
explicit ISphInfixBuilder() {}
virtual ~ISphInfixBuilder() {}
virtual void AddWord ( const BYTE* pWord, int iWordLength, int iCheckpoint, bool bHasMorphology ) = 0;
virtual void SaveEntries ( CSphWriter& wrDict ) = 0;
virtual int64_t SaveEntryBlocks ( CSphWriter& wrDict ) = 0;
virtual int GetBlocksWordsSize() const = 0;
};
std::unique_ptr<ISphInfixBuilder> sphCreateInfixBuilder ( int iCodepointBytes, CSphString* pError );
bool sphLookupInfixCheckpoints ( const char* sInfix, int iBytes, const BYTE* pInfixes, const CSphVector<InfixBlock_t>& dInfixBlocks, int iInfixCodepointBytes, CSphVector<DWORD>& dCheckpoints );
| 1,529
|
C++
|
.h
| 38
| 38.736842
| 193
| 0.765657
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,248
|
html_stripper_tag.h
|
manticoresoftware_manticoresearch/src/stripper/html_stripper_tag.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "sphinxstd.h"
namespace html_stripper {
struct StripperTag_t
{
CSphString m_sTag; ///< tag name
int m_iTagLen = 0; ///< tag name length
bool m_bInline = false; ///< whether this tag is inline
bool m_bIndexAttrs = false; ///< whether to index attrs
bool m_bRemove = false; ///< whether to remove contents
bool m_bPara = false; ///< whether to mark a paragraph boundary
bool m_bZone = false; ///< whether to mark a zone boundary
bool m_bZonePrefix = false; ///< whether the zone name is a full name or a prefix
StrVec_t m_dAttrs; ///< attr names to index
};
inline bool operator< ( const StripperTag_t& lhs, const StripperTag_t& rhs )
{
return strcmp ( lhs.m_sTag.cstr(), rhs.m_sTag.cstr() ) < 0;
}
}
| 1,223
|
C++
|
.h
| 31
| 37.935484
| 82
| 0.717538
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,249
|
html_stripper.h
|
manticoresoftware_manticoresearch/src/stripper/html_stripper.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "sphinxstd.h"
#include "html_stripper_tag.h"
/// HTML stripper
class CSphHTMLStripper
{
public:
explicit CSphHTMLStripper ( bool bDefaultTags );
bool SetIndexedAttrs ( const char* sConfig, CSphString& sError );
bool SetRemovedElements ( const char* sConfig, CSphString& sError );
bool SetZones ( const char* sZones, CSphString& sError );
void EnableParagraphs();
void Strip ( BYTE* sData ) const;
public:
/// finds appropriate tag and zone name ( tags zone name could be prefix only )
/// advances source to the end of the tag
const BYTE* FindTag ( const BYTE* sSrc, const html_stripper::StripperTag_t** ppTag, const BYTE** ppZoneName, int* pZoneNameLen ) const;
bool IsValidTagStart ( int iCh ) const;
private:
static const int MAX_CHAR_INDEX = 28; ///< max valid char index (a-z, underscore, colon)
CSphVector<html_stripper::StripperTag_t> m_dTags; ///< known tags to index attrs and/or to remove contents
int m_dStart[MAX_CHAR_INDEX]; ///< maps index of the first tag name char to start offset in m_dTags
int m_dEnd[MAX_CHAR_INDEX]; ///< maps index of the first tag name char to end offset in m_dTags
int GetCharIndex ( int iCh ) const; ///< calcs index by raw char
void UpdateTags(); ///< sorts tags, updates internal helpers
};
| 1,765
|
C++
|
.h
| 37
| 46.081081
| 136
| 0.742592
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,251
|
log_management.h
|
manticoresoftware_manticoresearch/src/http/log_management.h
|
static nljson GetSystemTable()
{
nljson tSystemTable = R"({})"_json;
tSystemTable["_xpack"] =
R"(
{
"license": {
"type": "basic",
"mode": "basic",
"status": "active"
},
"features": {
"analytics": {
"available": false,
"enabled": false
},
"ccr": {
"available": false,
"enabled": false
},
"data_frame": {
"available": false,
"enabled": false
},
"flattened": {
"available": false,
"enabled": true
},
"frozen_indices": {
"available": false,
"enabled": false
},
"graph": {
"available": false,
"enabled": false
},
"ilm": {
"available": false,
"enabled": false
},
"logstash": {
"available": true,
"enabled": true
},
"ml": {
"available": false,
"enabled": false
},
"monitoring": {
"available": false,
"enabled": false
},
"rollup": {
"available": false,
"enabled": false
},
"security": {
"available": false,
"enabled": false
},
"spatial": {
"available": false,
"enabled": false
},
"sql": {
"available": true,
"enabled": true
},
"vectors": {
"available": false,
"enabled": false
},
"voting_only": {
"available": false,
"enabled": false
},
"watcher": {
"available": false,
"enabled": false
}
},
"tagline": "You know, for X"
}
)"_json;
tSystemTable["_cluster"] =
R"(
{
"settings" : {
"persistent": {},
"transient": {},
"defaults": {}
}
}
)"_json;
tSystemTable["_nodes"] =
R"(
{
}
)"_json;
tSystemTable["master"] =
R"(
{
}
)"_json;
tSystemTable["templates"] = R"({})"_json;
return tSystemTable;
}
| 1,776
|
C++
|
.h
| 107
| 11.934579
| 41
| 0.504819
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,252
|
receiver_ctx.h
|
manticoresoftware_manticoresearch/src/replication/receiver_ctx.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "wsrep_cxx.h"
// returns main receiver which will take and apply replication commands from remote nodes
Wsrep::Receiver_i* MakeReceiverCtx ( CSphString sName, Wsrep::Provider_i * pProvider, std::function<void()> fnOnClean );
| 628
|
C++
|
.h
| 13
| 47.076923
| 120
| 0.763072
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,253
|
cluster_commands.h
|
manticoresoftware_manticoresearch/src/replication/cluster_commands.h
|
//
// Copyright (c) 2023-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "searchdaemon.h"
void ReceiveClusterDelete ( ISphOutputBuffer& tOut, InputBuffer_c& tBuf, CSphString& sCluster );
void ReceiveClusterFileReserve ( ISphOutputBuffer& tOut, InputBuffer_c& tBuf, CSphString& sCluster );
void ReceiveClusterGetNodes ( ISphOutputBuffer& tOut, InputBuffer_c& tBuf, CSphString& sCluster );
void ReceiveClusterIndexAddLocal ( ISphOutputBuffer& tOut, InputBuffer_c& tBuf, CSphString& sCluster );
void ReceiveClusterSynced ( ISphOutputBuffer& tOut, InputBuffer_c& tBuf, CSphString& sCluster );
void ReceiveClusterUpdateNodes ( ISphOutputBuffer& tOut, InputBuffer_c& tBuf, CSphString& sCluster );
void ReceiveClusterGetState ( ISphOutputBuffer & tOut, InputBuffer_c & tBuf, CSphString & sCluster );
void ReceiveClusterGetVer ( ISphOutputBuffer & tOut );
// sending doesn't include cluster name
void ReceiveClusterFileSend ( ISphOutputBuffer& tOutb, InputBuffer_c& tBuf );
void ReceiveDistIndex ( ISphOutputBuffer & tOut, InputBuffer_c & tBuf, CSphString & sCluster );
| 1,490
|
C++
|
.h
| 24
| 60.916667
| 103
| 0.791382
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,254
|
cluster_file_send.h
|
manticoresoftware_manticoresearch/src/replication/cluster_file_send.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "api_command_cluster.h"
struct SyncDst_t;
struct RemoteFileState_t
{
const AgentDesc_t* m_pAgentDesc = nullptr;
const SyncSrc_t * m_pSyncSrc = nullptr;
const SyncDst_t * m_pSyncDst = nullptr;
};
// send file to multiple nodes by chunks as API command CLUSTER_FILE_SEND
bool RemoteClusterFileSend ( const SyncSrc_t & tSigSrc, const CSphVector<RemoteFileState_t> & dDesc, const CSphString & sCluster, const CSphString & sIndex );
| 934
|
C++
|
.h
| 22
| 41.045455
| 158
| 0.764901
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,255
|
commit_monitor.h
|
manticoresoftware_manticoresearch/src/replication/commit_monitor.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "accumulator.h"
#include "searchdaemon.h"
// interface to pass into static Replicate to issue commit for specific command
class CommitMonitor_c
{
public:
explicit CommitMonitor_c ( RtAccum_t& tAcc )
: m_tAcc ( tAcc )
{}
CommitMonitor_c ( RtAccum_t& tAcc, CSphString* pWarning, int* pUpdated )
: m_tAcc ( tAcc )
, m_pWarning ( pWarning )
, m_pUpdated ( pUpdated )
{}
CommitMonitor_c ( RtAccum_t& tAcc, int* pDeletedCount, CSphString* pWarning, int* pUpdated )
: m_tAcc ( tAcc )
, m_pDeletedCount ( pDeletedCount )
, m_pWarning ( pWarning )
, m_pUpdated ( pUpdated )
{}
~CommitMonitor_c();
// commit for common commands
bool Commit ();
// commit for Total Order Isolation commands
bool CommitTOI ();
// update with Total Order Isolation
bool UpdateTOI ();
private:
RtAccum_t & m_tAcc;
int * m_pDeletedCount = nullptr;
CSphString * m_pWarning = nullptr;
int * m_pUpdated = nullptr;
bool CommitNonEmptyCmds ( RtIndex_i* pIndex, const ReplicationCommand_t& tCmd, bool bOnlyTruncate ) const;
};
| 1,530
|
C++
|
.h
| 46
| 31.304348
| 107
| 0.734057
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,256
|
wsrep_cxx_int.h
|
manticoresoftware_manticoresearch/src/replication/wsrep_cxx_int.h
|
//
// Copyright (c) 2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "wsrep_cxx.h"
#include "task_info.h"
#include "coroutine.h"
bool CheckNoWarning ( const char* szMsg );
enum class LogLevel_e {
FATAL,
ERROR_, // named this way because of macro conflict with winnt.h
WARN,
INFO,
DEBUG
};
void WsrepLog ( LogLevel_e eLevel, const char* szMsg );
// log debug info about nodes as current nodes views that
void LogGroupView ( const Wsrep::ViewInfo_t* pView );
// display incoming string as client name in show threads
struct GaleraInfo_t: public TaskInfo_t
{
DECLARE_RENDER ( GaleraInfo_t );
CSphString m_sName; // set once on create, so is th-safe
explicit GaleraInfo_t ( const CSphString& sName )
: m_sName { sName }
{}
};
enum class CbStatus_e {
SUCCESS = 0,
FAILURE,
};
inline constexpr CbStatus_e Bool2Cb ( bool b ) noexcept
{
return b ? CbStatus_e::SUCCESS : CbStatus_e::FAILURE;
}
// common structs and flags
using InitArgs_t = void; // actually it is version-dependent struct
using PoHandle_t = void;
struct TxHandle_t
{
uint64_t m_uTrx = UINT64_MAX;
void* m_pCookie = nullptr;
};
struct Buf_t
{
const void* m_pData;
uint64_t m_uLen;
};
struct Key_t
{
const Buf_t* m_pParts;
uint64_t m_uCount;
};
enum class KeyType_e {
SHARED = 0,
SEMI,
EXCLUSIVE
};
enum class DataType_e {
ORDERED = 0,
UNORDERED,
ANNOTATION
};
struct DwFlags_t
{
static constexpr DWORD COMMIT = 1ULL;
static constexpr DWORD ROLLBACK = 2ULL;
static constexpr DWORD ISOLATION = 4ULL;
static constexpr DWORD PA_UNSAFE = 8ULL;
static constexpr DWORD COMMUTATIVE = 16ULL;
static constexpr DWORD NATIVE = 32ULL;
};
extern std::atomic<uint64_t> uWritesetConnIds;
// wrap replication writeset to RAII
template<typename WSREPWRAP>
class Writeset_T final: public Wsrep::Writeset_i
{
using Status_e = typename WSREPWRAP::Status_e_;
CSphRefcountedPtr<WSREPWRAP> m_pWsrep;
uint64_t m_uConnId;
Wsrep::TrxMeta_t m_tMeta;
TxHandle_t m_tHnd;
Status_e m_eLastRes = Status_e::OK;
bool m_bNeedPostRollBack = false; // if we need rollback on exit, not just FreeConnection
// check return code from Galera calls
// FIXME!!! handle more status codes properly
bool CheckResult ( const char* sAt, bool bCritical = false )
{
if ( LastOk() )
return true;
TlsMsg::Err ( "error at %s, code %d (%s), seqno %l", sAt, m_eLastRes, WSREPWRAP::szGetStatus ( m_eLastRes ), m_tMeta.m_tGtid.m_iSeqNo );
sphWarning ( "%s", TlsMsg::szError() );
if ( bCritical )
m_bNeedPostRollBack = true;
return false;
}
public:
explicit Writeset_T ( WSREPWRAP* pWsrep )
: m_pWsrep { pWsrep }
, m_uConnId { uWritesetConnIds.fetch_add ( 1, std::memory_order_relaxed ) }
{
pWsrep->AddRef();
m_tHnd.m_uTrx = m_uConnId;
}
[[nodiscard]] int64_t LastSeqno() const noexcept final
{
return m_tMeta.m_tGtid.m_iSeqNo;
}
[[nodiscard]] bool LastOk() const noexcept final
{
return m_eLastRes == Status_e::OK;
}
[[nodiscard]] bool AppendKeys ( const VecTraits_T<uint64_t>& dBufKeys, bool bSharedKeys ) final
{
auto iKeysCount = dBufKeys.GetLength();
// set keys wsrep_buf_t ptr and len
CSphFixedVector<Buf_t> dBufProxy { iKeysCount };
CSphFixedVector<Key_t> dKeys { iKeysCount };
ARRAY_CONSTFOREACH ( i, dBufKeys )
{
dBufProxy[i].m_pData = &dBufKeys[i];
dBufProxy[i].m_uLen = sizeof ( uint64_t );
dKeys[i].m_pParts = &dBufProxy[i];
dKeys[i].m_uCount = 1;
}
m_eLastRes = m_pWsrep->AppendKey ( &m_tHnd, dKeys.begin(), iKeysCount, ( bSharedKeys ? KeyType_e::SHARED : KeyType_e::EXCLUSIVE ), false );
return CheckResult ( "AppendKeys" );
}
[[nodiscard]] bool AppendData ( const VecTraits_T<BYTE>& dData ) final
{
Buf_t tQueries { dData.Begin(), (uint64_t)dData.GetLength64() };
m_eLastRes = m_pWsrep->AppendData ( &m_tHnd, &tQueries, 1, DataType_e::ORDERED, false );
return CheckResult ( "AppendData" );
}
[[nodiscard]] bool PreCommit() final
{
m_eLastRes = m_pWsrep->PreCommit ( m_uConnId, &m_tHnd, DwFlags_t::COMMIT, &m_tMeta );
return CheckResult ( "PreCommit", true );
}
void AbortPreCommit() final
{
m_eLastRes = m_pWsrep->AbortPreCommit ( Wsrep::WRONG_SEQNO, m_tHnd.m_uTrx );
CheckResult ( "AbortPreCommit" );
m_bNeedPostRollBack = true;
}
void InterimCommit() final;
[[nodiscard]] bool Replicate() final
{
m_eLastRes = Status_e::OK; // no 'replicate' function in v25
return true;
}
void PostCommit() final
{
m_eLastRes = m_pWsrep->PostCommit ( &m_tHnd );
CheckResult ( "PostCommit" );
m_bNeedPostRollBack = false;
}
// TOI stuff
[[nodiscard]] bool ToExecuteStart ( const VecTraits_T<uint64_t>& dBufKeys, const VecTraits_T<BYTE>& dData ) final
{
auto iKeysCount = dBufKeys.GetLength();
// set keys ptr and len
CSphFixedVector<Buf_t> dBufProxy ( iKeysCount );
CSphFixedVector<Key_t> dKeys ( iKeysCount );
for ( int i = 0; i < iKeysCount; ++i )
{
dBufProxy[i].m_pData = &dBufKeys[i];
dBufProxy[i].m_uLen = sizeof ( uint64_t );
dKeys[i].m_pParts = &dBufProxy[i];
dKeys[i].m_uCount = 1;
}
Buf_t tQueries { dData.Begin(), (uint64_t)dData.GetLength() };
m_eLastRes = m_pWsrep->ToExecuteStart ( m_uConnId, dKeys.begin(), iKeysCount, &tQueries, 1, &m_tMeta );
return CheckResult ( "ToExecuteStart" );
}
void ToExecuteEnd() final
{
m_eLastRes = m_pWsrep->ToExecuteEnd ( m_uConnId );
CheckResult ( "ToExecuteEnd" );
}
~Writeset_T() final
{
if ( m_bNeedPostRollBack )
{
m_pWsrep->PostRollback ( &m_tHnd );
CheckResult ( "PostRollback" );
}
m_pWsrep->FreeConnection ( m_uConnId );
}
};
template<typename WSREPWRAP>
class Provider_T: public Wsrep::Provider_i
{
protected:
using Status_e = typename WSREPWRAP::Status_e_;
CSphRefcountedPtr<WSREPWRAP> m_pWsrep;
Wsrep::Cluster_i* m_pCluster;
Wsrep::ReceiverRefPtr_c m_pReceiver;
Wsrep::GlobalTid_t m_tStateID;
CSphString m_sName;
protected:
static CbStatus_e ViewChanged_fn ( void* pAppCtx, void* pRecvCtx, const Wsrep::ViewInfo_t* pView, const char* pState, uint64_t iStateLen, void** ppSstReq, uint64_t* pSstReqLen )
{
assert ( pAppCtx );
Wsrep::ClusterRefPtr_c pCluster { (Wsrep::Cluster_i*)pAppCtx };
pCluster->AddRef();
LogGroupView ( pView );
pCluster->ChangeView ( pView, pState, iStateLen, ppSstReq, pSstReqLen );
return Bool2Cb ( true );
}
// callback for Galera synced_cb that cluster fully synced and could accept transactions
static void Synced_fn ( void* pAppCtx )
{
assert ( pAppCtx );
Wsrep::ClusterRefPtr_c pCluster { (Wsrep::Cluster_i*)pAppCtx };
pCluster->AddRef();
pCluster->SetSynced();
}
static CbStatus_e Apply_fn ( void* pRecvCtx, const void* pData, uint64_t uSize, DWORD uFlags, const Wsrep::TrxMeta_t* pMeta )
{
assert ( pRecvCtx );
Wsrep::ReceiverRefPtr_c pReceiver { (Wsrep::Receiver_i*)pRecvCtx };
pReceiver->AddRef();
bool bCommit = ( ( uFlags & DwFlags_t::COMMIT ) != 0 );
bool bIsolated = ( ( uFlags & DwFlags_t::ISOLATION ) != 0 );
sphLogDebugRpl ( "writeset at apply, seq " INT64_FMT ", size %d, flags %u, on %s", pMeta->m_tGtid.m_iSeqNo, (int)uSize, uFlags, ( bCommit ? "commit" : "rollback" ) );
return Bool2Cb ( pReceiver->ApplyWriteset ( { (const BYTE*)pData, uSize }, bIsolated ) );
}
// callback for Galera to become of donor and start sending SST (all cluster indexes) to joiner
static CbStatus_e SstDonate_fn ( void* pAppCtx, void* pRecvCtx, const void* sMsg, uint64_t uMsgLen, const Wsrep::GlobalTid_t* pStateID, const char* pState, uint64_t uStateLen, bool bBypass )
{
assert ( pAppCtx );
Wsrep::ClusterRefPtr_c pCluster { (Wsrep::Cluster_i*)pAppCtx };
pCluster->AddRef();
CSphString sNode;
sNode.SetBinary ( (const char*)sMsg, uMsgLen );
return Bool2Cb ( pCluster->DonateSST ( std::move ( sNode ), pStateID, bBypass ) );
}
// template callback for Galera commit that transaction received and parsed before should be committed or rolled back
static CbStatus_e Commit_fn ( void* pRecvCtx, const void* hndTrx, DWORD uFlags, const Wsrep::TrxMeta_t* pMeta, bool* pExit, bool bCommit )
{
assert ( pRecvCtx );
Wsrep::ReceiverRefPtr_c pReceiver { (Wsrep::Receiver_i*)pRecvCtx };
pReceiver->AddRef();
sphLogDebugRpl ( "writeset at %s, seq " INT64_FMT ", flags %u", ( bCommit ? "commit" : "rollback" ), pMeta->m_tGtid.m_iSeqNo, uFlags );
return Bool2Cb ( pReceiver->Commit ( hndTrx, uFlags, pMeta, bCommit ) );
}
// callback for Galera that unordered transaction received
static CbStatus_e Unordered_fn ( void* pRecvCtx, const void* pData, uint64_t uSize )
{
assert ( pRecvCtx );
Wsrep::ReceiverRefPtr_c pReceiver { (Wsrep::Receiver_i*)pRecvCtx };
pReceiver->AddRef();
pReceiver->ApplyUnordered ( { (const BYTE*)pData, uSize } );
return Bool2Cb ( true );
}
public:
Provider_T ( Wsrep::Cluster_i* pCluster, WSREPWRAP* pWsrep )
: m_pWsrep { pWsrep }
, m_pCluster ( pCluster )
{
assert ( pCluster );
pWsrep->AddRef();
}
void SstReceived ( const Wsrep::GlobalTid_t& tGtid, int iRes ) final
{
m_pWsrep->SstReceived ( &tGtid, nullptr, 0, iRes );
}
void SstSent ( const Wsrep::GlobalTid_t& tGtid, bool bOk ) final
{
m_pWsrep->SstSent ( &tGtid, ( bOk ? 0 : -ECANCELED ) );
}
void Disconnect() final
{
m_pWsrep->Disconnect();
}
bool OptionsSet ( const CSphString& sName, const CSphString& sValue ) final
{
StringBuilder_c sOpt;
sOpt << sName << "=" << sValue;
auto tOk = m_pWsrep->OptionsSet ( sOpt.cstr() );
return tOk == Status_e::OK || TlsMsg::Err ( GetStatus ( tOk ) );
}
bool EnumFindStatsVar ( Wsrep::StatsVarsIteratorFN&& fnIterator ) final
{
auto* pAllVars = m_pWsrep->StatsGet();
AT_SCOPE_EXIT ( [pAllVars, this]() { m_pWsrep->StatsFree ( pAllVars ); } );
for ( auto* pVars = pAllVars; pVars->m_szName; ++pVars )
if ( fnIterator ( *pVars ) )
return true;
return false;
}
void EnumStatsVars ( Wsrep::StatsVarsVisitorFN&& fnVisitor ) final
{
auto* pAllVars = m_pWsrep->StatsGet();
AT_SCOPE_EXIT ( [pAllVars, this]() { m_pWsrep->StatsFree ( pAllVars ); } );
for ( auto* pVars = pAllVars; pVars->m_szName; ++pVars )
fnVisitor ( *pVars );
}
std::unique_ptr<Wsrep::Writeset_i> MakeWriteSet() final
{
return std::make_unique<Writeset_T<WSREPWRAP>> ( m_pWsrep );
}
bool Connect ( const char* szName, const char* szNodes, bool bBootStrap )
{
auto eRes = m_pWsrep->Connect ( szName, szNodes, "", bBootStrap );
// might try to join existed cluster however that took too long to timeout in case no cluster started
return eRes == Status_e::OK || TlsMsg::Err ( "replication connection failed: %d '%s'", (int)eRes, GetStatus ( eRes ) );
}
void StartListen ( Wsrep::Receiver_i* pReceiver )
{
assert ( pReceiver );
assert ( !m_pReceiver );
pReceiver->AddRef();
m_pReceiver = pReceiver;
auto sThName = SphSprintf ( "%s_repl", m_sName.cstr() );
// let's start listening thread with proper provider set
auto pScheduler = MakeSingleThreadExecutor ( -1, sThName.cstr() );
Threads::Coro::Go ( [this]() {
// publish stuff in 'show threads'
ScopedInfo_T<GaleraInfo_t> _ { new GaleraInfo_t ( m_sName ) };
ReplicationRecv();
},
pScheduler );
}
// main recv thread of Galera that handles cluster
// This is the listening thread. It blocks in recv() call until
// disconnect from cluster. It will apply and commit writesets through the
// callbacks defined above.
void ReplicationRecv()
{
assert ( m_pCluster );
m_pCluster->AddRef();
m_pCluster->OnRecvStarted();
sphLogDebugRpl ( "receiver thread started" );
Status_e eState = m_pWsrep->Recv ( m_pReceiver.Ptr() );
sphLogDebugRpl ( "receiver done, code %d, %s", (int)eState, GetStatus ( eState ) );
m_pCluster->OnRecvFinished ( eState != Status_e::CONNECTION_FAIL && eState != Status_e::NODE_FAIL && eState != Status_e::FATAL );
m_pCluster->Release();
}
};
using WsrepLoaderFN = int ( * ) ( void* );
struct WsrepLoader_t
{
std::unique_ptr<CSphDynamicLibrary> m_pLibrary;
int m_iIfaceVer = -1;
WsrepLoaderFN m_WsrepLoaderFn = nullptr;
};
WsrepLoader_t TryWsrep();
inline bool LoadWsrep ( void* pWsrep, const WsrepLoader_t& tLoader )
{
assert ( pWsrep );
auto iRes = tLoader.m_WsrepLoaderFn ( pWsrep );
return !!iRes || TlsMsg::Err ( "loading galera failed. Error %d - %s", iRes, strerrorm ( iRes ) );
}
template<typename PROVIDER>
Wsrep::Provider_i* MakeProvider ( WsrepLoader_t tLoader, Wsrep::Cluster_i* pCluster, CSphString sName, const char* szListenAddr, const char* szIncoming, const char* szPath, const char* szOptions )
{
using WSREPWRAP = typename PROVIDER::WSREPWRAP;
CSphRefcountedPtr<WSREPWRAP> pWsrepWrap { new WSREPWRAP };
auto iRes = tLoader.m_WsrepLoaderFn ( &pWsrepWrap->m_tWsrep );
if ( iRes )
{
TlsMsg::Err ( "loading galera failed. Error %d - %s", iRes, strerrorm ( iRes ) );
return nullptr;
}
pWsrepWrap->m_pWsrepLib = std::move ( tLoader.m_pLibrary );
if ( !pWsrepWrap->CheckLoadWsrep() )
return nullptr;
auto pProvider = std::make_unique<PROVIDER> ( pCluster, pWsrepWrap );
if ( !pProvider->Init ( std::move ( sName ), szListenAddr, szIncoming, szPath, szOptions ) )
return nullptr;
return pProvider.release();
}
Wsrep::Provider_i* MakeProviderV25 ( WsrepLoader_t tLoader, Wsrep::Cluster_i* pCluster, CSphString sName, const char* szListenAddr, const char* szIncoming, const char* szPath, const char* szOptions );
Wsrep::Provider_i* MakeProviderV31 ( WsrepLoader_t tLoader, Wsrep::Cluster_i* pCluster, CSphString sName, const char* szListenAddr, const char* szIncoming, const char* szPath, const char* szOptions );
| 13,802
|
C++
|
.h
| 382
| 33.709424
| 200
| 0.71069
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,257
|
replicate_index.h
|
manticoresoftware_manticoresearch/src/replication/replicate_index.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (http://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "std/vectraits.h"
#include "searchdha.h"
// send local index to remote nodes via API
bool ReplicateIndexToNodes ( const CSphString& sCluster, const CSphString& sIndex, const VecTraits_T<AgentDesc_t>& dDesc, const cServedIndexRefPtr_c& pServedIndex );
// send distributed index to remote nodes via API
bool ReplicateDistIndexToNodes ( const CSphString & sCluster, const CSphString & sIndex, const VecTraits_T<AgentDesc_t> & dDesc );
| 836
|
C++
|
.h
| 16
| 51
| 165
| 0.77451
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,258
|
serialize.h
|
manticoresoftware_manticoresearch/src/replication/serialize.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
int LoadUpdate ( const BYTE * pBuf, int iLen, CSphQuery & tQuery );
int LoadAttrUpdate ( const BYTE * pBuf, int iLen, CSphAttrUpdate & tUpd, bool & bBlob );
bool LoadCmdHeader ( MemoryReader_c & tReader, ReplicationCommand_t * pCmd );
void SaveUpdate ( const CSphQuery & tQuery, MemoryWriter_c & tWriter );
void SaveAttrUpdate ( const CSphAttrUpdate & tUpd, MemoryWriter_c & tWriter );
void SaveCmdHeader ( const ReplicationCommand_t& tCmd, MemoryWriter_c & tWriter );
WORD GetVerCommandReplicate();
| 993
|
C++
|
.h
| 19
| 51
| 88
| 0.759546
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,259
|
api_command_cluster.h
|
manticoresoftware_manticoresearch/src/replication/api_command_cluster.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/ints.h"
#include "std/string.h"
#include "std/fixedvector.h"
#include "std/bitvec.h"
#include "searchdconfig.h"
#include "searchdha.h"
#include "wsrep_cxx.h"
#include "send_files.h"
#include <memory>
// API commands that not get replicated via Galera, cluster management
enum class E_CLUSTER : WORD
{
DELETE_ = 0, // named this way because of macro conflict with winnt.h
FILE_RESERVE = 1,
FILE_SEND = 3,
INDEX_ADD_LOCAL = 4,
SYNCED = 5,
GET_NODES = 6,
UPDATE_NODES = 7,
INDEX_ADD_DIST = 8,
GET_NODE_STATE = 9,
GET_NODE_VER = 10,
};
inline constexpr const char* szClusterCmd ( E_CLUSTER eCmd )
{
switch ( eCmd )
{
case E_CLUSTER::DELETE_ : return "delete";
case E_CLUSTER::FILE_RESERVE: return "file_reserve";
case E_CLUSTER::FILE_SEND: return "file_send";
case E_CLUSTER::INDEX_ADD_LOCAL: return "index_add_local";
case E_CLUSTER::SYNCED: return "synced";
case E_CLUSTER::GET_NODES: return "get_nodes";
case E_CLUSTER::UPDATE_NODES: return "update_nodes";
case E_CLUSTER::INDEX_ADD_DIST: return "index_add_distributed";
case E_CLUSTER::GET_NODE_STATE: return "get_node_state";
case E_CLUSTER::GET_NODE_VER: return "get_node_ver";
default: return "unknown";
}
}
struct ClusterRequest_t
{
CSphString m_sCluster;
};
struct EmptyReply_t { };
// use void as result type, as we never chain this requests.
void operator<< ( ISphOutputBuffer&, const ClusterRequest_t& );
void operator>> ( InputBuffer_c&, ClusterRequest_t& );
StringBuilder_c& operator<< ( StringBuilder_c&, const ClusterRequest_t& );
void operator<< ( ISphOutputBuffer&, const StrVec_t& );
void operator>> ( InputBuffer_c&, StrVec_t& );
StringBuilder_c& operator<< ( StringBuilder_c&, const StrVec_t& );
inline void operator<< ( ISphOutputBuffer& tOut, const EmptyReply_t& ) { tOut.SendByte ( 1 ); }
inline void operator>> ( InputBuffer_c& tIn, EmptyReply_t& ) { tIn.GetByte(); }
inline StringBuilder_c& operator<< ( StringBuilder_c& tOut, const EmptyReply_t& ) { tOut << "byte 1 (fake)"; return tOut; }
template <typename REQUEST, typename REPLY>
struct CustomAgentData_T final: public DefaultQueryResult_t
{
const REQUEST& m_tRequest;
REPLY m_tReply;
explicit CustomAgentData_T ( const REQUEST& tReq )
: m_tRequest ( tReq )
{}
};
// base of API commands request and reply builders
AgentConn_t* CreateAgentBase ( const AgentDesc_t& tDesc, int64_t iTimeoutMs );
// set to true to see all proto exchanging in the log
constexpr bool VERBOSE_LOG = false;
template<E_CLUSTER CMD, typename REQUEST = ClusterRequest_t, typename REPLY = EmptyReply_t >
class ClusterCommand_T: public RequestBuilder_i, public ReplyParser_i
{
public:
using REQUEST_T = REQUEST;
using REPLY_T = REPLY;
static REPLY& GetRes ( const AgentConn_t& tAgent )
{
auto* pResult = static_cast<CustomAgentData_T<REQUEST, REPLY>*> ( tAgent.m_pResult.get() );
assert ( pResult );
return pResult->m_tReply;
}
static const REQUEST& GetReq ( const AgentConn_t& tAgent )
{
const auto* pResult = (CustomAgentData_T<REQUEST, REPLY>*)tAgent.m_pResult.get();
assert ( pResult );
return pResult->m_tRequest;
}
static AgentConn_t* CreateAgent ( const AgentDesc_t& tDesc, int64_t iTimeoutMs, const REQUEST& tReq )
{
auto* pAgent = CreateAgentBase ( tDesc, iTimeoutMs );
pAgent->m_pResult = std::make_unique<CustomAgentData_T<REQUEST, REPLY>> ( tReq );
return pAgent;
}
static VecRefPtrs_t<AgentConn_t*> MakeAgents ( const VecTraits_T<AgentDesc_t>& dDesc, int64_t iTimeout, const REQUEST& tReq )
{
VecRefPtrs_t<AgentConn_t*> dNodes;
dNodes.Resize ( dDesc.GetLength() );
ARRAY_FOREACH ( i, dDesc )
dNodes[i] = CreateAgent ( dDesc[i], iTimeout, tReq );
return dNodes;
}
template<typename REQ>
static void VerboseProtoImpl ( const char* szCmd, const REQ& tData )
{
StringBuilder_c sRequest;
sRequest.Sprintf ( "%s [%s]: ", szCmd, szClusterCmd ( CMD ) );
ScopedComma_c space ( sRequest, " " );
sRequest << tData;
sphLogDebugRpl ( "%s", sRequest.cstr() );
}
#define VerboseProto( ... ) do if constexpr ( VERBOSE_LOG ) VerboseProtoImpl ( __VA_ARGS__ ); while ( 0 )
void BuildRequest ( const AgentConn_t& tAgent, ISphOutputBuffer& tOut ) const final
{
if ( CMD==E_CLUSTER::FILE_SEND )
{
{
auto tHdr = APIHeader ( tOut, SEARCHD_COMMAND_PERSIST );
tOut.SendInt ( 1 ); // set persistent to 1
}
}
// API header
auto tReply = APIHeader ( tOut, SEARCHD_COMMAND_CLUSTER, VER_COMMAND_CLUSTER );
tOut.SendWord ( static_cast<WORD> ( CMD ) );
tOut << GetReq ( tAgent );
if ( CMD==E_CLUSTER::FILE_SEND )
{
{
auto tHdr = APIHeader ( tOut, SEARCHD_COMMAND_PERSIST );
tOut.SendInt ( 0 ); // set persistent to 0
}
}
VerboseProto ( "BldRq", GetReq ( tAgent ) );
}
static void ParseRequest ( InputBuffer_c& tIn, REQUEST_T& tReq )
{
tIn >> tReq;
VerboseProto ( "PrsRq", tReq );
}
static void BuildReply ( ISphOutputBuffer& tOut, const REPLY_T& tRes = {} )
{
auto tReply = APIAnswer ( tOut );
tOut << tRes;
VerboseProto ( "BldRpl", tRes );
}
bool ParseReply ( InputBuffer_c& tReq, AgentConn_t& tAgent ) const final
{
tReq >> GetRes ( tAgent );
VerboseProto ( "PrsRpl", GetRes ( tAgent ) );
return !tReq.GetError();
}
};
bool PerformRemoteTasksWrap ( VectorAgentConn_t & dNodes, RequestBuilder_i & tReq, ReplyParser_i & tReply, bool bRetry );
// handle all API incoming.
void HandleAPICommandCluster ( ISphOutputBuffer& tOut, WORD uCommandVer, InputBuffer_c& tBuf, const char* szClient );
void ReplicationSetTimeouts ( int iConnectTimeoutMs, int iQueryTimeoutMs, int iRetryCount, int iRetryDelayMs );
int64_t ReplicationTimeoutQuery ( int64_t iTimeout = 0 ); // 2 minutes in msec
int ReplicationTimeoutConnect ();
int ReplicationRetryCount ();
int ReplicationRetryDelay ();
int ReplicationTimeoutAnyNode ();
int ReplicationFileRetryCount ();
int ReplicationFileRetryDelay ();
void ReportClusterError ( const CSphString& sCluster, const CSphString& sError, const char* szClient, E_CLUSTER eCmd );
| 6,397
|
C++
|
.h
| 172
| 35.02907
| 126
| 0.723793
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,260
|
cluster_synced.h
|
manticoresoftware_manticoresearch/src/replication/cluster_synced.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "nodes.h"
#include "std/string.h"
#include "wsrep_cxx.h"
#include "api_command_cluster.h"
struct ClusterSyncedRequest_t : ClusterRequest_t
{
Wsrep::GlobalTid_t m_tGtid; // GTID received
StrVec_t m_dIndexes; // index list received
bool m_bSendFilesSuccess = true;
CSphString m_sMsg;
};
bool SendClusterSynced ( const VecAgentDesc_t& dDesc, const ClusterSyncedRequest_t& tRequest );
| 888
|
C++
|
.h
| 24
| 35.625
| 95
| 0.763679
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,261
|
recv_state.h
|
manticoresoftware_manticoresearch/src/replication/recv_state.h
|
//
// Copyright (c) 2023-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "send_files.h"
#include "std/ints.h"
#include "std/string.h"
#include "coroutine.h"
#include "cluster_file_reserve.h"
enum class FileOp_e : BYTE {
COPY_FILE,
COPY_BUFFER,
VERIFY_FILE
};
struct FileOp_t
{
FileOp_e m_eOp { FileOp_e::COPY_FILE };
int64_t m_iOffFile { 0 };
int m_iOffBuf { 0 };
int64_t m_iSize { 0 };
};
enum class WriteResult_e : BYTE {
OK,
WRITE_FAILED,
VERIFY_FAILED
};
uint64_t DoubleStringKey ( const CSphString& sFirst, const CSphString& sSecond );
class RecvState_c
{
public:
WriteResult_e Write ( int iFile, const CSphVector<FileOp_t>& dOps, const VecTraits_T<BYTE>& dBuf ) EXCLUDES ( m_tLock );
MergeState_t* Flush () EXCLUDES ( m_tLock );
void SetMerge ( const SyncSrc_t& tSync, const SyncDst_t& tRes, const CSphString& sIndexPath, const VecTraits_T<CSphString>& dFilesRef ) EXCLUDES ( m_tLock );
private:
bool SetFile ( int iFile, bool bRestart ) REQUIRES ( m_tLock );
bool CmdCopyFile ( int64_t iOff, int64_t iSize ) REQUIRES ( m_tLock );
bool CmdCopyBuffer ( int64_t iOffFile, const VecTraits_T<BYTE>& dBuf, int iOffBuf, int64_t iSize ) REQUIRES ( m_tLock );
WriteResult_e CmdVerifyFile ( int iFile ) REQUIRES ( m_tLock );
bool VerifyHashWriter () REQUIRES ( m_tLock );
void Close() REQUIRES ( m_tLock );
bool CheckFiles ( bool bSeekReader, int64_t iOff ) REQUIRES ( m_tLock );
[[nodiscard]] inline const char* GetFilename() const noexcept REQUIRES ( m_tLock )
{
return ( ( m_iFile == -1 || !m_pMerge ) ? "" : m_pMerge->m_dFilesNew[m_iFile].cstr() );
}
private:
Threads::Coro::Mutex_c m_tLock; // prevent writing to same file from multiple clients
std::unique_ptr<WriterWithHash_c> m_pWriter GUARDED_BY ( m_tLock );
std::unique_ptr<CSphAutoreader> m_pReader GUARDED_BY ( m_tLock );
std::unique_ptr<MergeState_t> m_pMerge GUARDED_BY ( m_tLock );
CSphString m_sError; // writer need a string to put error message there
int m_iFile GUARDED_BY ( m_tLock ) { -1 };
int m_bFileRestarted GUARDED_BY ( m_tLock ) { false };
};
namespace RecvState {
RecvState_c& GetState ( uint64_t tWriterKey );
void Free ( uint64_t tWriterKey );
bool HasState ( uint64_t tWriterKey );
} // RecvState
| 2,646
|
C++
|
.h
| 67
| 37.791045
| 158
| 0.725819
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,262
|
configuration.h
|
manticoresoftware_manticoresearch/src/replication/configuration.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include "searchdaemon.h"
#include "std/string.h"
#pragma once
// returns true, if set data dir and replication ports
bool ReplicationEnabled();
// setup IP, ports and node incoming address
bool SetReplicationListener ( const VecTraits_T<ListenerDesc_t>& dListeners, CSphString & sError );
// listen IP part of address for Galera. The first of 'listen=' config with proto = replication
const char* szListenReplicationIP();
// incoming IP - one set by 'node_address=', or same as szListenReplicationIP, if none
const char* szIncomingIP();
bool HasIncoming() noexcept;
// incoming address (IP:port from API listener)
// used for request to this node from other daemons
const char* szIncomingProto();
// used to filter out own adrress
bool MyIncomingApiAddrBeginsWith ( const char* szHost );
void ReplicationSetIncoming ( CSphString sIncoming );
| 1,328
|
C++
|
.h
| 29
| 44.448276
| 99
| 0.775019
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,263
|
grastate.h
|
manticoresoftware_manticoresearch/src/replication/grastate.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
// clean up Galera files
void CleanClusterFiles ( const CSphString& sPath );
// set safe_to_bootstrap: 1 at cluster/grastate.dat for Galera to start properly
bool NewClusterForce ( const CSphString& sPath );
bool CheckClusterNew ( const CSphString& sPath );
| 677
|
C++
|
.h
| 16
| 41.0625
| 80
| 0.765601
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,264
|
cluster_file_reserve.h
|
manticoresoftware_manticoresearch/src/replication/cluster_file_reserve.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "searchdha.h"
#include "api_command_cluster.h"
struct SyncSrc_t;
struct FileReserveRequest_t: ClusterRequest_t
{
CSphString m_sIndex;
CSphString m_sIndexFileName;
SyncSrc_t* m_pChunks = nullptr;
};
void operator<< ( ISphOutputBuffer& tOut, const FileReserveRequest_t& tReq );
void operator>> ( InputBuffer_c& tIn, FileReserveRequest_t& tReq );
StringBuilder_c& operator<< ( StringBuilder_c& tOut, const FileReserveRequest_t& tReq );
struct SyncDst_t
{
CSphBitvec m_dNodeChunksMask;
StrVec_t m_dRemotePaths;
int64_t m_tmTimeout = 0;
int64_t m_tmTimeoutFile = 0;
};
struct FileReserveReply_t: SyncDst_t
{
bool m_bIndexActive = false;
};
void operator<< ( ISphOutputBuffer& tOut, const FileReserveReply_t& tReq );
void operator>> ( InputBuffer_c& tIn, FileReserveReply_t& tReq );
StringBuilder_c& operator<< ( StringBuilder_c& tOut, const FileReserveReply_t& tReq );
// API command to remote node prior to file send
using ClusterFileReserve_c = ClusterCommand_T<E_CLUSTER::FILE_RESERVE, FileReserveRequest_t, FileReserveReply_t>;
bool SendClusterFileReserve ( VecRefPtrs_t<AgentConn_t*>& dAgents );
| 1,516
|
C++
|
.h
| 39
| 37.358974
| 113
| 0.773379
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,265
|
portrange.h
|
manticoresoftware_manticoresearch/src/replication/portrange.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/generics.h"
#include "std/string.h"
class FreePortList_i;
// managed port got back into global ports list
class ScopedPort_c : public ISphNoncopyable
{
int m_iPort = -1;
FreePortList_i * m_pPortsList { nullptr };
public:
ScopedPort_c() = default;
ScopedPort_c ( int iPort, FreePortList_i * pPortList );
~ScopedPort_c();
ScopedPort_c ( ScopedPort_c&& rhs ) noexcept { Swap (rhs); }
ScopedPort_c& operator = ( ScopedPort_c&& rhs ) noexcept { Swap (rhs); return *this; }
void Swap ( ScopedPort_c& rhs ) noexcept { ::Swap ( m_iPort, rhs.m_iPort ); ::Swap ( m_pPortsList, rhs.m_pPortsList ); }
operator int() const noexcept { return m_iPort; }
[[nodiscard]] bool IsValid() const noexcept { return m_iPort!=-1;}
};
class FreePortList_i
{
public:
FreePortList_i() = default;
virtual ~FreePortList_i() {};
virtual ScopedPort_c AcquirePort () = 0;
virtual void Free ( int iPort ) = 0;
};
namespace PortRange
{
ScopedPort_c AcquirePort();
void AddPortsRange ( int iPort, int iCount );
void AddAddr ( const CSphString & sAddr );
FreePortList_i * Create ( const CSphString & sAddr, int iPort, int iCount );
}
| 1,627
|
C++
|
.h
| 45
| 34.533333
| 121
| 0.725191
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,266
|
cluster_update_nodes.h
|
manticoresoftware_manticoresearch/src/replication/cluster_update_nodes.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
#include "searchdaemon.h"
#include "api_command_cluster.h"
enum class NODES_E : bool;
struct UpdateNodesRequest_t : public ClusterRequest_t
{
NODES_E m_eKindNodes;
};
bool SendClusterUpdateNodes ( const CSphString& sCluster, NODES_E eNodes, const VecTraits_T<CSphString>& dNodes );
| 704
|
C++
|
.h
| 19
| 35.684211
| 114
| 0.768778
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,267
|
common.h
|
manticoresoftware_manticoresearch/src/replication/common.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
#include "searchdaemon.h"
// Update nodes list at cluster from actual nodes list
enum class NODES_E : bool { VIEW, BOTH };
bool ClusterUpdateNodes ( const CSphString& sCluster, NODES_E eNodes, StrVec_t* pNodes = nullptr );
// command at remote node for CLUSTER_DELETE to delete cluster
bool ClusterDelete ( const CSphString& sCluster );
// command at remote node for CLUSTER_SYNCED to pick up received indexes and notify Galera that sst received
struct ClusterSyncedRequest_t;
bool ClusterSynced ( const ClusterSyncedRequest_t& tCmd );
// cluster state this node sees
enum class ClusterState_e
{
// stop terminal states
CLOSED, // node shut well or not started
DESTROYED, // node closed with error
// transaction states
JOINING, // node joining cluster
DONOR, // node is donor for another node joining cluster
// ready terminal state
SYNCED // node works as usual
};
| 1,310
|
C++
|
.h
| 32
| 39.46875
| 108
| 0.762579
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,268
|
wsrep_cxx.h
|
manticoresoftware_manticoresearch/src/replication/wsrep_cxx.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/ints.h"
#include "std/vectraits.h"
#include "std/refcounted_mt.h"
#include "std/string.h"
#include "std/blobs.h"
#include <cstdint>
#include <functional>
#include <memory>
#include <array>
namespace Wsrep {
enum class ViewStatus_e
{
PRIMARY, // have quorum
NON_PRIMARY, // haven't quorum
DISCONNECTED,
MAX
};
using UUID_t = std::array<BYTE, 16>;
constexpr int64_t WRONG_SEQNO = -1;
// global transaction identifier
struct GlobalTid_t {
UUID_t m_tUuid {}; // { 0 } by default
int64_t m_iSeqNo { WRONG_SEQNO };
};
struct StatsVars_t
{
const char* m_szName;
enum {
STRING, // point to asciiz
INT64,
DOUBLE
} m_eType;
union {
const char* szString;
int64_t iVal64;
double fDouble;
} m_tValue;
};
using StatsVarsIteratorFN = std::function<bool ( const StatsVars_t& )>;
using StatsVarsVisitorFN = std::function<void ( const StatsVars_t& )>;
struct MemberInfo_t
{
UUID_t m_tUuid {};
char m_sName[32];
char m_sIncoming[256];
};
struct ViewInfo_t
{
GlobalTid_t m_tStateId;
int64_t m_ViewSeqNo;
ViewStatus_e m_eStatus;
bool m_bGap;
int m_iIdx;
int m_iNMembers;
int m_iProto;
MemberInfo_t m_tMemInfo;
};
class Writeset_i
{
public:
[[nodiscard]] virtual int64_t LastSeqno () const noexcept = 0;
[[nodiscard]] virtual bool LastOk () const noexcept = 0;
[[nodiscard]] virtual bool AppendKeys ( const VecTraits_T<uint64_t> & dBufKeys, bool bSharedKeys ) = 0;
[[nodiscard]] virtual bool AppendData ( const VecTraits_T<BYTE> & dData ) = 0;
[[nodiscard]] virtual bool Replicate () = 0;
[[nodiscard]] virtual bool PreCommit () = 0;
virtual void AbortPreCommit () = 0;
virtual void InterimCommit () = 0;
virtual void PostCommit () = 0;
[[nodiscard]] virtual bool ToExecuteStart ( const VecTraits_T<uint64_t> & dBufKeys, const VecTraits_T<BYTE> & dData ) = 0;
virtual void ToExecuteEnd () = 0;
virtual ~Writeset_i() = default;
};
class Cluster_i : public ISphRefcountedMT
{
public:
// cb invoked when cluster's structure changed. No other callbacks are called concurrently with it.
virtual void ChangeView ( const ViewInfo_t* pView, const char* pState, uint64_t uStateLen, void** ppSstReq, uint64_t* pSstReqLen ) = 0;
// cluster synced and could accept trx
virtual void SetSynced() = 0;
// transfer full state to another node.
virtual bool DonateSST ( CSphString sNode, const GlobalTid_t* pStateID, bool bBypass ) = 0;
// cb invoked when started recv
virtual void OnRecvStarted() = 0;
// cb invoked when recv is to be finished
virtual void OnRecvFinished ( bool bSuccess ) = 0;
};
using ClusterRefPtr_c = CSphRefcountedPtr<Cluster_i>;
// transaction meta data
struct TrxMeta_t
{
GlobalTid_t m_tGtid;
int64_t m_iDepSeqNo;
};
class Receiver_i : public ISphRefcountedMT
{
public:
virtual bool ApplyWriteset ( ByteBlob_t tData, bool bIsolated ) = 0;
virtual void ApplyUnordered ( ByteBlob_t tData ) = 0;
virtual bool Commit ( const void * pHndTrx, uint32_t uFlags, const TrxMeta_t * pMeta, bool bCommit ) = 0;
};
using ReceiverRefPtr_c = CSphRefcountedPtr<Receiver_i>;
class Applier_i
{
public:
virtual void ApplierPreCommit ( const void* ) = 0;
virtual void ApplierInterimPostCommit ( const void* ) = 0;
};
class Provider_i : ISphNoncopyable
{
public:
virtual ~Provider_i() = default;
virtual void SstReceived ( const GlobalTid_t & tGtid, int iRes ) = 0;
virtual void SstSent ( const GlobalTid_t & tGtid, bool bOk ) = 0;
virtual void Disconnect () = 0;
[[nodiscard]] virtual bool OptionsSet ( const CSphString & sName, const CSphString & sValue ) = 0;
virtual bool EnumFindStatsVar ( StatsVarsIteratorFN&& fnCondition ) = 0;
virtual void EnumStatsVars ( StatsVarsVisitorFN&& fnVisitor ) = 0;
[[nodiscard]] virtual bool Connect ( const char * szName, const char * szNodes, bool bBootStrap ) = 0;
virtual void StartListen ( Wsrep::Receiver_i * pReceiver ) = 0;
virtual std::unique_ptr<Writeset_i> MakeWriteSet() = 0;
virtual Applier_i* GetApplier() = 0;
};
Provider_i * MakeProvider ( Cluster_i * pCluster, CSphString sName, const char * szListenAddr, const char * szIncoming, const char * szPath, const char * szOptions );
// these guys tested in gtests_wsrep.cpp
CSphString Uuid2Str ( const UUID_t& tUuid );
UUID_t Str2Uuid ( const CSphString& sUuid );
CSphString Gtid2Str ( const GlobalTid_t& tGtid );
GlobalTid_t Str2Gtid ( const CSphString& sGtid );
const char * GetViewStatus ( ViewStatus_e tStatus ) noexcept;
} // namespace Wsrep
// comparing moved out from Wsrep namespace
inline bool operator== ( const Wsrep::GlobalTid_t & lhs, const Wsrep::GlobalTid_t & rhs ) noexcept
{
return lhs.m_iSeqNo == rhs.m_iSeqNo && lhs.m_tUuid == rhs.m_tUuid;
}
inline bool operator!= ( const Wsrep::GlobalTid_t & lhs, const Wsrep::GlobalTid_t & rhs ) noexcept
{
return !( lhs == rhs );
}
| 5,187
|
C++
|
.h
| 150
| 32.853333
| 166
| 0.735012
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,269
|
nodes.h
|
manticoresoftware_manticoresearch/src/replication/nodes.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (http://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "searchdha.h"
using VecAgentDesc_t = CSphVector<AgentDesc_t>;
// string to list
StrVec_t ParseNodesFromString ( CSphString sNodes );
// collect listener API with external address
enum class Resolve_e { QUICK, SLOW };
VecAgentDesc_t GetDescAPINodes ( const VecTraits_T<CSphString> & dNodes, Resolve_e eSpeed );
StrVec_t FilterNodesByProto ( const VecTraits_T<CSphString> & dSrcNodes, Proto_e eProto, bool bResolve = true );
| 829
|
C++
|
.h
| 18
| 44.722222
| 112
| 0.767702
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,270
|
cluster_index_add_local.h
|
manticoresoftware_manticoresearch/src/replication/cluster_index_add_local.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
#include "searchdconfig.h"
#include "searchdha.h"
#include "api_command_cluster.h"
struct ClusterIndexAddLocalRequest_t : ClusterRequest_t
{
CSphString m_sIndex; // local name of index
IndexType_e m_eIndex = IndexType_e::ERROR_;
bool m_bSendFilesSuccess = false;
};
void operator<< ( ISphOutputBuffer& tOut, const ClusterIndexAddLocalRequest_t& tReq );
void operator>> ( MemInputBuffer_c& tOut, ClusterIndexAddLocalRequest_t& tReq );
using ClusterIndexAddLocal_c = ClusterCommand_T<E_CLUSTER::INDEX_ADD_LOCAL, ClusterIndexAddLocalRequest_t>;
bool AddLoadedIndexIntoCluster ( const CSphString & sCluster, const CSphString & sIndex );
| 1,153
|
C++
|
.h
| 26
| 43.038462
| 107
| 0.778966
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,271
|
send_files.h
|
manticoresoftware_manticoresearch/src/replication/send_files.h
|
//
// Copyright (c) 2023-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/ints.h"
#include "std/string.h"
#include "std/fixedvector.h"
#include "digest_sha1.h"
#include <optional>
struct FileChunks_t
{
int64_t m_iFileSize = 0; // size of whole file
int m_iHashStartItem = 0; // offset in hashes vector in HASH20_SIZE items
int m_iChunkBytes = 0; // length bytes of one hash chunk in file
// count of chunks for file size
[[nodiscard]] int GetChunksCount () const noexcept;
[[nodiscard]] int64_t GetChunkFileLength ( int iChunk ) const noexcept;
[[nodiscard]] int64_t GetChunkFileOffset ( int iChunk ) const noexcept;
};
struct MergeState_t
{
CSphBitvec m_dMergeMask;
CSphString m_sIndexPath;
FixedStrVec_t m_dFilesNew { 0 };
FixedStrVec_t m_dFilesRef { 0 };
CSphFixedVector<FileChunks_t> m_dChunks { 0 };
CSphFixedVector<HASH20_t> m_dHashes { 0 };
};
struct SyncSrc_t
{
// index file names (full path, file name, extension) at source node
StrVec_t m_dIndexFiles;
// index file names only (file name, extension) send from source node to destination
FixedStrVec_t m_dBaseNames { 0 };
CSphFixedVector<FileChunks_t> m_dChunks { 0 };
// hashes of all index files
CSphFixedVector<HASH20_t> m_dHashes { 0 };
int64_t m_tmTimeout = 0; // millisecond it took to read and hash all files, used for calc agent query timeout later
int64_t m_tmTimeoutFile = 0; // max millisecond to read or hash files, used for calc agent query timeout later
int64_t m_iBufferSize = 0;
public:
SyncSrc_t() = default;
explicit SyncSrc_t ( StrVec_t&& dIndexFiles );
[[nodiscard]] HASH20_t& GetFileHash ( int iFile ) const noexcept;
[[nodiscard]] HASH20_t& GetChunkHash ( int iFile, int iChunk ) const noexcept;
bool CalculateFilesSignatures ();
private:
std::optional<int> InitSyncSrc ();
};
bool VerifyFileHash ( int iFile, const CSphString& sName, const SyncSrc_t& tSrc, CSphBitvec& tDst, CSphVector<BYTE>& dBuf, CSphString& sError );
bool SyncSigVerify ( const CSphString& sFile, const HASH20_t& dHash );
bool SyncSigVerify ( const VecTraits_T<CSphString>& dFiles, const VecTraits_T<HASH20_t>& dHashes );
| 2,549
|
C++
|
.h
| 60
| 40.783333
| 144
| 0.75
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,272
|
cluster_delete.h
|
manticoresoftware_manticoresearch/src/replication/cluster_delete.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
// ask remote nodes to delete given cluster by name
void SendClusterDeleteToNodes ( const VecTraits_T<CSphString>& dNodes, const CSphString& sCluster );
| 670
|
C++
|
.h
| 15
| 43.333333
| 100
| 0.764615
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,273
|
cluster_get_nodes.h
|
manticoresoftware_manticoresearch/src/replication/cluster_get_nodes.h
|
//
// Copyright (c) 2019-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
#include "searchdaemon.h"
#include "common.h"
// command to all remote nodes at cluster to get actual nodes list
StrVec_t GetNodeListFromRemotes ( const ClusterDesc_t& tDesc );
struct RemoteNodeClusterState_t
{
CSphString m_sNode;
ClusterState_e m_eState;
CSphString m_sHash;
};
using ClusterNodesStatesVec_t = CSphVector<RemoteNodeClusterState_t>;
// command to all remote nodes at cluster to get actual nodes states
ClusterNodesStatesVec_t GetStatesFromRemotes ( const ClusterDesc_t & tDesc );
bool ClusterGetState ( const CSphString & sCluster, RemoteNodeClusterState_t & tState );
bool CheckRemotesVersions ( const ClusterDesc_t & tDesc );
| 1,068
|
C++
|
.h
| 26
| 39.730769
| 88
| 0.787645
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,276
|
ischema.h
|
manticoresoftware_manticoresearch/src/schema/ischema.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "columninfo.h"
class CSphRsetSchema;
/// barebones schema interface
/// everything that is needed from every implementation of a schema
class ISphSchema
{
public:
/// dtor
virtual ~ISphSchema () = default;
/// assign current schema to rset schema (kind of a visitor operator)
virtual void AssignTo ( class CSphRsetSchema & lhs ) const = 0;
/// get schema name
virtual const char * GetName() const = 0;
/// add an attribute
virtual void AddAttr ( const CSphColumnInfo & tAttr, bool bDynamic ) = 0;
/// get row size (static+dynamic combined)
virtual int GetRowSize() const = 0;
/// get static row part size
virtual int GetStaticSize() const = 0;
/// get dynamic row part size
virtual int GetDynamicSize() const = 0;
virtual int GetAttrsCount() const = 0;
virtual int GetFieldsCount() const = 0;
virtual const CSphColumnInfo & GetField ( int iIndex ) const = 0;
virtual const CSphColumnInfo * GetField ( const char * szName ) const = 0;
virtual const CSphVector<CSphColumnInfo> & GetFields () const = 0;
/// get attribute index by name, returns -1 if not found
virtual int GetAttrIndex ( const char * sName ) const = 0;
/// get field index by name, returns -1 if not found
virtual int GetFieldIndex ( const char * sName ) const = 0;
/// get attr by index
virtual const CSphColumnInfo & GetAttr ( int iIndex ) const = 0;
/// get attr by name
virtual const CSphColumnInfo * GetAttr ( const char * sName ) const = 0;
/// get the first one of field length attributes. return -1 if none exist
virtual int GetAttrId_FirstFieldLen() const = 0;
/// get the last one of field length attributes. return -1 if none exist
virtual int GetAttrId_LastFieldLen() const = 0;
/// free all allocated attibures. Does NOT free m_pDynamic of match itself!
virtual void FreeDataPtrs ( CSphMatch & tMatch ) const = 0;
/// return original attribute id (for compound schemas)
virtual int GetAttrIndexOriginal ( const char * szName ) const = 0;
/// simple copy; clones either the entire dynamic part, or a part thereof
virtual void CloneMatch ( CSphMatch & tDst, const CSphMatch & rhs ) const = 0;
virtual void SwapAttrs ( CSphVector<CSphColumnInfo> & dAttrs ) = 0;
virtual ISphSchema* CloneMe() const = 0;
};
| 2,815
|
C++
|
.h
| 59
| 45.677966
| 83
| 0.72019
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,277
|
columninfo.h
|
manticoresoftware_manticoresearch/src/schema/columninfo.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "sphinxstd.h"
#include "sphinxdefs.h"
#include "locator.h"
#include "sphinxexpr.h"
#include "knn/knn.h"
class CSphWriter;
class CSphReader;
struct NamedKNNSettings_t : public knn::IndexSettings_t
{
CSphString m_sName;
};
/// source column info
struct CSphColumnInfo
{
enum
{
FIELD_NONE = 0,
FIELD_STORED = 1 << 0,
FIELD_INDEXED = 1 << 1,
FIELD_IS_ATTRIBUTE = 1 << 2, // internal flag used in 'alter'
};
enum
{
ATTR_NONE = 0,
ATTR_COLUMNAR = 1 << 0,
ATTR_COLUMNAR_HASHES = 1 << 1,
ATTR_STORED = 1 << 2,
ATTR_INDEXED_KNN = 1 << 3,
ATTR_JOINED = 1 << 4,
ATTR_INDEXED_SI = 1 << 5
};
CSphString m_sName; ///< column name
ESphAttr m_eAttrType; ///< attribute type
ESphWordpart m_eWordpart { SPH_WORDPART_WHOLE }; ///< wordpart processing type
bool m_bIndexed = false; ///< whether to index this column as fulltext field too
int m_iIndex = -1; ///< index into source result set (-1 for joined fields)
CSphAttrLocator m_tLocator; ///< attribute locator in the row
ESphAttrSrc m_eSrc { SPH_ATTRSRC_NONE }; ///< attr source (for multi-valued attrs only)
CSphString m_sQuery; ///< query to retrieve values (for multi-valued attrs only)
CSphString m_sQueryRange; ///< query to retrieve range (for multi-valued attrs only)
ISphExprRefPtr_c m_pExpr; ///< evaluator for expression items
ESphAggrFunc m_eAggrFunc { SPH_AGGR_NONE }; ///< aggregate function on top of expression (for GROUP BY)
ESphEvalStage m_eStage { SPH_EVAL_STATIC }; ///< column evaluation stage (who and how computes this column)
bool m_bPayload = false;
bool m_bFilename = false; ///< column is a file name
bool m_bWeight = false; ///< is a weight column
DWORD m_uFieldFlags = FIELD_INDEXED; ///< stored/indexed/highlighted etc
DWORD m_uAttrFlags = ATTR_NONE; ///< attribute storage spec
AttrEngine_e m_eEngine = AttrEngine_e::DEFAULT; ///< used together with per-table engine specs to determine attribute storage
knn::IndexSettings_t m_tKNN; ///< knn index settings
WORD m_uNext = 0xFFFF; ///< next in linked list for hash in CSphSchema
/// handy ctor
explicit CSphColumnInfo ( const char * sName = nullptr, ESphAttr eType = SPH_ATTR_NONE );
/// equality comparison checks name, type, and locator
bool operator== ( const CSphColumnInfo & rhs ) const;
/// returns true if this column stores a pointer to data
bool IsDataPtr() const;
bool IsColumnar() const;
bool HasStringHashes() const;
bool IsColumnarExpr() const;
bool IsStoredExpr() const;
bool IsIndexedKNN() const;
bool IsJoined() const;
bool IsIndexedSI() const;
};
CSphString sphDumpAttr ( const CSphColumnInfo & tAttr );
| 3,223
|
C++
|
.h
| 78
| 39.269231
| 126
| 0.7056
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,278
|
helper.h
|
manticoresoftware_manticoresearch/src/schema/helper.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "ischema.h"
#include "match.h"
/// helper class that is used by CSphSchema and CSphRsetSchema
class CSphSchemaHelper : public ISphSchema
{
public:
void FreeDataPtrs ( CSphMatch & tMatch ) const final;
int GetAttrIndexOriginal ( const char * szName ) const { return GetAttrIndex(szName); }
void CloneMatch ( CSphMatch & tDst, const CSphMatch & rhs ) const final;
/// clone all raw attrs and only specified ptrs
FORCE_INLINE void CloneMatchSpecial ( CSphMatch & tDst, const CSphMatch & rhs, const VecTraits_T<int> & dSpecials ) const;
/// exclude vec of rowitems from dataPtrAttrs and return diff back
CSphVector<int> SubsetPtrs ( CSphVector<int> &dSpecials ) const ;
/// get dynamic row part size
int GetDynamicSize () const final { return m_dDynamicUsed.GetLength (); }
void Swap ( CSphSchemaHelper& rhs ) noexcept;
// free/copy by specified vec of rowitems, assumed to be from SubsetPtrs() call.
static FORCE_INLINE void FreeDataSpecial ( CSphMatch & tMatch, const VecTraits_T<int> & dSpecials );
static FORCE_INLINE void CopyPtrsSpecial ( CSphMatch & tDst, const CSphMatch & tSrc, const VecTraits_T<int> & dSpecials );
static void MovePtrsSpecial ( CSphMatch & tDst, CSphMatch & tSrc, const VecTraits_T<int> & dSpecials );
protected:
CSphVector<int> m_dDataPtrAttrs; ///< rowitems of pointers to data that are stored inside matches
CSphVector<int> m_dDynamicUsed; ///< dynamic row part map
/// generic InsertAttr() implementation that tracks data ptr attributes
void InsertAttr ( CSphVector<CSphColumnInfo> & dAttrs, CSphVector<int> & dUsed, int iPos, const CSphColumnInfo & tCol, bool bDynamic );
void ResetSchemaHelper();
void CopyPtrs ( CSphMatch & tDst, const CSphMatch & rhs ) const;
};
void CSphSchemaHelper::CloneMatchSpecial ( CSphMatch & tDst, const CSphMatch & rhs, const VecTraits_T<int> & dSpecials ) const
{
FreeDataSpecial ( tDst, dSpecials );
tDst.Combine ( rhs, GetDynamicSize() );
for ( auto i : m_dDataPtrAttrs )
*(BYTE**)( tDst.m_pDynamic + i ) = nullptr;
CopyPtrsSpecial ( tDst, rhs, dSpecials );
}
// fixme! direct reinterpreting rows is not good idea. Use sphGetAttr/sphSetAttr!
/*
* wide (64bit) attributes occupies 2 rows and placed order lo,high
* On LE arch (intel) it is ok to reinterpret them back as 64-bit pointer
* However on BE (mips) you have problems since such cast gives garbage.
*/
void CSphSchemaHelper::FreeDataSpecial ( CSphMatch & tMatch, const VecTraits_T<int> & dSpecials )
{
if ( !tMatch.m_pDynamic )
return;
for ( auto iOffset : dSpecials )
{
BYTE*& pData = *(BYTE**)( tMatch.m_pDynamic + iOffset );
sphDeallocatePacked ( pData );
pData = nullptr;
}
}
void CSphSchemaHelper::CopyPtrsSpecial ( CSphMatch & tDst, const CSphMatch & tSrc, const VecTraits_T<int> & dSpecials )
{
auto pSrc = tSrc.m_pDynamic;
assert ( pSrc || dSpecials.IsEmpty() );
for ( auto i : dSpecials )
{
const BYTE* pData = *(BYTE**)( pSrc + i );
if ( pData )
*(BYTE**)( tDst.m_pDynamic + i ) = sph::CopyPackedAttr ( pData );
}
}
| 3,515
|
C++
|
.h
| 76
| 44.368421
| 136
| 0.740795
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,279
|
schema.h
|
manticoresoftware_manticoresearch/src/schema/schema.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "helper.h"
class CSphSourceSettings;
/// plain good old schema
/// container that actually holds and owns all the fields, columns, etc
///
/// NOTE that while this one can be used everywhere where we need a schema
/// it might be huge (say 1000+ attributes) and expensive to copy, modify, etc!
/// so for most of the online query work, consider CSphRsetSchema
class CSphSchema final : public CSphSchemaHelper
{
friend class CSphRsetSchema;
public:
/// ctor
explicit CSphSchema ( CSphString sName="(nameless)" );
CSphSchema ( const CSphSchema & rhs );
CSphSchema ( CSphSchema && rhs ) noexcept;
void Swap ( CSphSchema & rhs ) noexcept;
CSphSchema & operator = ( const ISphSchema & rhs );
CSphSchema & operator = ( CSphSchema rhs );
/// visitor-style uber-virtual assignment implementation
void AssignTo ( CSphRsetSchema & lhs ) const final;
const char * GetName() const final;
void AddAttr ( const CSphColumnInfo & tAttr, bool bDynamic ) final;
void AddField ( const char * sFieldName );
void AddField ( const CSphColumnInfo & tField );
/// remove field
void RemoveField ( const char * szFieldName );
void RemoveField ( int iIdx );
/// get field index by name
/// returns -1 if not found
int GetFieldIndex ( const char * sName ) const final;
/// get attribute index by name
/// returns -1 if not found
int GetAttrIndex ( const char * sName ) const final;
/// checks if two schemas fully match (ie. fields names, attr names, types and locators are the same)
/// describe mismatch (if any) to sError
bool CompareTo ( const CSphSchema & rhs, CSphString & sError, bool bFullComparison = true, bool bIndexLoadCheck=false ) const;
/// reset fields and attrs
void Reset ();
/// get row size (static+dynamic combined)
int GetRowSize () const final { return GetStaticSize () + GetDynamicSize(); }
/// get static row part size
int GetStaticSize () const final { return m_dStaticUsed.GetLength(); }
int GetAttrsCount () const final { return m_dAttrs.GetLength(); }
int GetFieldsCount() const final { return m_dFields.GetLength(); }
const CSphColumnInfo & GetField ( int iIndex ) const final { return m_dFields[iIndex]; }
const CSphColumnInfo * GetField ( const char * szName ) const final;
const CSphVector<CSphColumnInfo> & GetFields () const final { return m_dFields; }
// most of the time we only need to get the field name
const char * GetFieldName ( int iIndex ) const { return m_dFields[iIndex].m_sName.cstr(); }
/// get attr by index
const CSphColumnInfo & GetAttr ( int iIndex ) const final { return m_dAttrs[iIndex]; }
/// get attr by name
const CSphColumnInfo * GetAttr ( const char * sName ) const final;
/// insert attr
void InsertAttr ( int iPos, const CSphColumnInfo & tAggr, bool bDynamic );
/// remove attr
void RemoveAttr ( const char * szAttr, bool bDynamic );
/// get the first one of field length attributes. return -1 if none exist
int GetAttrId_FirstFieldLen() const final;
/// get the last one of field length attributes. return -1 if none exist
int GetAttrId_LastFieldLen() const final;
static bool IsReserved ( const char * szToken );
/// full copy, both static & dynamic became pure dynamic
void CloneWholeMatch ( CSphMatch & tDst, const CSphMatch & rhs ) const;
/// update wordpart settings for a field
void SetFieldWordpart ( int iField, ESphWordpart eWordpart );
void SwapAttrs ( CSphVector<CSphColumnInfo> & dAttrs ) final;
ISphSchema * CloneMe () const final;
bool HasBlobAttrs() const;
int GetCachedRowSize() const;
void SetupFlags ( const CSphSourceSettings & tSettings, bool bPQ, StrVec_t * pWarnings );
bool HasStoredFields() const;
bool HasStoredAttrs() const;
bool HasColumnarAttrs() const;
bool HasNonColumnarAttrs() const;
bool HasKNNAttrs() const;
bool HasJsonSIAttrs() const;
bool IsFieldStored ( int iField ) const;
bool IsAttrStored ( int iAttr ) const;
private:
static const int HASH_THRESH = 32;
static const int BUCKET_COUNT = 256;
WORD m_dBuckets [ BUCKET_COUNT ]; ///< uses indexes in m_dAttrs as ptrs; 0xffff is like NULL in this hash
CSphString m_sName; ///< my human-readable name
int m_iFirstFieldLenAttr = -1;///< position of the first field length attribute (cached on insert/delete)
int m_iLastFieldLenAttr = -1; ///< position of the last field length attribute (cached on insert/delete)
int m_iRowSize = 0; ///< cached row size
CSphVector<CSphColumnInfo> m_dFields; ///< my fulltext-searchable fields
CSphVector<CSphColumnInfo> m_dAttrs; ///< all my attributes
CSphVector<int> m_dStaticUsed; ///< static row part map (amount of used bits in each rowitem)
/// returns 0xffff if bucket list is empty and position otherwise
WORD & GetBucketPos ( const char * sName );
/// reset hash and re-add all attributes
void RebuildHash ();
/// rebuild the attribute value array
void RebuildLocators();
/// add iAddVal to all indexes strictly greater than iStartIdx in hash structures
void UpdateHash ( int iStartIdx, int iAddVal );
void SetupColumnarFlags ( const CSphSourceSettings & tSettings, StrVec_t * pWarnings );
void SetupKNNFlags ( const CSphSourceSettings & tSettings );
void SetupSIFlags ( const CSphSourceSettings & tSettings, StrVec_t * pWarnings );
};
void sphFixupLocator ( CSphAttrLocator & tLocator, const ISphSchema * pOldSchema, const ISphSchema * pNewSchema );
| 6,088
|
C++
|
.h
| 116
| 50.206897
| 131
| 0.719541
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,280
|
rset.h
|
manticoresoftware_manticoresearch/src/schema/rset.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "schema.h"
/// lightweight schema to be used in sorters, result sets, etc
/// avoids copying of static attributes part by keeping a pointer
/// manages the additional dynamic attributes on its own
///
/// NOTE that for that reason CSphRsetSchema needs the originating index to exist
/// (in case it keeps and uses a pointer to original schema in that index)
class CSphRsetSchema: public CSphSchemaHelper
{
public:
CSphRsetSchema() = default;
CSphRsetSchema ( const CSphRsetSchema& rhs );
CSphRsetSchema ( CSphRsetSchema&& rhs ) noexcept { Swap (rhs); }
CSphRsetSchema & operator = ( const ISphSchema& rhs );
CSphRsetSchema & operator = ( const CSphSchema& rhs );
CSphRsetSchema& operator= ( CSphRsetSchema rhs ) noexcept
{
Swap ( rhs );
return *this;
}
void AddAttr ( const CSphColumnInfo& tCol, bool bDynamic ) final;
void AssignTo ( CSphRsetSchema& lhs ) const final { lhs = *this; }
const char * GetName() const final;
void Swap ( CSphRsetSchema& rhs ) noexcept;
public:
int GetRowSize() const final;
int GetStaticSize() const final;
int GetAttrsCount() const final;
int GetFieldsCount() const final;
int GetAttrIndex ( const char* sName ) const final;
int GetAttrIndexOriginal ( const char * szName ) const final;
int GetFieldIndex ( const char* sName ) const final;
const CSphColumnInfo & GetField ( int iIndex ) const final;
const CSphColumnInfo * GetField ( const char * szName ) const final;
const CSphVector<CSphColumnInfo> & GetFields() const final;
const CSphColumnInfo & GetAttr ( int iIndex ) const final;
const CSphColumnInfo * GetAttr ( const char * szName ) const final;
int GetAttrId_FirstFieldLen() const final;
int GetAttrId_LastFieldLen() const final;
public:
void RemoveStaticAttr ( int iAttr );
void ResetRsetSchema();
bool IsRemovedAttr ( int iAttr ) const;
public:
/// swap in a subset of current attributes, with not necessarily (!) unique names
/// used to create a network result set (ie. rset to be sent and then discarded)
/// WARNING, DO NOT USE THIS UNLESS ABSOLUTELY SURE!
void SwapAttrs ( CSphVector<CSphColumnInfo>& dAttrs ) final;
ISphSchema * CloneMe() const final;
protected:
const CSphSchema * m_pIndexSchema = nullptr; ///< original index schema, for the static part
CSphVector<CSphColumnInfo> m_dExtraAttrs; ///< additional dynamic attributes, for the dynamic one
CSphVector<int> m_dRemoved; ///< original indexes that are suppressed from the index schema by RemoveStaticAttr()
private:
int ActualLen() const; ///< len of m_pIndexSchema accounting removed stuff
};
| 3,100
|
C++
|
.h
| 68
| 43.573529
| 121
| 0.75174
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,281
|
locator.h
|
manticoresoftware_manticoresearch/src/schema/locator.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include <cstdint>
#include "sphinxdefs.h"
/// attribute locator within the row
struct CSphAttrLocator
{
int m_iBitOffset = -1;
int m_iBitCount = -1;
int m_iBlobAttrId = -1;
int m_iBlobRowOffset = 1;
int m_nBlobAttrs = 0;
bool m_bDynamic = true;
// todo: don't forget to update sphCalcLocatorHash when adding fields!
CSphAttrLocator () = default;
explicit CSphAttrLocator ( int iBitOffset, int iBitCount=ROWITEM_BITS );
inline bool IsBitfield () const;
int CalcRowitem () const;
bool IsBlobAttr() const;
void Reset();
// just sphFNV64 (&loc,sizeof(loc)) isn't correct as members are not aligned
uint64_t FNV ( uint64_t uHash ) const;
#ifndef NDEBUG
/// get last item touched by this attr (for debugging checks only)
int GetMaxRowitem () const;
#endif
bool operator == ( const CSphAttrLocator & rhs ) const;
};
SphAttr_t sphGetRowAttr ( const CSphRowitem* pRow, const CSphAttrLocator& tLoc );
void sphSetRowAttr ( CSphRowitem* pRow, const CSphAttrLocator& tLoc, SphAttr_t uValue );
/// add numeric value of another attribute
void sphAddCounterAttr ( CSphRowitem* pRow, const CSphRowitem* pVal, const CSphAttrLocator& tLoc );
/// add scalar value to aligned numeric attribute
void sphAddCounterScalar ( CSphRowitem* pRow, const CSphAttrLocator& tLoc, SphAttr_t uValue );
#include "locator_impl.h"
| 1,839
|
C++
|
.h
| 45
| 39.066667
| 99
| 0.753378
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,282
|
locator_impl.h
|
manticoresoftware_manticoresearch/src/schema/locator_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#pragma once
#include "std/fnv64.h"
inline CSphAttrLocator::CSphAttrLocator ( int iBitOffset, int iBitCount )
: m_iBitOffset ( iBitOffset )
, m_iBitCount ( iBitCount )
{}
inline bool CSphAttrLocator::IsBitfield() const
{
return ( m_iBitCount < ROWITEM_BITS || ( m_iBitOffset % ROWITEM_BITS ) != 0 );
}
inline int CSphAttrLocator::CalcRowitem() const
{
return IsBitfield() ? -1 : ( m_iBitOffset / ROWITEM_BITS );
}
inline bool CSphAttrLocator::IsBlobAttr() const
{
return m_iBlobAttrId >= 0;
}
inline void CSphAttrLocator::Reset()
{
m_iBitOffset = -1;
m_iBitCount = -1;
m_iBlobAttrId = -1;
m_iBlobRowOffset = 1;
m_nBlobAttrs = 0;
m_bDynamic = true;
}
// just sphFNV64 (&loc,sizeof(loc)) isn't correct as members are not aligned
inline uint64_t CSphAttrLocator::FNV ( uint64_t uHash ) const
{
BYTE sBuf[sizeof ( CSphAttrLocator )];
auto* p = sBuf;
sphUnalignedWrite ( p, m_iBitOffset );
p += sizeof ( m_iBitOffset );
sphUnalignedWrite ( p, m_iBitCount );
p += sizeof ( m_iBitCount );
sphUnalignedWrite ( p, m_iBlobAttrId );
p += sizeof ( m_iBlobAttrId );
sphUnalignedWrite ( p, m_iBlobRowOffset );
p += sizeof ( m_iBlobRowOffset );
sphUnalignedWrite ( p, m_nBlobAttrs );
p += sizeof ( m_nBlobAttrs );
sphUnalignedWrite ( p, m_bDynamic );
p += sizeof ( m_bDynamic );
return sphFNV64 ( sBuf, (int)( p - sBuf ), uHash );
}
#ifndef NDEBUG
/// get last item touched by this attr (for debugging checks only)
inline int CSphAttrLocator::GetMaxRowitem() const
{
return ( m_iBitOffset + m_iBitCount - 1 ) / ROWITEM_BITS;
}
#endif
inline bool CSphAttrLocator::operator== ( const CSphAttrLocator& rhs ) const
{
if ( m_iBlobAttrId == -1 )
return m_bDynamic == rhs.m_bDynamic && m_iBitOffset == rhs.m_iBitOffset && m_iBitCount == rhs.m_iBitCount;
else
return m_bDynamic == rhs.m_bDynamic && m_iBlobAttrId == rhs.m_iBlobAttrId && m_nBlobAttrs == rhs.m_nBlobAttrs;
}
FORCE_INLINE SphAttr_t sphGetRowAttr ( const CSphRowitem * pRow, const CSphAttrLocator & tLoc )
{
assert(pRow);
assert ( tLoc.m_iBitCount );
int iItem = tLoc.m_iBitOffset >> ROWITEM_SHIFT;
switch ( tLoc.m_iBitCount )
{
case ROWITEM_BITS:
return SphAttr_t ( pRow[iItem] );
case 2*ROWITEM_BITS:
#if USE_LITTLE_ENDIAN
return *(SphAttr_t*) (const_cast<CSphRowitem*>(pRow) + iItem);
#else
return SphAttr_t ( pRow[iItem] ) + ( SphAttr_t ( pRow[iItem+1] ) << ROWITEM_BITS ); break;
#endif
default: break;
}
auto iShift = tLoc.m_iBitOffset & (( 1 << ROWITEM_SHIFT )-1 );
return ( pRow[iItem] >> iShift ) & (( 1UL << tLoc.m_iBitCount )-1 );
}
FORCE_INLINE void sphSetRowAttr ( CSphRowitem * pRow, const CSphAttrLocator & tLoc, SphAttr_t uValue )
{
assert(pRow);
assert ( tLoc.m_iBitCount );
int iItem = tLoc.m_iBitOffset >> ROWITEM_SHIFT;
if ( tLoc.m_iBitCount==2*ROWITEM_BITS )
{
// FIXME? write a generalized version, perhaps
#if USE_LITTLE_ENDIAN
memcpy( pRow+iItem, &uValue, ROWITEM_BITS/4 ); // actually it became 1 op in release asm
#else
pRow[iItem] = CSphRowitem ( uValue & ( ( SphAttr_t(1) << ROWITEM_BITS )-1 ) );
pRow[iItem+1] = CSphRowitem ( uValue >> ROWITEM_BITS );
#endif
} else if ( tLoc.m_iBitCount==ROWITEM_BITS )
{
memcpy ( pRow+iItem, &uValue, ROWITEM_BITS / 8 );
} else
{
int iShift = tLoc.m_iBitOffset & ( ( 1 << ROWITEM_SHIFT )-1);
CSphRowitem uMask = ( ( 1UL << tLoc.m_iBitCount )-1 ) << iShift;
pRow[iItem] &= ~uMask;
pRow[iItem] |= ( uMask & ( uValue << iShift ) );
}
}
/// add numeric value of another attribute
inline void sphAddCounterAttr ( CSphRowitem * pRow, const CSphRowitem * pVal, const CSphAttrLocator & tLoc )
{
assert( pRow && pVal);
int iItem = tLoc.m_iBitOffset >> ROWITEM_SHIFT;
SphAttr_t uValue;
switch (tLoc.m_iBitCount )
{
case ROWITEM_BITS:
uValue = SphAttr_t ( pRow[iItem] ) + SphAttr_t ( pVal[iItem] );
memcpy ( pRow+iItem, &uValue, ROWITEM_BITS / 8 );
return;
case 2*ROWITEM_BITS:
#if USE_LITTLE_ENDIAN
uValue = *(SphAttr_t *) ( pRow+iItem ) +*(SphAttr_t *) ( const_cast<CSphRowitem*>(pVal)+iItem );
memcpy ( pRow+iItem, &uValue, ROWITEM_BITS / 4 );
#else
uValue = SphAttr_t ( pRow[iItem] ) + ( SphAttr_t ( pRow[iItem+1] ) << ROWITEM_BITS )
+SphAttr_t ( pVal[iItem] ) + ( SphAttr_t ( pVal[iItem+1] ) << ROWITEM_BITS );
pRow[iItem] = CSphRowitem ( uValue & ( ( SphAttr_t(1) << ROWITEM_BITS )-1 ) );
pRow[iItem+1] = CSphRowitem ( uValue >> ROWITEM_BITS );
#endif
return;
default: break;
}
assert ( false && "Unable to add non-aligned attribute " );
}
/// add scalar value to aligned numeric attribute
inline void sphAddCounterScalar ( CSphRowitem * pRow, const CSphAttrLocator & tLoc, SphAttr_t uValue )
{
assert( pRow );
int iItem = tLoc.m_iBitOffset >> ROWITEM_SHIFT;
switch (tLoc.m_iBitCount )
{
case ROWITEM_BITS:
uValue += SphAttr_t ( pRow[iItem] );
memcpy ( pRow+iItem, &uValue, ROWITEM_BITS / 8 );
return;
case 2*ROWITEM_BITS:
#if USE_LITTLE_ENDIAN
uValue += *(SphAttr_t *) ( pRow+iItem );
memcpy ( pRow+iItem, &uValue, ROWITEM_BITS / 4 );
#else
uValue += SphAttr_t ( pRow[iItem] ) + ( SphAttr_t ( pRow[iItem+1] ) << ROWITEM_BITS );
pRow[iItem] = CSphRowitem ( uValue & ( ( SphAttr_t(1) << ROWITEM_BITS )-1 ) );
pRow[iItem+1] = CSphRowitem ( uValue >> ROWITEM_BITS );
#endif
return;
default: break;
}
assert ( false && "Unable to add non-aligned attribute " );
}
| 5,794
|
C++
|
.h
| 168
| 32.535714
| 112
| 0.6932
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,284
|
indexlink.h
|
manticoresoftware_manticoresearch/src/detail/indexlink.h
|
//
// Copyright (c) 2023-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/string.h"
// if sBase differs from sNewPath - write .link file with sNewPath. Otherwise unlink .link file, if any.
bool WriteLinkFile ( const CSphString& sBase, const CSphString& sNewPath, CSphString& sError );
// if .link file exists in sBase - read it and return it's content. Otherwise return sBase unchanged.
CSphString RedirectToRealPath ( CSphString sBase );
| 870
|
C++
|
.h
| 17
| 50
| 104
| 0.764706
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,285
|
coroutine_impl.h
|
manticoresoftware_manticoresearch/src/detail/coroutine_impl.h
|
//
// Copyright (c) 2022-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
// that file includes implementation details from coroutine.h
namespace Threads
{
/////////////////////////////////////////////////////////////////////////////
/// ClonableCtx_T
/////////////////////////////////////////////////////////////////////////////
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
template<typename... PARAMS>
ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::ClonableCtx_T ( PARAMS&&... tParams )
: m_dParentContext ( std::forward<PARAMS> ( tParams )... )
{
m_bSingle = !m_dParentContext.IsClonable();
}
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
void ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::LimitConcurrency ( int iDistThreads )
{
assert ( m_iTasks == 0 ); // can be run only when no work started
if ( m_bSingle || !iDistThreads ) // 0 as for dist_threads means 'no limit'
return;
auto iContexts = iDistThreads - 1; // one context is always clone-free
if ( !iContexts )
{
m_bSingle = true;
return;
}
m_dChildrenContexts.Reset ( iContexts );
m_dJobsOrder.Reset ( iContexts );
m_dJobsOrder.ZeroVec();
}
// called once per coroutine, when it really has to process something
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
template<ECONTEXT ORD>
std::enable_if_t<ORD == ECONTEXT::ORDERED, std::pair<REFCONTEXT, int>> ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::CloneNewContext ( bool bFirst )
{
if ( m_bSingle || bFirst )
return { m_dParentContext, 0 };
auto iMyIdx = m_iTasks.fetch_add ( 1, std::memory_order_relaxed );
auto& tCtx = m_dChildrenContexts[iMyIdx];
if ( !tCtx )
tCtx.emplace ( m_dParentContext );
return { (REFCONTEXT)tCtx.value(), iMyIdx + 1 };
}
// called once per coroutine, when it really has to process something
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
template<ECONTEXT ORD>
std::enable_if_t<ORD == ECONTEXT::UNORDERED, std::pair<REFCONTEXT, int>> ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::CloneNewContext ()
{
if ( m_bSingle )
return { m_dParentContext, 0 };
auto iMyIdx = m_iTasks.fetch_add ( 1, std::memory_order_relaxed );
if ( !iMyIdx )
return { m_dParentContext, 0 };
--iMyIdx; // make it back 0-based
auto& tCtx = m_dChildrenContexts[iMyIdx];
if ( !tCtx )
tCtx.emplace ( m_dParentContext );
return { (REFCONTEXT)tCtx.value(), iMyIdx + 1 };
}
// set (optionally) 'weight' of a job; ForAll will iterate jobs according to ascending weights
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
template<ECONTEXT ORD>
std::enable_if_t<ORD == ECONTEXT::ORDERED> ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::SetJobOrder ( int iCtxID, int iOrder )
{
assert ( iCtxID < m_iTasks + 1 );
if ( !iCtxID ) // todo! zero (parent) context doesn't have an order
return;
m_dJobsOrder[iCtxID - 1] = iOrder;
}
// Num of parallel workers to complete iTasks jobs
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
inline bool ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::IsSingle () const
{
return m_bSingle;
}
// Num of parallel workers to complete iTasks jobs
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
inline int ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::Concurrency ( int iTasks ) const
{
return Min ( m_dChildrenContexts.GetLength() + 1, iTasks ); // +1 since parent is also an extra context
}
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
int ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::NumWorked() const
{
return m_iTasks.load ( std::memory_order_relaxed );
}
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
template<typename FNPROCESSOR, ECONTEXT ORD>
std::enable_if_t<ORD == ECONTEXT::ORDERED> ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::ForAll ( FNPROCESSOR fnProcess, bool bIncludeRoot )
{
assert ( !bIncludeRoot ); // for ordered context it should not be set
if ( m_bSingle ) // nothing to do; sorters and results are already original
return;
int iWorkedThreads = m_iTasks; // NOT - 1, as we didn't account parent context in the counter
CSphFixedVector<int> dOrder { iWorkedThreads };
dOrder.FillSeq();
dOrder.Sort ( Lesser ( [this] ( int a, int b ) { return m_dJobsOrder[a] < m_dJobsOrder[b]; } ) );
for ( auto i : dOrder )
{
assert ( m_dChildrenContexts[i] );
auto tCtx = (REFCONTEXT)m_dChildrenContexts[i].value();
fnProcess ( tCtx );
}
}
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
template<typename FNPROCESSOR, ECONTEXT ORD>
std::enable_if_t<ORD == ECONTEXT::UNORDERED> ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::ForAll ( FNPROCESSOR fnProcess, bool bIncludeRoot )
{
if ( bIncludeRoot )
fnProcess ( m_dParentContext );
if ( m_bSingle ) // nothing to do; sorters and results are already original
return;
int iWorkedThreads = m_iTasks - 1;
CSphFixedVector<int> dOrder { iWorkedThreads };
dOrder.FillSeq();
dOrder.Sort ( Lesser ( [this] ( int a, int b ) { return m_dJobsOrder[a] < m_dJobsOrder[b]; } ) );
for ( auto i : dOrder )
{
assert ( m_dChildrenContexts[i] );
auto tCtx = (REFCONTEXT)m_dChildrenContexts[i].value();
fnProcess ( tCtx );
}
}
template<typename REFCONTEXT, typename CONTEXT, ECONTEXT IS_ORDERED>
void ClonableCtx_T<REFCONTEXT, CONTEXT, IS_ORDERED>::Finalize()
{
ForAll ( [this] ( REFCONTEXT tContext ) { m_dParentContext.MergeChild ( tContext ); }, false );
}
/////////////////////////////////////////////////////////////////////////////
/// HighFreqChecker_c
/////////////////////////////////////////////////////////////////////////////
inline bool Coro::HighFreqChecker_c::operator()()
{
using namespace std::chrono;
if ( !m_iPivotPeriod )
return false;
++m_iHits;
if ( !m_iPivotHits )
{
if ( !m_iHits ) // very first run, we know nothing yet.
{
m_tmFirstHit = steady_clock::now();
return false;
}
if ( m_iHits < m_iFibCurrent )
return false;
if ( duration_cast<microseconds> ( steady_clock::now() - m_tmFirstHit ).count() >= m_iPivotPeriod )
{
m_iPivotHits = m_iHits;
} else
{
m_iFibPrev = std::exchange ( m_iFibCurrent, m_iFibCurrent + m_iFibPrev ); // next fibonacci seq number
return false;
}
}
assert ( m_iPivotHits );
if ( m_iHits == m_iPivotHits )
{
m_iHits = 0;
return true;
}
return false;
}
/////////////////////////////////////////////////////////////////////////////
/// ScopedScheduler_c
/////////////////////////////////////////////////////////////////////////////
inline ScopedScheduler_c::ScopedScheduler_c ( SchedRole pRole )
{
if ( !pRole )
return;
m_pRoleRef = Coro::CurrentScheduler();
// if ( m_pRoleRef )
AcquireSched ( pRole );
}
inline ScopedScheduler_c::ScopedScheduler_c ( RoledSchedulerSharedPtr_t& pRole )
{
if ( !pRole )
return;
m_pRoleRef = Coro::CurrentScheduler();
// if ( m_pRoleRef )
AcquireSched ( pRole );
}
inline ScopedScheduler_c::~ScopedScheduler_c()
{
if ( m_pRoleRef )
AcquireSched ( m_pRoleRef );
}
namespace Coro
{
// if iStack<0, just immediately invoke the handler (that is bypass)
template<typename HANDLER>
void Continue ( int iStack, HANDLER&& handler )
{
if ( iStack<0 )
return handler ();
Continue ( std::forward<HANDLER> ( handler ), iStack );
}
// if iStack<0, just immediately invoke the handler (that is bypass). Returns boolean result from handler
template<typename HANDLER>
bool ContinueBool ( int iStack, HANDLER handler )
{
if ( iStack<0 )
return handler ();
bool bResult;
Continue ( [&bResult, fnHandler = std::move ( handler )] { bResult = fnHandler (); }, iStack );
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
/// ConditionVariableAny_c
/////////////////////////////////////////////////////////////////////////////
template<typename LockType>
void ConditionVariableAny_c::Wait ( LockType& tMutex )
{
auto* pActiveWorker = Worker();
// atomically call tMutex.unlock() and block on current worker
// store this coro in waiting-queue
sph::Spinlock_lock tLock { m_tWaitQueueSpinlock };
tMutex.Unlock();
m_tWaitQueue.SuspendAndWait ( tLock, pActiveWorker );
// relock external again before returning
tMutex.Lock();
}
template<typename LockType>
bool ConditionVariableAny_c::WaitUntil ( LockType& tMutex, int64_t iTimestamp )
{
auto* pActiveWorker = Worker();
// atomically call tMutex.unlock() and block on current worker
// store this coro in waiting-queue
sph::Spinlock_lock tLock { m_tWaitQueueSpinlock };
tMutex.Unlock();
bool bResult = m_tWaitQueue.SuspendAndWaitUntil ( tLock, pActiveWorker, iTimestamp );
// relock external again before returning
tMutex.Lock();
return bResult;
}
template<typename LockType>
bool ConditionVariableAny_c::WaitForMs ( LockType& tMutex, int64_t iTimePeriodMS )
{
return WaitUntil ( tMutex, sphMicroTimer() + iTimePeriodMS*1000 );
}
template<typename LockType, typename PRED>
void ConditionVariableAny_c::Wait ( LockType& tMutex, PRED fnPred )
{
while ( !fnPred() ) {
Wait ( tMutex );
}
}
template<typename LockType, typename PRED>
bool ConditionVariableAny_c::WaitUntil ( LockType& tMutex, PRED fnPred, int64_t iTimestamp )
{
while ( !fnPred() ) {
if ( !WaitUntil ( tMutex, iTimestamp ) )
return fnPred();
}
return true;
}
template<typename LockType, typename PRED>
bool ConditionVariableAny_c::WaitForMs ( LockType& tMutex, PRED fnPred, int64_t iTimePeriodMS )
{
return WaitUntil ( tMutex, std::forward<PRED> ( fnPred ), sphMicroTimer() + iTimePeriodMS * 1000 );
}
/////////////////////////////////////////////////////////////////////////////
/// ConditionVariable_c
/////////////////////////////////////////////////////////////////////////////
template<typename PRED>
void ConditionVariable_c::Wait ( ScopedMutex_t& lt, PRED&& fnPred ) REQUIRES ( lt )
{
m_tCnd.Wait ( lt, std::forward<PRED> ( fnPred ) );
}
template<typename PRED>
bool ConditionVariable_c::WaitUntil ( ScopedMutex_t& lt, PRED&& fnPred, int64_t iTime ) REQUIRES ( lt )
{
return m_tCnd.WaitUntil ( lt, std::forward<PRED> ( fnPred ), iTime );
}
template<typename PRED>
bool ConditionVariable_c::WaitForMs ( ScopedMutex_t& lt, PRED&& fnPred, int64_t iPeriodMS ) REQUIRES ( lt )
{
return m_tCnd.WaitForMs ( lt, std::forward<PRED> ( fnPred ), iPeriodMS );
}
/////////////////////////////////////////////////////////////////////////////
/// Waitable_T
/////////////////////////////////////////////////////////////////////////////
template<typename T>
template<typename... PARAMS>
Waitable_T<T>::Waitable_T ( PARAMS&&... tParams )
: m_tValue ( std::forward<PARAMS> ( tParams )... )
{}
template<typename T>
void Waitable_T<T>::SetValue ( T tValue )
{
ScopedMutex_t lk ( m_tMutex );
m_tValue = tValue;
}
template<typename T>
T Waitable_T<T>::ExchangeValue ( T tNewValue )
{
ScopedMutex_t lk ( m_tMutex );
return std::exchange ( m_tValue, tNewValue );
}
template<typename T>
void Waitable_T<T>::SetValueAndNotifyOne ( T tValue )
{
SetValue ( tValue );
NotifyOne();
}
template<typename T>
void Waitable_T<T>::SetValueAndNotifyAll ( T tValue )
{
SetValue ( tValue );
NotifyAll();
}
template<typename T>
void Waitable_T<T>::UpdateValueAndNotifyOne ( T tValue )
{
if ( tValue == GetValue() )
return;
SetValueAndNotifyOne ( tValue );
}
template<typename T>
void Waitable_T<T>::UpdateValueAndNotifyAll ( T tValue )
{
if ( tValue == GetValue() )
return;
SetValueAndNotifyAll ( tValue );
}
template<typename T>
template<typename MOD>
void Waitable_T<T>::ModifyValue ( MOD&& fnMod )
{
ScopedMutex_t lk ( m_tMutex );
fnMod ( m_tValue );
}
template<typename T>
template<typename MOD>
void Waitable_T<T>::ModifyValueAndNotifyOne ( MOD&& fnMod )
{
ModifyValue ( std::forward<MOD> ( fnMod ) );
NotifyOne();
}
template<typename T>
template<typename MOD>
void Waitable_T<T>::ModifyValueAndNotifyAll ( MOD&& fnMod )
{
ModifyValue ( std::forward<MOD> ( fnMod ) );
NotifyAll();
}
template<typename T>
T Waitable_T<T>::GetValue() const
{
return m_tValue;
}
template<typename T>
const T& Waitable_T<T>::GetValueRef() const
{
return m_tValue;
}
template<typename T>
inline void Waitable_T<T>::NotifyOne()
{
m_tCondVar.NotifyOne();
}
template<typename T>
inline void Waitable_T<T>::NotifyAll()
{
m_tCondVar.NotifyAll();
}
template<typename T>
void Waitable_T<T>::Wait () const
{
ScopedMutex_t lk ( m_tMutex );
m_tCondVar.Wait ( lk );
}
template<typename T>
bool Waitable_T<T>::WaitUntil(int64_t iTime) const
{
ScopedMutex_t lk ( m_tMutex );
return m_tCondVar.WaitUntil ( lk, iTime );
}
template<typename T>
bool Waitable_T<T>::WaitForMs(int64_t iPeriodMS) const
{
ScopedMutex_t lk ( m_tMutex );
return m_tCondVar.WaitForMs ( lk, iPeriodMS );
}
template<typename T>
template<typename PRED>
T Waitable_T<T>::Wait ( PRED&& fnPred ) const
{
ScopedMutex_t lk ( m_tMutex );
m_tCondVar.Wait ( lk, [this, fnPred = std::forward<PRED> ( fnPred )]() { return fnPred ( m_tValue ); } );
return m_tValue;
}
template<typename T>
template<typename PRED>
T Waitable_T<T>::WaitUntil ( PRED&& fnPred, int64_t iTime ) const
{
ScopedMutex_t lk ( m_tMutex );
m_tCondVar.WaitUntil ( lk, [this, fnPred = std::forward<PRED> ( fnPred )]() { return fnPred ( m_tValue ); }, iTime );
return m_tValue;
}
template<typename T>
template<typename PRED>
T Waitable_T<T>::WaitForMs ( PRED&& fnPred, int64_t iPeriodMs ) const
{
ScopedMutex_t lk ( m_tMutex );
m_tCondVar.WaitForMs ( lk, [this, fnPred = std::forward<PRED> ( fnPred )]() { return fnPred ( m_tValue ); }, iPeriodMs );
return m_tValue;
}
template<typename T>
template<typename PRED>
void Waitable_T<T>::WaitVoid ( PRED&& fnPred ) const
{
ScopedMutex_t lk ( m_tMutex );
m_tCondVar.Wait ( lk, std::forward<PRED> ( fnPred ) );
}
template<typename T>
template<typename PRED>
bool Waitable_T<T>::WaitVoidUntil ( PRED&& fnPred, int64_t iTime ) const
{
ScopedMutex_t lk ( m_tMutex );
return m_tCondVar.WaitUntil ( lk, std::forward<PRED> ( fnPred ), iTime );
}
template<typename T>
template<typename PRED>
bool Waitable_T<T>::WaitVoidForMs ( PRED&& fnPred, int64_t iPeriodMs ) const
{
ScopedMutex_t lk ( m_tMutex );
return m_tCondVar.WaitForMs ( lk, std::forward<PRED> ( fnPred ), iPeriodMs );
}
} // namespace Coro
} // namespace Threads
| 14,678
|
C++
|
.h
| 441
| 31.54195
| 150
| 0.685248
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,286
|
expmeter.h
|
manticoresoftware_manticoresearch/src/detail/expmeter.h
|
//
// Copyright (c) 2023-2024, Manticore Software LTD (https://manticoresearch.com)
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "std/ints.h"
// implement exponential sliding stat
class ExpMeter_c
{
double m_fSum = 0.0;
double m_fVal = 0.0;
BYTE m_uSamples = 0;
const BYTE m_uTimeConstant;
public:
explicit ExpMeter_c ( BYTE uTimeConstant )
: m_uTimeConstant { uTimeConstant }
{}
[[nodiscard]] double Value() const noexcept { return m_fVal; }
void Reset()
{
m_fSum = 0.0;
m_fVal = 0;
m_uSamples = 0;
}
template<typename NUM>
void Tick ( NUM tSample ) noexcept
{
m_fSum += tSample;
if ( m_uSamples < m_uTimeConstant )
++m_uSamples;
else
m_fSum -= m_fVal;
m_fVal = m_fSum / m_uSamples;
}
};
| 1,005
|
C++
|
.h
| 40
| 23
| 80
| 0.707113
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,287
|
attrstub.h
|
manticoresoftware_manticoresearch/src/std/attrstub.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#if !defined( __GNUC__ ) && !defined( __clang__ )
#define __attribute__( x )
#endif
| 574
|
C++
|
.h
| 15
| 37.133333
| 80
| 0.725314
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,288
|
mutex.h
|
manticoresoftware_manticoresearch/src/std/mutex.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "thread_annotations.h"
#include "generics.h"
#include "ints.h"
#include <mutex>
#if _WIN32
using TMutex = HANDLE;
#else
using TMutex = pthread_mutex_t;
#endif
/// mutex implementation
class CAPABILITY ( "mutex" ) CSphMutex: public ISphNoncopyable
{
public:
CSphMutex() noexcept;
~CSphMutex() noexcept;
bool Lock() ACQUIRE();
bool Unlock() RELEASE();
bool TimedLock ( int iMsec ) TRY_ACQUIRE ( true );
// Just for clang negative capabilities.
const CSphMutex& operator!() const { return *this; }
using mtx = TMutex;
mtx& mutex() RETURN_CAPABILITY ( this )
{
return m_tMutex;
}
protected:
TMutex m_tMutex;
};
#include "scopedlock.h"
using ScopedMutex_t = CSphScopedLock<CSphMutex>;
| 1,201
|
C++
|
.h
| 42
| 27.02381
| 80
| 0.748477
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,289
|
vector_impl.h
|
manticoresoftware_manticoresearch/src/std/vector_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <cassert>
#include "checks.h"
#include "uniq.h"
namespace sph
{
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
inline std::enable_if_t<S::is_sized> Vector_T<T, POLICY, LIMIT, STORE>::Vector_T::Deallocate ( typename STORE::TYPE* pData, int64_t iLimit )
{
STORE::Deallocate ( pData, iLimit );
}
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
inline std::enable_if_t<!S::is_sized> Vector_T<T, POLICY, LIMIT, STORE>::Vector_T::Deallocate ( typename STORE::TYPE* pData, int64_t )
{
STORE::Deallocate ( pData );
}
/* variant below needs C++17
template<class STORE>
inline void Deallocate ( typename STORE::TYPE* pData, int64_t iLimit )
{
if constexpr ( STORE::is_sized )
STORE::Deallocate ( pData, iLimit );
else
STORE::Deallocate ( pData );
}
*/
/// ctor with initial size
template<typename T, class POLICY, class LIMIT, class STORE>
Vector_T<T,POLICY,LIMIT,STORE>::Vector_T ( int64_t iCount )
{
Resize ( iCount );
}
/// copy ctor
template<typename T, class POLICY, class LIMIT, class STORE>
Vector_T<T, POLICY, LIMIT, STORE>::Vector_T ( const Vector_T<T>& rhs )
{
m_iCount = rhs.m_iCount;
m_iLimit = rhs.m_iLimit;
if ( m_iLimit )
m_pData = STORE::Allocate ( m_iLimit );
__analysis_assume ( m_iCount <= m_iLimit );
POLICY::Copy ( m_pData, rhs.m_pData, m_iCount );
}
/// move ctr
template<typename T, class POLICY, class LIMIT, class STORE>
Vector_T<T, POLICY, LIMIT, STORE>::Vector_T ( Vector_T<T>&& rhs ) noexcept
: Vector_T()
{
SwapData ( rhs );
}
/// dtor
template<typename T, class POLICY, class LIMIT, class STORE>
Vector_T<T, POLICY, LIMIT, STORE>::~Vector_T()
{
destroy_at ( 0, m_iCount );
Deallocate ( m_pData, m_iLimit );
}
/// add entry
template<typename T, class POLICY, class LIMIT, class STORE>
T& Vector_T<T, POLICY, LIMIT, STORE>::Add()
{
if ( m_iCount >= m_iLimit )
Reserve ( 1 + m_iCount );
construct_at ( m_iCount, 1 );
return m_pData[m_iCount++];
}
/// add entry
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if_t<S::is_constructed> Vector_T<T, POLICY, LIMIT, STORE>::Add ( T tValue )
{
assert ( ( &tValue < m_pData || &tValue >= ( m_pData + m_iCount ) ) && "inserting own value (like last()) by ref!" );
if ( m_iCount >= m_iLimit )
Reserve ( 1 + m_iCount );
m_pData[m_iCount++] = std::move ( tValue );
}
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if_t<!S::is_constructed> Vector_T<T, POLICY, LIMIT, STORE>::Add ( T tValue )
{
assert ( ( &tValue < m_pData || &tValue >= ( m_pData + m_iCount ) ) && "inserting own value (like last()) by ref!" );
if ( m_iCount >= m_iLimit )
Reserve ( 1 + m_iCount );
new ( m_pData + m_iCount++ ) T ( std::move ( tValue ) );
}
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S, class... Args>
typename std::enable_if_t<!S::is_constructed> Vector_T<T, POLICY, LIMIT, STORE>::Emplace_back ( Args&&... args )
{
assert ( m_iCount <= m_iLimit );
new ( m_pData + m_iCount++ ) T ( std::forward<Args> ( args )... );
}
/// add N more entries, and return a pointer to that buffer
template<typename T, class POLICY, class LIMIT, class STORE>
T* Vector_T<T, POLICY, LIMIT, STORE>::AddN ( int iCount )
{
if ( m_iCount + iCount > m_iLimit )
Reserve ( m_iCount + iCount );
construct_at ( m_iCount, iCount );
m_iCount += iCount;
return m_pData + m_iCount - iCount;
}
/// add unique entry (ie. do not add if equal to last one)
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::AddUnique ( const T& tValue )
{
assert ( ( &tValue < m_pData || &tValue >= ( m_pData + m_iCount ) ) && "inserting own value (like last()) by ref!" );
if ( m_iCount >= m_iLimit )
Reserve ( 1 + m_iCount );
if ( m_iCount == 0 || m_pData[m_iCount - 1] != tValue )
m_pData[m_iCount++] = tValue;
}
/// remove several elements by index
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::Remove ( int iIndex, int iCount )
{
if ( iCount <= 0 )
return;
assert ( iIndex >= 0 && iIndex < m_iCount );
assert ( iIndex + iCount <= m_iCount );
m_iCount -= iCount;
if ( m_iCount > iIndex )
POLICY::Move ( m_pData + iIndex, m_pData + iIndex + iCount, m_iCount - iIndex );
destroy_at ( m_iCount, iCount );
}
/// remove element by index, swapping it with the tail
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::RemoveFast ( int iIndex )
{
assert ( iIndex >= 0 && iIndex < m_iCount );
if ( iIndex != --m_iCount )
Swap ( m_pData[iIndex], m_pData[m_iCount] ); // fixme! What about POLICY::CopyOrSwap here?
destroy_at ( m_iCount, 1 );
}
/// remove element by value (warning, linear O(n) search)
template<typename T, class POLICY, class LIMIT, class STORE>
bool Vector_T<T, POLICY, LIMIT, STORE>::RemoveValue ( T tValue )
{
for ( int i = 0; i < m_iCount; ++i )
if ( m_pData[i] == tValue )
{
Remove ( i );
return true;
}
return false;
}
/// remove element by value, asuming vec is sorted/uniq
template<typename T, class POLICY, class LIMIT, class STORE>
bool Vector_T<T, POLICY, LIMIT, STORE>::RemoveValueFromSorted ( T tValue )
{
T* pValue = VecTraits_T<T>::BinarySearch ( tValue );
if ( !pValue )
return false;
Remove ( int ( pValue - Begin() ) );
return true;
}
/// pop last value by ref (for constructed storage)
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<S::is_constructed, T&>::type Vector_T<T, POLICY, LIMIT, STORE>::Pop()
{
assert ( m_iCount > 0 );
return m_pData[--m_iCount];
}
/// pop last value
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_constructed, T>::type Vector_T<T, POLICY, LIMIT, STORE>::Pop()
{
assert ( m_iCount > 0 );
auto res = m_pData[--m_iCount];
destroy_at ( m_iCount );
return res;
}
/// grow enough to hold iNewLimit-iDiscard entries, if needed.
/// returns updated index of elem iDiscard.
template<typename T, class POLICY, class LIMIT, class STORE>
int Vector_T<T, POLICY, LIMIT, STORE>::DiscardAndReserve ( int64_t iDiscard, int64_t iNewLimit )
{
assert ( iNewLimit >= 0 );
assert ( iDiscard >= 0 );
// check that we really need to be called
if ( iNewLimit <= m_iLimit )
return (int)iDiscard;
if ( iDiscard > 0 )
{
// align limit and size
iNewLimit -= iDiscard;
m_iCount = ( iDiscard < m_iCount ) ? ( m_iCount - iDiscard ) : 0;
// check, if we still need to be called with aligned limit
if ( iNewLimit <= m_iLimit )
{
if ( m_iCount ) // has something to move back
POLICY::Move ( m_pData, m_pData + iDiscard, m_iCount );
return 0;
}
}
// calc new limit
m_iLimit = LIMIT::Relimit ( m_iLimit, std::exchange ( iNewLimit, m_iLimit ) );
// realloc
T* pNew = nullptr;
if ( m_iLimit )
{
pNew = STORE::Allocate ( m_iLimit );
__analysis_assume ( m_iCount - iDiscard <= m_iLimit );
if ( m_iCount ) // has something to copy from an old storage
POLICY::Move ( pNew, m_pData + iDiscard, m_iCount );
if ( pNew == m_pData )
return 0;
}
Swap ( pNew, m_pData );
Deallocate ( pNew, iNewLimit );
return 0;
}
/// grow enough to hold that much entries, if needed, but do *not* change the length
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::Reserve ( int64_t iNewLimit )
{
DiscardAndReserve ( 0, iNewLimit );
}
/// for non-copyable types - work like Reset() + Reserve()
/// destroys previous dataset, allocate new one and set size to 0.
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::Reserve_static ( int64_t iNewLimit )
{
// check that we really need to be called
destroy_at ( 0, m_iCount );
m_iCount = 0;
if ( iNewLimit == m_iLimit )
return;
std::swap ( m_iLimit, iNewLimit );
// realloc
T* pNew = nullptr;
pNew = STORE::Allocate ( m_iLimit );
if ( pNew == m_pData )
return;
__analysis_assume ( m_iCount <= m_iLimit );
std::swap ( pNew, m_pData );
Deallocate ( pNew, iNewLimit );
}
/// ensure we have space for iGap more items (reserve more if necessary)
template<typename T, class POLICY, class LIMIT, class STORE>
inline void Vector_T<T, POLICY, LIMIT, STORE>::ReserveGap ( int iGap )
{
Reserve ( m_iCount + iGap );
}
/// resize
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::Resize ( int64_t iNewLength )
{
assert ( iNewLength >= 0 );
if ( iNewLength > m_iCount )
Reserve ( iNewLength );
m_iCount = iNewLength;
}
/// for non-constructed imply destroy when shrinking, of construct when widening
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::Resize ( int64_t iNewLength )
{
assert ( iNewLength >= 0 );
if ( iNewLength < m_iCount )
destroy_at ( iNewLength, m_iCount - iNewLength );
else
{
Reserve ( iNewLength );
construct_at ( m_iCount, iNewLength - m_iCount );
}
m_iCount = iNewLength;
}
// doesn't need default c-tr
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::Shrink ( int64_t iNewLength )
{
assert ( iNewLength <= m_iCount );
destroy_at ( iNewLength, m_iCount - iNewLength );
m_iCount = iNewLength;
}
/// reset
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::Reset()
{
Shrink ( 0 );
Deallocate ( m_pData, m_iLimit );
m_pData = nullptr;
m_iLimit = 0;
}
/// Set whole vec to 0. For trivially copyable memset will be used
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::ZeroVec()
{
POLICY::Zero ( m_pData, m_iLimit );
}
/// set the tail [m_iCount..m_iLimit) to zero
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::ZeroTail()
{
if ( !m_pData )
return;
POLICY::Zero ( &m_pData[m_iCount], m_iLimit - m_iCount );
}
/// query current reserved size, in elements
template<typename T, class POLICY, class LIMIT, class STORE>
int Vector_T<T, POLICY, LIMIT, STORE>::GetLimit() const
{
return (int)m_iLimit;
}
/// query currently allocated RAM, in bytes
/// (could be > GetLengthBytes() since uses limit, not size)
template<typename T, class POLICY, class LIMIT, class STORE>
int64_t Vector_T<T, POLICY, LIMIT, STORE>::AllocatedBytes() const
{
return (int)m_iLimit * sizeof ( T );
}
/// filter unique
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::Uniq ( bool bSort )
{
if ( !m_iCount )
return;
if ( bSort )
Sort();
int64_t iLeft = sphUniq ( m_pData, m_iCount );
Shrink ( iLeft );
}
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::MergeSorted ( const Vector_T<T>& dA, const Vector_T<T>& dB )
{
// fixme: add comparators
int iLenA = dA.GetLength();
int iLenB = dB.GetLength();
Resize ( iLenA + iLenB );
T* pA = dA.Begin();
T* pB = dB.Begin();
T* pRes = Begin();
const T* pMaxA = pA + iLenA;
const T* pMaxB = pB + iLenB;
while ( pA < pMaxA && pB < pMaxB )
*pRes++ = *pA < *pB ? *pA++ : *pB++;
while ( pA < pMaxA )
*pRes++ = *pA++;
while ( pB < pMaxB )
*pRes++ = *pB++;
}
/// copy + move
// if provided lvalue, it will be copied into rhs via copy ctr, then swapped to *this
// if provided rvalue, it will just pass to SwapData immediately.
template<typename T, class POLICY, class LIMIT, class STORE>
Vector_T<T, POLICY, LIMIT, STORE>& Vector_T<T, POLICY, LIMIT, STORE>::operator= ( Vector_T<T> rhs ) noexcept
{
SwapData ( rhs );
return *this;
}
template<typename T, class POLICY, class LIMIT, class STORE>
bool Vector_T<T, POLICY, LIMIT, STORE>::operator== ( const Vector_T<T>& rhs ) noexcept
{
if ( m_iCount != rhs.m_iCount )
return false;
for ( int i = 0; i < m_iCount; i++ )
if ( m_pData[i] != rhs.m_pData[i] )
return false;
return true;
}
/// memmove N elements from raw pointer to the end
/// works ONLY if T is POD type (i.e. may be simple memmoved)
/// otherwize compile error will appear (if so, use typed version below).
template<typename T, class POLICY, class LIMIT, class STORE>
void Vector_T<T, POLICY, LIMIT, STORE>::Append ( const void* pData, int iN )
{
if ( iN <= 0 )
return;
auto* pDst = AddN ( iN );
POLICY::CopyVoid ( pDst, pData, iN );
}
/// append another vec to the end
/// will use memmove (POD case), or one-by-one copying.
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::Append ( const VecTraits_T<T>& rhs )
{
if ( rhs.IsEmpty() )
return;
auto* pDst = AddN ( rhs.GetLength() );
POLICY::Copy ( pDst, rhs.begin(), rhs.GetLength() );
}
/// append another vec to the end for non-constructed
/// will construct in-place with copy c-tr
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::Append ( const VecTraits_T<T>& rhs )
{
if ( rhs.IsEmpty() )
return;
auto iRhsLen = rhs.GetLength64();
if ( m_iCount + iRhsLen > m_iLimit )
Reserve ( m_iCount + iRhsLen );
for ( int i = 0; i < iRhsLen; ++i )
new ( m_pData + m_iCount + i ) T ( rhs[i] );
m_iCount += iRhsLen;
}
/// swap
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename L, typename S>
typename std::enable_if<!S::is_owned>::type Vector_T<T, POLICY, LIMIT, STORE>::SwapData ( Vector_T<T, POLICY, L, STORE>& rhs ) noexcept
{
Swap ( m_iCount, rhs.m_iCount );
Swap ( m_iLimit, rhs.m_iLimit );
Swap ( m_pData, rhs.m_pData );
}
/// leak
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_owned, T*>::type Vector_T<T, POLICY, LIMIT, STORE>::LeakData()
{
T* pData = m_pData;
m_pData = nullptr;
Reset();
return pData;
}
/// adopt external buffer
/// note that caller must himself then nullify origin pData to avoid double-deletion
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_owned>::type Vector_T<T, POLICY, LIMIT, STORE>::AdoptData ( T* pData, int64_t iLen, int64_t iLimit )
{
assert ( iLen >= 0 );
assert ( iLimit >= 0 );
assert ( pData || iLimit == 0 );
assert ( iLen <= iLimit );
Reset();
m_pData = pData;
m_iLimit = iLimit;
m_iCount = iLen;
}
/// insert into a middle by policy-defined copier
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename TT>
void Vector_T<T, POLICY, LIMIT, STORE>::Insert ( int64_t iIndex, TT&& tValue )
{
assert ( iIndex >= 0 && iIndex <= m_iCount );
if ( this->m_iCount >= this->m_iLimit )
Reserve ( this->m_iCount + 1 );
for ( auto i = this->m_iCount - 1; i >= iIndex; --i )
POLICY::CopyOrSwap ( this->m_pData[i + 1], this->m_pData[i] );
POLICY::CopyOrSwap ( this->m_pData[iIndex], std::forward<TT> ( tValue ) );
++this->m_iCount;
}
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::destroy_at ( int64_t iIndex, int64_t iCount )
{
for ( int64_t i = 0; i < iCount; ++i )
m_pData[iIndex + i].~T();
}
template<typename T, class POLICY, class LIMIT, class STORE>
template<typename S>
typename std::enable_if<!S::is_constructed>::type Vector_T<T, POLICY, LIMIT, STORE>::construct_at ( int64_t iIndex, int64_t iCount )
{
assert ( m_pData );
for ( int64_t i = 0; i < iCount; ++i )
new ( m_pData + iIndex + i ) T();
}
} // namespace sph
| 16,500
|
C++
|
.h
| 478
| 32.746862
| 140
| 0.689558
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,290
|
tdigest.h
|
manticoresoftware_manticoresearch/src/std/tdigest.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
#include <memory>
//////////////////////////////////////////////////////////////////////////
class TDigest_c
{
class Impl_c;
std::unique_ptr<Impl_c> m_pImpl;
public:
TDigest_c();
~TDigest_c();
void Add ( double fValue, int64_t iWeight = 1 );
double Percentile ( int iPercent ) const noexcept;
};
std::unique_ptr<TDigest_c> sphCreateTDigest();
| 862
|
C++
|
.h
| 26
| 31.653846
| 80
| 0.675513
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,291
|
stringbuilder.h
|
manticoresoftware_manticoresearch/src/std/stringbuilder.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "blobs.h"
#include "ints.h"
#include "generics.h"
#include "string.h"
#include "variant.h"
#include "comma.h"
#include <type_traits>
#include <functional>
using StrBlock_t = std::tuple<Str_t, Str_t, Str_t>;
// common patterns
inline const StrBlock_t dEmptyBl { dEmptyStr, dEmptyStr, dEmptyStr }; // empty
inline const StrBlock_t dBracketsComma { FROMS(","), FROMS("("), FROMS(")") }; // collection in brackets, comma separated
/// string builder
/// somewhat quicker than a series of SetSprintf()s
/// lets you build strings bigger than 1024 bytes, too
class StringBuilder_c : public ISphNoncopyable
{
class LazyComma_c;
public:
// creates and m.b. start block
explicit StringBuilder_c ( const char * sDel = nullptr, const char * sPref = nullptr, const char * sTerm = nullptr );
StringBuilder_c ( StringBuilder_c&& rhs ) noexcept;
~StringBuilder_c ();
void Swap ( StringBuilder_c& rhs ) noexcept;
// reset to initial state
void Clear();
// rewind to initial state, but don't clear the commas
void Rewind();
// get current build value
const char * cstr() const { return m_szBuffer ? m_szBuffer : ""; }
explicit operator CSphString() const { return { cstr() }; }
explicit operator Str_t() const { return m_szBuffer ? Str_t { m_szBuffer, (int)m_iUsed } : dEmptyStr; }
explicit operator ByteBlob_t() const { return m_szBuffer ? ByteBlob_t { (const BYTE*) m_szBuffer, (int)m_iUsed } : S2B(dEmptyStr); }
// move out (de-own) value
BYTE * Leak();
void MoveTo ( CSphString &sTarget ); // leak to string
// get state
bool IsEmpty () const { return !m_szBuffer || m_szBuffer[0]=='\0'; }
inline int64_t GetLength () const { return m_iUsed; }
// different kind of fullfillments
StringBuilder_c & AppendChunk ( const Str_t& sChunk, char cQuote = '\0' );
StringBuilder_c & AppendString ( const CSphString & sText, char cQuote = '\0' );
StringBuilder_c & AppendString ( const char* szText, char cQuote = '\0' );
StringBuilder_c & AppendString ( Str_t sText, char cQuote = '\0' );
StringBuilder_c & operator = ( StringBuilder_c rhs ) noexcept;
template<typename T>
StringBuilder_c & operator += ( const T * pVal );
StringBuilder_c & operator += ( const char* sText );
StringBuilder_c & operator << ( const Str_t& sChunk );
StringBuilder_c & operator << ( const VecTraits_T<char> &sText );
/*
* Two guys below distinguishes `const char*` param from `const char[]`.
* First one implies strlen() and uses it
* Second implies length to be known at compile time, and avoids strlen().
* So, << "bar" - will be faster, as we know size of that literal in compile time.
* Look at TEST ( functions, stringbuilder_templated ) for experiments.
*/
template<size_t N>
StringBuilder_c & operator << ( char const(& sLiteral)[N] ) { return *this << Str_t { sLiteral, N-1 }; }
template<typename CHAR>
StringBuilder_c & operator << ( const CHAR * const& sText ) { return *this += sText; }
StringBuilder_c & operator << ( char cChar ) { return *this << Str_t {&cChar,1}; }
StringBuilder_c & operator << ( const CSphString &sText ) { return *this += sText.cstr (); }
StringBuilder_c & operator << ( const CSphVariant &sText ) { return *this += sText.cstr (); }
StringBuilder_c & operator << ( const StringBuilder_c &sText ) { return *this << (Str_t) sText; }
StringBuilder_c & operator << ( Comma_c& dComma ) { return *this << (Str_t)dComma; }
StringBuilder_c & operator << ( int iVal );
StringBuilder_c & operator << ( long iVal );
StringBuilder_c & operator << ( long long iVal );
StringBuilder_c & operator << ( unsigned int uVal );
StringBuilder_c & operator << ( unsigned long uVal );
StringBuilder_c & operator << ( unsigned long long uVal );
StringBuilder_c & operator << ( float fVal );
StringBuilder_c & operator << ( double fVal );
StringBuilder_c & operator << ( bool bVal );
// support for sph::Sprintf - emulate POD 'char*'
inline StringBuilder_c & operator ++() { GrowEnough ( 1 ); ++m_iUsed; return *this; }
inline void operator += ( int64_t i ) { GrowEnough ( i ); m_iUsed += i; }
inline void SetPos ( const char* sPos ) { assert (sPos>=m_szBuffer && sPos<m_szBuffer+m_iSize); m_iUsed = sPos-m_szBuffer; }; // helper. sPos must point inside existing buf
// append 1 char despite any blocks.
inline void RawC ( char cChar ) { GrowEnough ( 1 ); *end () = cChar; ++m_iUsed; }
void AppendRawChunk ( Str_t sText ); // append without any commas
StringBuilder_c & SkipNextComma();
StringBuilder_c & AppendName ( const char * szName, bool bQuoted=true ); // append "szName":
StringBuilder_c & AppendName ( const Str_t& sName, bool bQuoted = true ); // append "sName":
// these use standard sprintf() inside
StringBuilder_c & vAppendf ( const char * sTemplate, va_list ap );
StringBuilder_c & Appendf ( const char * sTemplate, ... ) __attribute__ ( ( format ( printf, 2, 3 ) ) );
// these use or own implementation sph::Sprintf which provides also some sugar
StringBuilder_c & vSprintf ( const char * sTemplate, va_list ap );
StringBuilder_c & Sprintf ( const char * sTemplate, ... );
// arbitrary output all params according to their << implementations (inlined in compile time).
template<typename... Params>
StringBuilder_c& Sprint ( Params&&... tParams );
// comma manipulations
// start new comma block; return index of it (for future possible reference in FinishBlocks())
int StartBlock ( const char * sDel = ", ", const char * sPref = nullptr, const char * sTerm = nullptr );
int StartBlock( const StrBlock_t& dBlock );
int MuteBlock ();
// finish and close last opened comma block.
// bAllowEmpty - close empty block output nothing(default), or prefix/suffix pair (if any).
void FinishBlock ( bool bAllowEmpty = true );
// finish and close all blocks including pLevels (by default - all blocks)
void FinishBlocks ( int iLevels = 0, bool bAllowEmpty = true );
inline char * begin() const { return m_szBuffer; }
inline char * end () const { return m_szBuffer + m_iUsed; }
inline char * AfterEnd () const { return m_szBuffer + m_iSize; }
// shrink, if necessary, to be able to fit at least iLen more chars
void GrowEnough ( int iLen );
template<typename INT, int iBase=10, int iWidth=0, int iPrec=0, char cFill=' '>
void NtoA ( INT uVal );
// template<int iBase = 10, int iWidth = 0, int iPrec = 0, char cFill = ' '>
// void NtoA ( int64_t tVal );
void FtoA ( float fVal );
void DtoA ( double fVal );
template<typename INT, int iPrec>
void IFtoA ( FixedFrac_T<INT, iPrec> tVal );
protected:
static constexpr BYTE GROW_STEP = 64; // how much to grow if no space left
char * m_szBuffer = nullptr;
int64_t m_iSize = 0;
int64_t m_iUsed = 0;
CSphVector<LazyComma_c> m_dDelimiters;
void Grow ( int iLen ); // unconditionally shrink enough to place at least iLen more bytes
void InitAddPrefix();
const Str_t & Delim ();
private:
void NewBuffer ();
void InitBuffer ();
// RAII comma for frequently used pattern of pushing into StringBuilder many values separated by ',', ';', etc.
// When in scope, inject prefix before very first item, or delimiter before each next.
class LazyComma_c : public Comma_c
{
bool m_bSkipNext = false;
public:
Str_t m_sPrefix = dEmptyStr;
Str_t m_sSuffix = dEmptyStr;
// c-tr for managed - linked StringBuilder will inject RawComma() on each call, terminator at end
LazyComma_c ( const char * sDelim, const char * sPrefix, const char * sTerm );
explicit LazyComma_c( const StrBlock_t& dBlock );
LazyComma_c () = default;
LazyComma_c ( const LazyComma_c & ) = default;
LazyComma_c ( LazyComma_c && ) noexcept = default;
LazyComma_c& operator= (LazyComma_c rhs)
{
Swap(rhs);
return *this;
}
void Swap ( LazyComma_c & rhs ) noexcept;
const Str_t & RawComma ( const std::function<void ()> & fnAddNext );
void SkipNext ()
{
m_bSkipNext = true;
}
};
};
StringBuilder_c& operator<< ( StringBuilder_c& tOut, const CSphNamedInt& tValue );
StringBuilder_c& operator<< ( StringBuilder_c& tOut, timespan_t tVal );
StringBuilder_c& operator<< ( StringBuilder_c& tOut, timestamp_t tVal );
template<typename INT, int iPrec>
StringBuilder_c& operator<< ( StringBuilder_c& tOut, FixedFrac_T<INT, iPrec> tVal );
template<typename INT, int iBase, int iWidth, int iPrec, char cFill>
StringBuilder_c& operator<< ( StringBuilder_c& tOut, FixedNum_T<INT, iBase, iWidth, iPrec, cFill> tVal );
// helpers
inline void Grow ( StringBuilder_c& tBuilder, int iInc )
{
tBuilder.GrowEnough ( iInc );
}
inline char* Tail ( StringBuilder_c& tBuilder )
{
return tBuilder.end();
}
CSphString StrVec2Str ( const VecTraits_T<CSphString>& tVec, const char* szDelim = "," ) noexcept;
inline CSphString ConcatWarnings ( const VecTraits_T<CSphString>& tVec ) noexcept
{
return StrVec2Str ( tVec, "; " );
}
#include "stringbuilder_impl.h"
| 9,387
|
C++
|
.h
| 190
| 47.189474
| 175
| 0.698918
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,292
|
vectraits.h
|
manticoresoftware_manticoresearch/src/std/vectraits.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "generics.h"
#include "ints.h"
/// vector traits - provides generic ops over a typed blob (vector).
/// just provide common operators; doesn't manage buffer anyway
template<typename T>
class VecTraits_T
{
public:
VecTraits_T() = default;
// this ctr allows to regard any typed blob as VecTraits, and use it's benefits.
VecTraits_T ( T* pData, int64_t iCount );
template<typename TT>
VecTraits_T ( TT* pData, int64_t iCount );
template<typename TT, typename INT>
VecTraits_T ( const std::pair<TT*, INT>& dData );
template<typename TT, typename INT>
VecTraits_T ( const std::pair<const TT*, INT>& dData );
VecTraits_T Slice ( int64_t iBegin = 0, int64_t iCount = -1 ) const;
/// accessor by forward index
FORCE_INLINE T & operator[] ( int64_t iIndex ) const;
T& At ( int64_t iIndex ) const;
/// get first entry ptr
FORCE_INLINE T * Begin() const;
/// pointer to the item after the last
FORCE_INLINE T * End() const;
/// make happy C++11 ranged for loops
FORCE_INLINE T * begin() const;
FORCE_INLINE T * end() const;
/// get first entry
T& First() const;
/// get last entry
T& Last() const;
/// return idx of the item pointed by pBuf, or -1
FORCE_INLINE int Idx ( const T* pBuf ) const;
/// make possible to pass VecTraits_T<T*> into funcs which need VecTraits_T<const T*>
operator VecTraits_T<const typename std::remove_pointer<T>::type*>&() const;
template<typename TT>
operator VecTraits_T<TT>&() const;
template<typename TT, typename INT>
operator std::pair<TT*, INT>() const;
/// check if i'm empty
FORCE_INLINE bool IsEmpty() const;
/// query current length, in elements
FORCE_INLINE int64_t GetLength64() const;
FORCE_INLINE int GetLength() const;
/// get length in bytes
size_t GetLengthBytes() const;
int64_t GetLengthBytes64() const;
/// default sort
void Sort ( int iStart = 0, int iEnd = -1 );
/// default reverse sort
void RSort ( int iStart = 0, int iEnd = -1 );
/// generic sort
template<typename F>
void Sort ( F&& COMP, int iStart = 0, int iEnd = -1 );
/// generic binary search
/// assumes that the array is sorted in ascending order
template<typename U, typename PRED>
T* BinarySearch ( const PRED& tPred, U tRef ) const;
/// generic binary search
/// assumes that the array is sorted in ascending order
T* BinarySearch ( T tRef ) const;
template<typename FILTER>
FORCE_INLINE int GetFirst ( FILTER&& cond ) const;
/// generic 'ARRAY_ALL'
template<typename FILTER>
FORCE_INLINE bool all_of ( FILTER&& cond ) const;
/// generic linear search - 'ARRAY_ANY' replace
/// see 'Contains()' below for examlpe of usage.
template<typename FILTER>
FORCE_INLINE bool any_of ( FILTER&& cond ) const;
template<typename FILTER>
FORCE_INLINE bool none_of ( FILTER&& cond ) const;
template<typename FILTER>
FORCE_INLINE int64_t count_of ( FILTER&& cond ) const;
/// Apply an action to every member
/// Apply ( [] (T& item) {...} );
template<typename ACTION>
FORCE_INLINE void Apply ( ACTION&& Verb ) const;
template<typename ACTION>
FORCE_INLINE void for_each ( ACTION&& tAction ) const;
/// generic linear search
bool Contains ( T tRef ) const;
/// generic linear search
template<typename FUNCTOR, typename U>
bool Contains ( FUNCTOR&& COMP, U tValue );
/// fill with given value
void Fill ( const T& rhs );
/// fill with sequence (appliable only to integers)
void FillSeq ( T iStart = 0, T iStep = 1 );
protected:
T* m_pData = nullptr;
int64_t m_iCount = 0;
};
#include "vectraits_impl.h"
| 4,011
|
C++
|
.h
| 107
| 35.336449
| 86
| 0.717206
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,293
|
lrucache.h
|
manticoresoftware_manticoresearch/src/std/lrucache.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#ifndef _lrucache_
#define _lrucache_
#include "ints.h"
#include "mutex.h"
#include "openhash.h"
template <typename KEY, typename VALUE, typename HELPER>
class LRUCache_T
{
public:
LRUCache_T ( int64_t iCacheSize );
~LRUCache_T();
bool Find ( KEY tKey, VALUE & tData );
bool Add ( KEY tKey, const VALUE & tData );
void Release ( KEY tKey );
template <typename COND>
void Delete ( COND && fnCond );
protected:
struct LinkedEntry_t
{
VALUE m_tValue;
DWORD m_uSize = 0;
int m_iRefcount = 0;
LinkedEntry_t * m_pPrev = nullptr;
LinkedEntry_t * m_pNext = nullptr;
KEY m_tKey;
};
LinkedEntry_t * m_pHead = nullptr;
LinkedEntry_t * m_pTail = nullptr;
int64_t m_iCacheSize = 0;
int64_t m_iMemUsed = 0;
CSphMutex m_tLock;
OpenHashTable_T<KEY, LinkedEntry_t *, HELPER> m_tHash;
void Delete ( LinkedEntry_t * pEntry );
private:
void MoveToHead ( LinkedEntry_t * pEntry );
void Add ( LinkedEntry_t * pEntry );
void SweepUnused ( DWORD uSpaceNeeded );
bool HaveSpaceFor ( DWORD uSpaceNeeded ) const;
};
#include "lrucache_impl.h"
#endif // _lrucache_
| 1,580
|
C++
|
.h
| 52
| 28.461538
| 80
| 0.716546
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,294
|
escaped_builder.h
|
manticoresoftware_manticoresearch/src/std/escaped_builder.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
#include "stringbuilder.h"
struct EqualQuotator_t
{
// returns N of additional chars need to escape
static constexpr BYTE EscapingSpace ( BYTE c ) { return 0; }
};
struct EscapeQuotator_t
{
static constexpr BYTE EscapingSpace ( BYTE c )
{
return ( c == '\\' || c == '\'' ) ? 1 : 0;
}
};
struct SqlQuotator_t
{
static constexpr BYTE EscapingSpace ( BYTE c )
{
return ( c == '\\' || c == '\'' || c == '\t' ) ? 1 : 0;
}
};
struct FixupSpace_t
{
// replaces \t, \n, \r into spaces
static constexpr void FixupSpace ( BYTE*& pOut, BYTE c )
{
alignas ( 16 ) constexpr BYTE dSpacesLookupTable[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, ' ', ' ', 0x0b, 0x0c, ' ', 0x0e, 0x0f };
*pOut++ = ( c & 0xF0 ) ? c : dSpacesLookupTable[c];
}
};
template<typename QUOTATOR = EqualQuotator_t, typename FIXUP = FixupSpace_t>
struct BaseQuotation_T : public QUOTATOR, public FIXUP
{
// represents char for quote
static const char cQuote = '\'';
static void EscapeChar ( BYTE*& pOut, BYTE c )
{
if ( QUOTATOR::EscapingSpace ( c ) )
*pOut++ = '\\';
*pOut++ = c;
}
static void EscapeCharWithSpaces ( BYTE*& pOut, BYTE c )
{
if ( QUOTATOR::EscapingSpace ( c ) )
{
pOut[0] = '\\';
pOut[1] = c;
pOut += 2;
} else
FIXUP::FixupSpace ( pOut, c );
}
};
namespace EscBld
{ // what kind of changes will do AppendEscaped of escaped string builder:
enum eAct : BYTE {
eNone = 0, // [comma,] append raw text without changes
eFixupSpace = 1, // [comma,] change \t, \n, \r into spaces
eEscape = 2, // [comma,] all escaping according to provided interface
eAll = 3, // [comma,] escape and change spaces
eSkipComma = 4, // force to NOT prefix comma (if any active)
eSkipQuotes = 8, // don't enclose text into quotes
eNoLimit = 16, // internal - set if iLen is not set (i.e. -1). To convert conditions into switch cases
};
}
template<typename Q = BaseQuotation_T<>>
class EscapedStringBuilder_T: public StringBuilder_c
{
bool AppendEmpty ( const char* sText );
void AppendEmptyQuotes();
bool AppendEmptyEscaped ( const char* sText );
public:
// dedicated EscBld::eEscape | EscBld::eSkipComma
void AppendEscapedSkippingComma ( const char* sText );
void AppendEscapedSkippingCommaNoQuotes ( const char* sText );
// dedicated EscBld::eEscape with comma
void AppendEscapedWithComma ( const char* sText );
void AppendEscapedWithCommaNoQuotes ( const char* sText );
// dedicated EscBld::eEscape with comma with external len
void AppendEscapedWithComma ( const char* sText, int iLen );
void AppendEscapedWithCommaNoQuotes ( const char* sText, int iLen );
// dedicated EscBld::eFixupSpace
void FixupSpacesAndAppend ( const char* sText );
// dedicated EscBld::eAll (=EscBld::eFixupSpace | EscBld::eEscape )
void FixupSpacedAndAppendEscaped ( const char* sText );
void FixupSpacedAndAppendEscapedNoQuotes ( const char* sText );
// dedicated EscBld::eAll (=EscBld::eFixupSpace | EscBld::eEscape ) with external len
void FixupSpacedAndAppendEscaped ( const char* sText, int iLen );
void FixupSpacedAndAppendEscapedNoQuotes ( const char* sText, int iLen );
// generic implementation. Used this way in tests. For best performance consider to use specialized versions
// (see selector switch inside) directly.
void AppendEscaped ( const char* sText, BYTE eWhat = EscBld::eAll, int iLen = -1 );
EscapedStringBuilder_T& SkipNextComma();
EscapedStringBuilder_T& AppendName ( const char* sName, bool bQuoted = true );
private:
template<bool BQUOTE = true>
void AppendEscapedSkippingCommaT ( const char* sText );
template<bool BQUOTE = true>
void AppendEscapedWithCommaT ( const char* sText );
template <bool BQUOTE = true>
void AppendEscapedWithCommaT ( const char* sText, int iLen );
template<bool BQUOTE = true>
void FixupSpacedAndAppendEscapedT ( const char* sText );
template<bool BQUOTE = true>
void FixupSpacedAndAppendEscapedT ( const char* sText, int iLen );
};
#include "escaped_builder_impl.h"
| 4,492
|
C++
|
.h
| 119
| 35.739496
| 109
| 0.723972
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,295
|
sharedptr.h
|
manticoresoftware_manticoresearch/src/std/sharedptr.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "refcounted_mt.h"
#include "deleter.h"
#include <type_traits>
#include <functional>
#include <utility>
/// shared pointer for any object, managed by refcount
template < typename T, typename DELETER, typename REFCOUNTED = ISphRefcountedMT >
class SharedPtr_T
{
using PTR = T*;
template <typename DELL, bool STATEFUL_DELETER = std::is_member_function_pointer<decltype ( &DELL::Delete )>::value>
struct SharedState_T : public REFCOUNTED
{
PTR m_pPtr { nullptr };
DELL m_fnDelete;
SharedState_T() noexcept = default;
template<typename DEL> explicit SharedState_T ( DEL&& fnDelete );
~SharedState_T() override;
};
template <typename DELL>
struct SharedState_T<DELL, false> : public REFCOUNTED
{
PTR m_pPtr { nullptr };
~SharedState_T() override;
};
using SharedState_t = SharedState_T<DELETER>;
using StatePtr = CSphRefcountedPtr<SharedState_t>;
StatePtr m_tState;
public:
///< default ctr (for vectors)
explicit SharedPtr_T () = default;
/// construction from raw pointer, creates new shared state!
explicit SharedPtr_T ( PTR pPtr );
template <typename DEL>
SharedPtr_T ( PTR pPtr, DEL&& fn );
SharedPtr_T ( const SharedPtr_T& rhs );
SharedPtr_T ( SharedPtr_T&& rhs ) noexcept;
SharedPtr_T& operator= ( SharedPtr_T rhs );
void Swap ( SharedPtr_T& rhs ) noexcept;
PTR operator -> () const;
explicit operator bool() const;
operator PTR () const;
public:
/// assignment of a raw pointer
SharedPtr_T & operator = ( PTR pPtr );
};
template <typename T, typename REFCOUNTED = ISphRefcountedMT>
using SharedPtr_t = SharedPtr_T<T, Deleter_T<T*, ETYPE::SINGLE>, REFCOUNTED>;
template<typename T, typename REFCOUNTED = ISphRefcountedMT>
using SharedPtrArr_t = SharedPtr_T<T, Deleter_T<T*, ETYPE::ARRAY>, REFCOUNTED>;
template<typename T, typename DELETER=std::function<void(T*)>, typename REFCOUNTED = ISphRefcountedMT>
using SharedPtrCustom_t = SharedPtr_T<T, CustomDeleter_T<T*, DELETER>, REFCOUNTED>;
#include "sharedptr_impl.h"
| 2,476
|
C++
|
.h
| 65
| 36.153846
| 117
| 0.747179
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,296
|
sys.h
|
manticoresoftware_manticoresearch/src/std/sys.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
int GetNumLogicalCPUs();
int GetNumPhysicalCPUs(); // may return -1 if fails
bool IsSSE42Supported();
int GetMemPageSize();
| 616
|
C++
|
.h
| 16
| 37.4375
| 80
| 0.75626
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,297
|
storage.h
|
manticoresoftware_manticoresearch/src/std/storage.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "type_traits.h"
//////////////////////////////////////////////////////////////////////////
/// Storage backends for vector
/// Each backend provides Allocate and Deallocate
namespace sph
{
/// Default backend - uses plain old new/delete
template<typename T>
class DefaultStorage_T
{
public:
using TYPE = T;
inline static TYPE* Allocate ( int64_t iLimit )
{
return new T[iLimit];
}
inline static void Deallocate ( TYPE* pData )
{
delete[] pData;
}
static constexpr bool is_sized = false;
static constexpr bool is_constructed = true;
static constexpr bool is_owned = false;
};
/// Static backend: small blobs stored localy,
/// bigger came to plain old new/delete
template<typename T, int STATICSIZE = 4096>
class LazyStorage_T
{
public:
using TYPE = T;
// don't allow moving (it has no sence with embedded buffer)
inline LazyStorage_T ( LazyStorage_T&& rhs ) noexcept = delete;
inline LazyStorage_T& operator= ( LazyStorage_T&& rhs ) noexcept = delete;
LazyStorage_T() = default;
static const int iSTATICSIZE = STATICSIZE;
public:
inline TYPE* Allocate ( int64_t iLimit )
{
if ( iLimit <= STATICSIZE )
return m_dData;
return new T[iLimit];
}
inline void Deallocate ( TYPE* pData ) const
{
if ( pData != m_dData )
delete[] pData;
}
static constexpr bool is_sized = false;
static constexpr bool is_constructed = true;
static constexpr bool is_owned = true;
private:
T m_dData[iSTATICSIZE];
};
/// optional backend - allocates space but *not* calls ctrs and dtrs
/// bigger came to plain old new/delete
template<typename T>
class RawStorage_T
{
using StorageType = typename std::aligned_storage<sizeof ( T ), alignof ( T )>::type;
public:
using TYPE = T;
inline static TYPE* Allocate ( int64_t iLimit )
{
return (TYPE*)new StorageType[iLimit];
}
inline static void Deallocate ( TYPE* pData )
{
delete[] reinterpret_cast<StorageType*> ( pData );
}
static constexpr bool is_sized = false;
// static const bool is_constructed = IS_TRIVIALLY_COPYABLE( T );
static constexpr bool is_constructed = IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE ( T );
static constexpr bool is_owned = false;
};
} // namespace sph
| 2,671
|
C++
|
.h
| 88
| 28.420455
| 86
| 0.720203
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,298
|
blobs.h
|
manticoresoftware_manticoresearch/src/std/blobs.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include <utility>
#include "ints.h"
/// generic bytes of chars array
using ByteBlob_t = std::pair<const BYTE*, int>;
inline bool IsEmpty ( const ByteBlob_t& dBlob ) noexcept { return !dBlob.second; }
inline bool IsFilled ( const ByteBlob_t& dBlob ) noexcept { return dBlob.first && dBlob.second > 0; }
inline bool IsValid ( const ByteBlob_t& dBlob ) noexcept { return IsEmpty ( dBlob ) || IsFilled ( dBlob ); }
/// blob of chars with length (for zero-copy string processing)
using Str_t = std::pair<const char*, int>;
inline const Str_t dEmptyStr { "", 0 };
// Str_t stuff
[[nodiscard]] inline bool IsEmpty ( const Str_t& dBlob ) noexcept { return !dBlob.second; }
[[nodiscard]] inline bool IsFilled ( const Str_t& dBlob ) noexcept { return dBlob.first && dBlob.second > 0; }
[[nodiscard]] inline const char* begin ( const Str_t& dBlob ) noexcept { return dBlob.first; }
[[nodiscard]] inline const char* end ( const Str_t& dBlob ) noexcept { return dBlob.first ? dBlob.first + dBlob.second : nullptr; }
Str_t FromSz ( const char* szString ) noexcept; // { return { szString, szString ? (int)strlen ( szString ) : 0 }; }
struct CSphString;
Str_t FromStr ( const CSphString& sString ) noexcept; // { return { sString.cstr(), (int)sString.Length() }; }
#define FROMS( STR ) Str_t { STR, sizeof ( STR ) - 1 }
/// mutual conversion Str_t <-> ByteBlob_t
inline Str_t B2S ( const ByteBlob_t& sData ) noexcept { return { (const char*)sData.first, sData.second }; }
inline ByteBlob_t S2B ( const Str_t& sStr ) noexcept { return { (const BYTE*)sStr.first, sStr.second }; };
/// name+int pair
using CSphNamedInt = std::pair<CSphString, int>;
/// period of time in us
struct timespan_t
{
int64_t m_iVal;
explicit timespan_t ( int64_t iVal ) noexcept
: m_iVal ( iVal ) {};
};
/// timestamp in us
struct timestamp_t
{
int64_t m_iVal;
explicit timestamp_t ( int64_t iVal ) noexcept
: m_iVal ( iVal ) {};
};
/// fixed prec. number
template<typename INT, int iPrec>
struct FixedFrac_T
{
INT m_tVal;
explicit FixedFrac_T ( INT iVal ) noexcept
: m_tVal ( iVal ) {};
};
template<int prec=3> FixedFrac_T<int, prec> FixedFrac ( int iVal );
template<int prec=3> FixedFrac_T<int64_t, prec> FixedFrac ( int64_t iVal );
/// num with predefined output traits (to be used in << instead of formatted)
template<typename INT, int iBase, int iWidth, int iPrec, char cFill>
struct FixedNum_T
{
INT m_tVal;
explicit FixedNum_T ( INT iVal ) noexcept
: m_tVal ( iVal ) {};
};
template<int iBase=10, int iWidth=0, int iPrec=0, char cFill=' '> FixedNum_T<int64_t, iBase, iWidth, iPrec, cFill> FixedNum ( int64_t iVal );
template<int iBase=10, int iWidth=0, int iPrec=0, char cFill=' '> FixedNum_T<int, iBase, iWidth, iPrec, cFill> FixedNum ( int iVal );
template<int iWidth> FixedNum_T<int64_t, 10, iWidth, 0, '0'> Digits ( int64_t iVal );
template<int iWidth> FixedNum_T<int, 10, iWidth, 0, '0'> Digits ( int iVal );
#include "blobs_impl.h"
| 3,424
|
C++
|
.h
| 73
| 45.479452
| 141
| 0.708034
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,299
|
mem.h
|
manticoresoftware_manticoresearch/src/std/mem.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "config.h"
#include <memory>
/////////////////////////////////////////////////////////////////////////////
// MEMORY MANAGEMENT
/////////////////////////////////////////////////////////////////////////////
#define SPH_DEBUG_LEAKS 0
#define SPH_ALLOC_FILL 0
#define SPH_ALLOCS_PROFILER 0
#define SPH_DEBUG_BACKTRACES 0 // will add not only file/line, but also full backtrace
#if SPH_DEBUG_LEAKS || SPH_ALLOCS_PROFILER
/// debug new that tracks memory leaks
void * operator new ( size_t iSize, const char * sFile, int iLine );
/// debug new that tracks memory leaks
void * operator new [] ( size_t iSize, const char * sFile, int iLine );
/// debug allocate to use in custom allocator
void * debugallocate ( size_t );
/// debug deallocate to use in custom allocator
void debugdeallocate ( void * );
/// get current allocs count
int sphAllocsCount ();
/// total allocated bytes
int64_t sphAllocBytes ();
/// get last alloc id
int sphAllocsLastID ();
/// dump all allocs since given id
void sphAllocsDump ( int iFile, int iSinceID );
/// dump stats to stdout
void sphAllocsStats ();
/// check all existing allocs; raises assertion failure in cases of errors
void sphAllocsCheck ();
void sphMemStatDump ( int iFD );
/// per thread cleanup of memory statistic's
void sphMemStatThdCleanup ( void * pTLS );
void * sphMemStatThdInit ();
void sphMemStatMMapAdd ( int64_t iSize );
void sphMemStatMMapDel ( int64_t iSize );
#undef new
#define new new(__FILE__,__LINE__)
#define NEW_IS_OVERRIDED 1
#if WITH_RE2
#define MYTHROW() throw()
#else
#define MYTHROW() noexcept
#endif
/// delete for my new
void operator delete ( void * pPtr ) MYTHROW();
/// delete for my new
void operator delete [] ( void * pPtr ) MYTHROW();
template<typename T>
class managed_allocator
{
public:
typedef size_t size_type;
typedef T * pointer;
typedef const T * const_pointer;
typedef T value_type;
template<typename _Tp1>
struct rebind
{
typedef managed_allocator <_Tp1> other;
};
pointer allocate ( size_type n, const void * = 0 )
{
return ( T * ) debugallocate ( n * sizeof ( T ) );
}
void deallocate ( pointer p, size_type )
{
debugdeallocate (p);
}
};
#else
template<typename T> using managed_allocator = std::allocator<T>;
#endif // SPH_DEBUG_LEAKS || SPH_ALLOCS_PROFILER
/// init of memory statistic's data
void sphMemStatInit();
/// cleanup of memory statistic's data
void sphMemStatDone();
| 2,992
|
C++
|
.h
| 89
| 31.561798
| 86
| 0.681976
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,300
|
refcounted_mt_impl.h
|
manticoresoftware_manticoresearch/src/std/refcounted_mt_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <cassert>
inline void ISphRefcountedMT::AddRef() const noexcept
{
m_iRefCount.fetch_add ( 1, std::memory_order_relaxed );
}
inline void ISphRefcountedMT::Release() const noexcept
{
if ( m_iRefCount.fetch_sub ( 1, std::memory_order_release ) == 1 )
{
std::atomic_thread_fence ( std::memory_order_acquire );
assert ( m_iRefCount.load ( std::memory_order_seq_cst ) == 0 );
delete this;
}
}
inline long ISphRefcountedMT::GetRefcount() const
{
return m_iRefCount.load ( std::memory_order_acquire );
}
inline bool ISphRefcountedMT::IsLast() const
{
return 1 == m_iRefCount.load ( std::memory_order_acquire );
}
template<class T>
VecRefPtrs_t<T>::VecRefPtrs_t ( VecRefPtrs_t<T>&& rhs ) noexcept
{
SwapData ( rhs );
}
template<class T>
VecRefPtrs_t<T>& VecRefPtrs_t<T>::operator= ( VecRefPtrs_t<T>&& rhs ) noexcept
{
SwapData ( rhs );
return *this;
}
template<class T>
VecRefPtrs_t<T>::~VecRefPtrs_t()
{
CSphVector<T>::Apply ( [] ( T& ptr ) { SafeRelease ( ptr ); } );
}
| 1,472
|
C++
|
.h
| 49
| 28.530612
| 80
| 0.722772
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,301
|
env.h
|
manticoresoftware_manticoresearch/src/std/env.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "string.h"
/// use env variables, if available, instead of hard-coded macro
// this returns env FULL_SHARE_DIR, or hardcoded path, or '.' if nothing hardcoded
const char* GET_FULL_SHARE_DIR();
// returns env ICU_DATA_DIR, or hardcoded path, or nullptr if nothing hardcoded
CSphString GetICUDataDir();
// returns env JIEBA_DATA_DIR, or hardcoded path, or nullptr if nothing hardcoded
CSphString GetJiebaDataDir();
// this returns env MANTICORE_MODULES, or GET_FULL_SHARE_DIR()/modules
const char* GET_MANTICORE_MODULES();
// this returns env GALERA_SONAME, or GET_MANTICORE_MODULES()/libgalera_manticore.so
CSphString GET_GALERA_FULLPATH();
// this returns env LIB_MANTICORE_COLUMNAR, or GET_MANTICORE_MODULES()/lib_manticore_columnar.xx (xx=so or dll)
CSphString GetColumnarFullpath();
CSphString GetSecondaryFullpath();
CSphString GetKNNFullpath();
// return value of asked ENV, or default.
// note, default determines the type which to return
bool val_from_env ( const char* szEnvName, bool bDefault );
int val_from_env ( const char* szEnvName, int iDefault );
DWORD dwval_from_env ( const char* szEnvName, DWORD uDefault );
| 1,633
|
C++
|
.h
| 33
| 48.212121
| 111
| 0.773099
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,302
|
rand.h
|
manticoresoftware_manticoresearch/src/std/rand.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
//////////////////////////////////////////////////////////////////////////
// RANDOM NUMBERS GENERATOR
//////////////////////////////////////////////////////////////////////////
/// seed RNG
void sphSrand ( DWORD uSeed );
/// auto-seed RNG based on time and PID
void sphAutoSrand();
/// generate another random
DWORD sphRand();
| 839
|
C++
|
.h
| 22
| 36.909091
| 80
| 0.6133
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,303
|
circular_buffer.h
|
manticoresoftware_manticoresearch/src/std/circular_buffer.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "fixedvector.h"
// simple circular buffer
template<typename T>
class CircularBuffer_T
{
public:
explicit CircularBuffer_T ( int iInitialSize = 256, float fGrowFactor = 1.5f );
CircularBuffer_T ( CircularBuffer_T&& rhs ) noexcept;
void Swap ( CircularBuffer_T& rhs ) noexcept;
CircularBuffer_T& operator= ( CircularBuffer_T rhs );
void Push ( const T& tValue );
T& Push();
T& Pop();
const T& Last() const;
T& Last();
const T& operator[] ( int iIndex ) const;
bool IsEmpty() const;
int GetLength() const;
private:
CSphFixedVector<T> m_dValues;
float m_fGrowFactor;
int m_iHead = 0;
int m_iTail = 0;
int m_iUsed = 0;
void Resize ( int iNewLength );
};
#include "circular_buffer_impl.h"
| 1,205
|
C++
|
.h
| 39
| 29.25641
| 80
| 0.735979
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,304
|
variant.h
|
manticoresoftware_manticoresearch/src/std/variant.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
#include "string.h"
/////////////////////////////////////////////////////////////////////////////
/// immutable string/int/float variant list proxy
/// used in config parsing
struct CSphVariant
{
protected:
CSphString m_sValue;
int m_iValue = 0;
int64_t m_i64Value = 0;
float m_fValue = 0.0f;
public:
CSphVariant* m_pNext = nullptr;
// tags are used for handling multiple same keys
bool m_bTag = false; // 'true' means override - no multi-valued; 'false' means multi-valued - chain them
int m_iTag = 0; // stores order like in config file
public:
/// default ctor
CSphVariant() = default;
/// ctor from C string
explicit CSphVariant ( const char* sString, int iTag = 0 );
/// copy ctor
CSphVariant ( const CSphVariant& rhs );
/// move ctor
CSphVariant ( CSphVariant&& rhs ) noexcept;
/// default dtor
/// WARNING: automatically frees linked items!
~CSphVariant();
const char* cstr() const { return m_sValue.cstr(); }
const CSphString& strval() const { return m_sValue; }
int intval() const { return m_iValue; }
int64_t int64val() const { return m_i64Value; }
float floatval() const { return m_fValue; }
/// default copy operator
CSphVariant& operator= ( CSphVariant rhs );
void Swap ( CSphVariant& rhs ) noexcept;
bool operator== ( const char* s ) const { return m_sValue == s; }
bool operator!= ( const char* s ) const { return m_sValue != s; }
};
#include "variant_impl.h"
| 1,928
|
C++
|
.h
| 53
| 34.528302
| 105
| 0.690694
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,305
|
helpers_impl.h
|
manticoresoftware_manticoresearch/src/std/helpers_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
template<typename NUM>
int64_t PercentOf ( NUM tVal, NUM tBase, int iFloatDigits )
{
NUM tMultiplier = 100;
switch ( iFloatDigits )
{
case 6:
tMultiplier *= 10;
case 5:
tMultiplier *= 10;
case 4:
tMultiplier *= 10;
case 3:
tMultiplier *= 10;
case 2:
tMultiplier *= 10;
case 1:
tMultiplier *= 10;
default: break;
}
if ( tBase )
return int64_t ( tVal * tMultiplier / tBase );
else
return int64_t ( tMultiplier );
}
| 917
|
C++
|
.h
| 36
| 23.666667
| 80
| 0.718502
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,306
|
bitcount_impl.h
|
manticoresoftware_manticoresearch/src/std/bitcount_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include "ints.h"
#if __GNUC__ || __clang__
inline int sphBitCount ( DWORD n )
{
return __builtin_popcount ( n );
}
inline int sphBitCount ( uint64_t n )
{
return __builtin_popcountll ( n );
}
#else
// MIT HACKMEM count
// works for 32-bit numbers only
// fix last line for 64-bit numbers
inline int sphBitCount ( DWORD n )
{
DWORD tmp;
tmp = n - ( ( n >> 1 ) & 033333333333 ) - ( ( n >> 2 ) & 011111111111 );
return ( ( tmp + ( tmp >> 3 ) ) & 030707070707 ) % 63;
}
// MIT HACKMEM count without division
inline int sphBitCount ( uint64_t n )
{
unsigned long tmp = ( n >> 1 ) & 0x7777777777777777UL;
n -= tmp;
tmp = ( tmp >> 1 ) & 0x7777777777777777UL;
n -= tmp;
tmp = ( tmp >> 1 ) & 0x7777777777777777UL;
n -= tmp;
n = ( n + ( n >> 4 ) ) & 0x0F0F0F0F0F0F0F0FUL;
n = n * 0x0101010101010101UL;
return n >> 56;
}
#endif
// that is the fastest variant of MIT HACKMEM count specified to single byte argument
// benches of different variants are available in gbenches/popcount
inline int sphBitCount ( BYTE n )
{
return (int)( ( ( ( ( DWORD ( n ) * 0x08040201 ) >> 3 ) & 0x11111111 ) * 0x11111111 ) >> 28 );
}
| 1,602
|
C++
|
.h
| 51
| 29.980392
| 95
| 0.681347
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,307
|
orderedhash_impl.h
|
manticoresoftware_manticoresearch/src/std/orderedhash_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <cassert>
#include "generics.h"
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
unsigned int CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::HashPos ( const KEY& tKey ) const
{
return ( (unsigned int)HASHFUNC::Hash ( tKey ) ) % LENGTH;
}
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
typename CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::HashEntry_t* CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::FindByKey ( const KEY& tKey ) const
{
HashEntry_t* pEntry = m_dHash[HashPos ( tKey )];
while ( pEntry )
{
if ( pEntry->first == tKey )
return pEntry;
pEntry = pEntry->m_pNextByHash;
}
return nullptr;
}
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
typename CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::HashEntry_t* CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::AddImpl ( const KEY& tKey )
{
// check if this key is already hashed
HashEntry_t** ppEntry = &m_dHash[HashPos ( tKey )];
HashEntry_t* pEntry = *ppEntry;
while ( pEntry )
{
if ( pEntry->first == tKey )
return nullptr;
ppEntry = &pEntry->m_pNextByHash;
pEntry = pEntry->m_pNextByHash;
}
// it's not; let's add the entry
assert ( !pEntry );
assert ( !*ppEntry );
pEntry = new HashEntry_t;
pEntry->first = tKey;
*ppEntry = pEntry;
if ( !m_pFirstByOrder )
m_pFirstByOrder = pEntry;
if ( m_pLastByOrder )
{
assert ( !m_pLastByOrder->m_pNextByOrder );
assert ( !pEntry->m_pNextByOrder );
m_pLastByOrder->m_pNextByOrder = pEntry;
pEntry->m_pPrevByOrder = m_pLastByOrder;
}
m_pLastByOrder = pEntry;
++m_iLength;
return pEntry;
}
/// ctor
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::CSphOrderedHash()
{
for ( auto& pHash : m_dHash )
pHash = nullptr;
}
/// dtor
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::~CSphOrderedHash()
{
Reset();
}
/// reset
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
void CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::Reset()
{
assert ( ( m_pFirstByOrder && m_iLength ) || ( !m_pFirstByOrder && !m_iLength ) );
HashEntry_t* pKill = m_pFirstByOrder;
while ( pKill )
{
HashEntry_t* pNext = pKill->m_pNextByOrder;
SafeDelete ( pKill );
pKill = pNext;
}
for ( auto& pHash : m_dHash )
pHash = nullptr;
m_pFirstByOrder = nullptr;
m_pLastByOrder = nullptr;
m_iLength = 0;
}
/// add new entry
/// returns true on success
/// returns false if this key is already hashed
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
bool CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::Add ( T&& tValue, const KEY& tKey )
{
// check if this key is already hashed
HashEntry_t* pEntry = AddImpl ( tKey );
if ( !pEntry )
return false;
pEntry->second = std::move ( tValue );
return true;
}
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
bool CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::Add ( const T& tValue, const KEY& tKey )
{
// check if this key is already hashed
HashEntry_t* pEntry = AddImpl ( tKey );
if ( !pEntry )
return false;
pEntry->second = tValue;
return true;
}
/// add new entry
/// returns ref to just inserted or previously existed value
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
T& CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::AddUnique ( const KEY& tKey )
{
// check if this key is already hashed
HashEntry_t** ppEntry = &m_dHash[HashPos ( tKey )];
HashEntry_t* pEntry = *ppEntry;
while ( pEntry )
{
if ( pEntry->first == tKey )
return pEntry->second;
ppEntry = &pEntry->m_pNextByHash;
pEntry = *ppEntry;
}
// it's not; let's add the entry
assert ( !pEntry );
pEntry = new HashEntry_t;
pEntry->first = tKey;
*ppEntry = pEntry;
if ( !m_pFirstByOrder )
m_pFirstByOrder = pEntry;
if ( m_pLastByOrder )
{
assert ( !m_pLastByOrder->m_pNextByOrder );
assert ( !pEntry->m_pNextByOrder );
m_pLastByOrder->m_pNextByOrder = pEntry;
pEntry->m_pPrevByOrder = m_pLastByOrder;
}
m_pLastByOrder = pEntry;
++m_iLength;
return pEntry->second;
}
/// delete an entry
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
bool CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::Delete ( const KEY& tKey )
{
auto uHash = HashPos ( tKey );
HashEntry_t* pEntry = m_dHash[uHash];
HashEntry_t* pPrevEntry = nullptr;
HashEntry_t* pToDelete = nullptr;
while ( pEntry )
{
if ( pEntry->first == tKey )
{
pToDelete = pEntry;
if ( pPrevEntry )
pPrevEntry->m_pNextByHash = pEntry->m_pNextByHash;
else
m_dHash[uHash] = pEntry->m_pNextByHash;
break;
}
pPrevEntry = pEntry;
pEntry = pEntry->m_pNextByHash;
}
if ( !pToDelete )
return false;
if ( pToDelete->m_pPrevByOrder )
pToDelete->m_pPrevByOrder->m_pNextByOrder = pToDelete->m_pNextByOrder;
else
m_pFirstByOrder = pToDelete->m_pNextByOrder;
if ( pToDelete->m_pNextByOrder )
pToDelete->m_pNextByOrder->m_pPrevByOrder = pToDelete->m_pPrevByOrder;
else
m_pLastByOrder = pToDelete->m_pPrevByOrder;
SafeDelete ( pToDelete );
--m_iLength;
return true;
}
/// get value reference by key, asserting that the key exists in hash
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
T& CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::operator[] ( const KEY& tKey ) const
{
HashEntry_t* pEntry = FindByKey ( tKey );
assert ( pEntry && "hash missing value in operator []" );
return pEntry->second;
}
template<typename T, typename KEY, typename HASHFUNC, int LENGTH>
void CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>::Swap ( CSphOrderedHash<T, KEY, HASHFUNC, LENGTH>& rhs ) noexcept
{
HashEntry_t* dFoo[LENGTH];
memcpy ( dFoo, m_dHash, LENGTH * sizeof ( HashEntry_t* ) );
memcpy ( m_dHash, rhs.m_dHash, LENGTH * sizeof ( HashEntry_t* ) );
memcpy ( rhs.m_dHash, dFoo, LENGTH * sizeof ( HashEntry_t* ) );
::Swap ( m_pFirstByOrder, rhs.m_pFirstByOrder );
::Swap ( m_pLastByOrder, rhs.m_pLastByOrder );
::Swap ( m_iLength, rhs.m_iLength );
}
| 6,475
|
C++
|
.h
| 204
| 29.602941
| 143
| 0.718966
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,308
|
sphwarn.h
|
manticoresoftware_manticoresearch/src/std/sphwarn.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "attrstub.h"
void sphWarn ( const char* sTemplate, ... ) __attribute__ ( ( format ( printf, 1, 2 ) ) );
| 603
|
C++
|
.h
| 14
| 41.928571
| 90
| 0.725724
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,309
|
comma_impl.h
|
manticoresoftware_manticoresearch/src/std/comma_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <utility>
#include "generics.h"
inline Comma_c::Comma_c ( const char* sDelim )
{
m_sComma = sDelim ? Str_t { sDelim, (int)strlen ( sDelim ) } : dEmptyStr;
}
inline Comma_c::Comma_c ( Str_t sDelim )
: m_sComma ( std::move ( sDelim ) )
{}
inline Comma_c& Comma_c::operator= ( Comma_c rhs )
{
Swap ( rhs );
return *this;
}
inline void Comma_c::Swap ( Comma_c& rhs ) noexcept
{
m_sComma.swap ( rhs.m_sComma );
::Swap ( m_bStarted, rhs.m_bStarted );
}
inline Comma_c::operator Str_t()
{
if ( m_bStarted )
return m_sComma;
m_bStarted = true;
return dEmptyStr;
}
| 1,058
|
C++
|
.h
| 37
| 27.108108
| 80
| 0.707101
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,310
|
bitvec.h
|
manticoresoftware_manticoresearch/src/std/bitvec.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
#include "log2.h"
//////////////////////////////////////////////////////////////////////////
/// generic dynamic bitvector
/// with a preallocated part for small-size cases, and a dynamic route for big-size ones
template<typename T=DWORD, int STATICBITS=128>
class BitVec_T
{
public:
BitVec_T () = default;
explicit BitVec_T ( int iElements );
explicit BitVec_T ( T * pData, int iElements );
~BitVec_T ();
void Swap ( BitVec_T & rhs ) noexcept;
BitVec_T ( BitVec_T && rhs ) noexcept;
BitVec_T ( const BitVec_T& rhs );
BitVec_T & operator= ( BitVec_T rhs );
void Init ( int iElements );
void Clear();
void Set ();
bool BitGet ( int iIndex ) const noexcept;
bool BitGetOr ( int iIndex, bool bAlternative=false ) const noexcept;
void BitSet ( int iIndex );
void BitClear ( int iIndex );
const T * Begin() const noexcept;
T * Begin();
int GetSizeBytes () const noexcept;
int GetSize() const noexcept;
bool IsEmpty() const noexcept;
int BitCount () const noexcept;
int Scan ( int iStart ) const;
void Negate ();
protected:
static constexpr int SIZEBITS = sizeof ( T ) * CHAR_BIT;
static constexpr int STATICSIZE = STATICBITS / SIZEBITS;
static constexpr T MASK = T ( sizeof ( T ) * CHAR_BIT - 1 );
static constexpr int SHIFT = sphLog2const ( SIZEBITS ) - 1;
T * m_pData = nullptr;
T m_dStatic[STATICSIZE] {0};
int m_iElements = 0;
bool m_bOwnStorage = true;
private:
int ScanBit ( int iIndex, int iStart ) const;
int CalcStorage() const noexcept;
};
using CSphBitvec = BitVec_T<>;
#include "bitvec_impl.h"
| 2,057
|
C++
|
.h
| 59
| 33.084746
| 88
| 0.695718
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,311
|
queue.h
|
manticoresoftware_manticoresearch/src/std/queue.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
/////////////////////////////////////////////////////////////////////////////
/// generic stateless priority queue
template<typename T, typename COMP>
class CSphQueue
{
public:
explicit CSphQueue ( int iSize );
~CSphQueue();
void Reset ( int iSize );
void Clear();
/// add entry to the queue
bool Push ( const T& tEntry );
/// remove root (ie. top priority) entry
void Pop();
/// get entries count
inline int GetLength() const { return m_iUsed; }
/// get current root
const T& Root() const;
const T& Last() const;
private:
T* m_pData = nullptr;
int m_iUsed = 0;
int m_iSize = 0;
};
#include "queue_impl.h"
| 1,120
|
C++
|
.h
| 37
| 28.567568
| 80
| 0.671948
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,312
|
num_conv_impl.h
|
manticoresoftware_manticoresearch/src/std/num_conv_impl.h
|
//
// Copyright (c) 2022-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <cassert>
#include <cstring>
#include "generics.h"
inline static void Grow ( char*, int ) {};
inline static char* Tail ( char* p )
{
return p;
}
template<typename Num, typename PCHAR>
static void NtoA_T ( PCHAR* ppOutput, Num uVal, int iBase = 10, int iWidth = 0, int iPrec = 0, char cFill = ' ' )
{
assert ( ppOutput );
// assert ( tail ( *ppOutput ) );
assert ( iWidth >= 0 );
assert ( iPrec >= 0 );
assert ( iBase > 0 && iBase <= 16 );
const char cAllDigits[] = "fedcba9876543210123456789abcdef";
// point to the '0'. This hack allows to process negative numbers,
// since digit[x%10] for both x==2 and x==-2 is '2'.
const char* cDigits = cAllDigits + sizeof ( cAllDigits ) / 2 - 1;
const char cZero = '0';
auto& pOutput = *ppOutput;
if ( !uVal )
{
if ( !iPrec && !iWidth )
{
*Tail ( pOutput ) = cZero;
++pOutput;
} else
{
if ( !iPrec )
++iPrec;
else
cFill = ' ';
if ( iWidth )
{
if ( iWidth < iPrec )
iWidth = iPrec;
iWidth -= iPrec;
}
if ( iWidth >= 0 )
{
Grow ( pOutput, iWidth );
memset ( Tail ( pOutput ), cFill, iWidth );
pOutput += iWidth;
}
if ( iPrec >= 0 )
{
Grow ( pOutput, iPrec );
memset ( Tail ( pOutput ), cZero, iPrec );
pOutput += iPrec;
}
}
return;
}
const BYTE uMaxIndex = 31; // 20 digits for MAX_INT64 in decimal; let it be 31 (32 digits max).
char CBuf[uMaxIndex + 1];
char* pRes = &CBuf[uMaxIndex];
BYTE uNegative = 0;
if ( uVal < 0 )
++uNegative;
while ( uVal )
{
*pRes-- = cDigits[uVal % iBase];
uVal /= iBase;
}
auto uLen = (BYTE)( uMaxIndex - ( pRes - CBuf ) );
if ( !uLen )
uNegative = 0;
if ( iPrec && iWidth && cFill == cZero )
cFill = ' ';
if ( iWidth )
iWidth = iWidth - Max ( iPrec, uLen ) - uNegative;
if ( uNegative && cFill == cZero )
{
*Tail ( pOutput ) = '-';
++pOutput;
uNegative = 0;
}
if ( iWidth >= 0 )
{
Grow ( pOutput, iWidth );
memset ( Tail ( pOutput ), cFill, iWidth );
pOutput += iWidth;
}
if ( uNegative )
{
*Tail ( pOutput ) = '-';
++pOutput;
}
if ( iPrec )
iPrec -= uLen;
if ( iPrec >= 0 )
{
Grow ( pOutput, iPrec );
memset ( Tail ( pOutput ), cZero, iPrec );
pOutput += iPrec;
}
Grow ( pOutput, uLen );
memcpy ( Tail ( pOutput ), pRes + 1, uLen );
pOutput += uLen;
}
static const int nDividers = 10;
static const int Dividers[nDividers] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
template<typename Num, typename PCHAR>
void IFtoA_T ( PCHAR* pOutput, Num nVal, int iPrec )
{
assert ( iPrec < nDividers );
auto& pBegin = *pOutput;
if ( nVal < 0 )
{
*Tail ( pBegin ) = '-';
++pBegin;
nVal = -nVal;
}
auto iInt = nVal / Dividers[iPrec];
auto iFrac = nVal % Dividers[iPrec];
::NtoA_T ( &pBegin, iInt );
*Tail ( pBegin ) = '.';
++pBegin;
::NtoA_T ( &pBegin, iFrac, 10, 0, iPrec, '0' );
}
namespace sph {
template<typename Num>
int NtoA ( char* pOutput, Num nVal, int iBase, int iWidth, int iPrec, char cFill )
{
auto pBegin = pOutput;
NtoA_T ( &pBegin, nVal, iBase, iWidth, iPrec, cFill );
return int ( pBegin - pOutput );
}
inline int IFtoA ( char* pOutput, int nVal, int iPrec )
{
auto pBegin = pOutput;
IFtoA_T ( &pBegin, nVal, iPrec );
return int ( pBegin - pOutput );
}
inline int IFtoA ( char* pOutput, int64_t nVal, int iPrec )
{
auto pBegin = pOutput;
IFtoA_T ( &pBegin, nVal, iPrec );
return int ( pBegin - pOutput );
}
}
| 3,930
|
C++
|
.h
| 154
| 23.038961
| 117
| 0.632969
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,313
|
circular_buffer_impl.h
|
manticoresoftware_manticoresearch/src/std/circular_buffer_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <utility>
#include <cassert>
// simple circular buffer
template<typename T>
CircularBuffer_T<T>::CircularBuffer_T ( int iInitialSize, float fGrowFactor )
: m_dValues ( iInitialSize )
, m_fGrowFactor ( fGrowFactor )
{}
template<typename T>
CircularBuffer_T<T>::CircularBuffer_T ( CircularBuffer_T<T>&& rhs ) noexcept
: CircularBuffer_T ( 0, 1.5f )
{
Swap ( rhs );
}
template<typename T>
void CircularBuffer_T<T>::Swap ( CircularBuffer_T& rhs ) noexcept
{
m_dValues.SwapData ( rhs.m_dValues );
std::swap ( m_fGrowFactor, rhs.m_fGrowFactor );
std::swap ( m_iHead, rhs.m_iHead );
std::swap ( m_iTail, rhs.m_iTail );
std::swap ( m_iUsed, rhs.m_iUsed );
}
template<typename T>
CircularBuffer_T<T>& CircularBuffer_T<T>::operator= ( CircularBuffer_T<T> rhs )
{
Swap ( rhs );
return *this;
}
template<typename T>
void CircularBuffer_T<T>::Push ( const T& tValue )
{
if ( m_iUsed == m_dValues.GetLength() )
Resize ( int ( m_iUsed * m_fGrowFactor ) );
m_dValues[m_iTail] = tValue;
m_iTail = ( m_iTail + 1 ) % m_dValues.GetLength();
m_iUsed++;
}
template<typename T>
T& CircularBuffer_T<T>::Push()
{
if ( m_iUsed == m_dValues.GetLength() )
Resize ( int ( m_iUsed * m_fGrowFactor ) );
int iOldTail = m_iTail;
m_iTail = ( m_iTail + 1 ) % m_dValues.GetLength();
++m_iUsed;
return m_dValues[iOldTail];
}
template<typename T>
T& CircularBuffer_T<T>::Pop()
{
assert ( !IsEmpty() );
int iOldHead = m_iHead;
m_iHead = ( m_iHead + 1 ) % m_dValues.GetLength();
--m_iUsed;
return m_dValues[iOldHead];
}
template<typename T>
const T& CircularBuffer_T<T>::Last() const
{
assert ( !IsEmpty() );
return operator[] ( GetLength() - 1 );
}
template<typename T>
T& CircularBuffer_T<T>::Last()
{
assert ( !IsEmpty() );
int iIndex = GetLength() - 1;
return m_dValues[( iIndex + m_iHead ) % m_dValues.GetLength()];
}
template<typename T>
const T& CircularBuffer_T<T>::operator[] ( int iIndex ) const
{
assert ( iIndex < m_iUsed );
return m_dValues[( iIndex + m_iHead ) % m_dValues.GetLength()];
}
template<typename T>
bool CircularBuffer_T<T>::IsEmpty() const
{
return m_iUsed == 0;
}
template<typename T>
int CircularBuffer_T<T>::GetLength() const
{
return m_iUsed;
}
template<typename T>
void CircularBuffer_T<T>::Resize ( int iNewLength )
{
CSphFixedVector<T> dNew ( iNewLength );
for ( int i = 0; i < GetLength(); i++ )
dNew[i] = m_dValues[( i + m_iHead ) % m_dValues.GetLength()];
m_dValues.SwapData ( dNew );
m_iHead = 0;
m_iTail = m_iUsed;
}
| 2,967
|
C++
|
.h
| 107
| 26.093458
| 80
| 0.698625
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,314
|
iterations_impl.h
|
manticoresoftware_manticoresearch/src/std/iterations_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include "thread_annotations.h"
template<typename CONTAINER, typename FILTER>
FORCE_INLINE bool all_of ( const CONTAINER& dData, FILTER cond ) NO_THREAD_SAFETY_ANALYSIS
{
for ( const auto& dItem : dData )
if ( !cond ( dItem ) )
return false;
return true;
}
template<typename CONTAINER, typename FILTER>
FORCE_INLINE bool any_of ( const CONTAINER& dData, FILTER cond ) NO_THREAD_SAFETY_ANALYSIS
{
for ( const auto& dItem : dData )
if ( cond ( dItem ) )
return true;
return false;
}
template<typename CONTAINER, typename FILTER>
FORCE_INLINE bool none_of ( const CONTAINER& dData, FILTER cond ) NO_THREAD_SAFETY_ANALYSIS
{
return !any_of ( dData, std::forward<FILTER> ( cond ) );
}
template<typename CONTAINER, typename FILTER>
FORCE_INLINE int64_t count_of ( const CONTAINER& dData, FILTER cond ) NO_THREAD_SAFETY_ANALYSIS
{
int64_t iRes = 0;
for ( const auto& dItem : dData )
if ( cond ( dItem ) )
++iRes;
return iRes;
}
template<typename CONTAINER, typename ACTION>
FORCE_INLINE void for_each ( CONTAINER&& dData, ACTION fnAction ) NO_THREAD_SAFETY_ANALYSIS
{
for ( auto& dItem : dData )
fnAction ( dItem );
}
| 1,619
|
C++
|
.h
| 48
| 32.041667
| 95
| 0.742327
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,315
|
unique_lock.h
|
manticoresoftware_manticoresearch/src/std/unique_lock.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "thread_annotations.h"
#include <mutex>
namespace sph
{
// tiny wrapper over std::unique_lock to provide thread-annotation capabilities
// naming convention follows std::unique_lock
template<typename Mutex>
class SCOPED_CAPABILITY unique_lock
{
std::unique_lock<Mutex> m_tLock;
public:
unique_lock() noexcept = default;
unique_lock ( unique_lock const& ) = delete;
unique_lock& operator= ( unique_lock const& ) = delete;
explicit unique_lock ( Mutex& m ) ACQUIRE ( m )
: m_tLock { m } {}
unique_lock ( Mutex& m, std::defer_lock_t t ) noexcept EXCLUDES ( m )
: m_tLock { m, t } {}
unique_lock ( Mutex& m, std::try_to_lock_t t ) ACQUIRE ( m )
: m_tLock { m, t } {}
unique_lock ( Mutex& m, std::adopt_lock_t t ) REQUIRES ( m )
: m_tLock { m, t } {}
template<class Clock, class Duration>
unique_lock ( Mutex& m, const std::chrono::time_point<Clock, Duration>& t ) ACQUIRE ( m )
: m_tLock { m, t } {}
template<class Rep, class Period>
unique_lock ( Mutex& m, const std::chrono::duration<Rep, Period>& d ) ACQUIRE ( m )
: m_tLock { m, d } {}
unique_lock ( unique_lock&& u ) noexcept ACQUIRE ( ) RELEASE ( u ) = default;
unique_lock& operator= ( unique_lock&& u ) noexcept ACQUIRE ( ) RELEASE ( u ) = default;
~unique_lock() RELEASE() = default;
void lock() ACQUIRE()
{
m_tLock.lock();
}
void unlock() RELEASE()
{
m_tLock.unlock();
}
bool try_lock() TRY_ACQUIRE ( true )
{
return m_tLock.try_lock();
}
template<class Rep, class Period>
bool try_lock_for ( const std::chrono::duration<Rep, Period>& d ) TRY_ACQUIRE ( true )
{
return m_tLock.try_lock_for (d);
}
template<class Clock, class Duration>
bool try_lock_until ( const std::chrono::time_point<Clock, Duration>& t ) TRY_ACQUIRE ( true )
{
return m_tLock.try_lock_until (t);
}
void swap ( unique_lock& u ) noexcept
{
m_tLock.swap ( u.m_tLock );
}
bool owns_lock() const noexcept { return m_tLock.owns_lock(); }
operator bool() const noexcept { return m_tLock(); }
Mutex* mutex() const noexcept { return m_tLock.mutex(); }
Mutex* release() noexcept RELEASE() { return m_tLock.release(); }
};
template<class Mutex>
inline void swap ( unique_lock<Mutex>& x, unique_lock<Mutex>& y ) noexcept
{
x.swap ( y );
}
} // namespace sph
| 2,758
|
C++
|
.h
| 80
| 32.375
| 95
| 0.689006
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,316
|
bitcount.h
|
manticoresoftware_manticoresearch/src/std/bitcount.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
int sphBitCount ( DWORD n );
int sphBitCount ( uint64_t n );
int sphBitCount ( BYTE n );
#include "bitcount_impl.h"
| 627
|
C++
|
.h
| 17
| 35.588235
| 80
| 0.745455
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,317
|
scoped_comma_impl.h
|
manticoresoftware_manticoresearch/src/std/scoped_comma_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
#include <cassert>
inline ScopedComma_c::ScopedComma_c ( StringBuilder_c& tOwner, const char* sDel, const char* sPref, const char* sTerm, bool bAllowEmpty )
: m_pOwner ( &tOwner )
, m_bAllowEmpty ( bAllowEmpty )
{
m_iLevel = tOwner.StartBlock ( sDel, sPref, sTerm );
}
inline ScopedComma_c::ScopedComma_c ( StringBuilder_c& tOwner, const StrBlock_t& dBlock, bool bAllowEmpty )
: m_pOwner ( &tOwner )
, m_bAllowEmpty ( bAllowEmpty )
{
m_iLevel = tOwner.StartBlock ( dBlock );
}
inline ScopedComma_c::~ScopedComma_c()
{
if ( m_pOwner )
m_pOwner->FinishBlocks ( m_iLevel, m_bAllowEmpty );
}
inline void ScopedComma_c::Swap ( ScopedComma_c& rhs ) noexcept
{
::Swap ( m_pOwner, rhs.m_pOwner );
::Swap ( m_iLevel, rhs.m_iLevel );
}
inline void ScopedComma_c::Init ( StringBuilder_c& tOwner, const char* sDel, const char* sPref, const char* sTerm )
{
assert ( !m_pOwner );
if ( m_pOwner )
return;
m_pOwner = &tOwner;
m_iLevel = tOwner.StartBlock ( sDel, sPref, sTerm );
}
inline StringBuilder_c& ScopedComma_c::Sink() const
{
assert ( m_pOwner );
return *m_pOwner;
}
| 1,562
|
C++
|
.h
| 47
| 31.680851
| 137
| 0.723475
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,318
|
fatal.h
|
manticoresoftware_manticoresearch/src/std/fatal.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include <stdarg.h>
#include "attrstub.h"
#define NO_RETURN __attribute__ ( ( __noreturn__ ) )
using SphDieCallback_t = bool ( * ) ( bool bDie, const char*, va_list );
/// crash with an error message, and do not have searchd watchdog attempt to resurrect
void sphDie ( const char* sFmt, ... ) __attribute__ ( ( format ( printf, 1, 2 ) ) ) NO_RETURN;
void sphDieVa ( const char* sFmt, va_list ap );
/// crash with an error message, but have searchd watchdog attempt to resurrect
void sphDieRestart ( const char* sMessage, ... ) __attribute__ ( ( format ( printf, 1, 2 ) ) ) NO_RETURN;
/// shutdown (not crash) on unrrecoverable error
void sphFatal ( const char* sFmt, ... ) __attribute__ ( ( format ( printf, 1, 2 ) ) ) NO_RETURN;
void sphFatalVa ( const char* sFmt, va_list ap );
/// log fatal error, not shutdown
void sphFatalLog ( const char* sFmt, ... ) __attribute__ ( ( format ( printf, 1, 2 ) ) );
/// setup a callback function to call from sphDie() before exit
/// if callback returns false, sphDie() will not log to stdout
void sphSetDieCallback ( SphDieCallback_t pfDieCallback );
bool sphIsDied();
void sphSetDied();
/// similar as abort but closes FD
/// not available on MacOS
#if defined( __APPLE__ )
#define sphQuickExit exit
#else
#define sphQuickExit std::quick_exit
#endif
| 1,790
|
C++
|
.h
| 38
| 45.789474
| 105
| 0.713218
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,319
|
zip_impl.h
|
manticoresoftware_manticoresearch/src/std/zip_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <type_traits>
// N of bytes need to store value
template<typename T>
inline int sphCalcZippedLen ( T tValue )
{
auto uValue = static_cast<std::make_unsigned_t<T>> ( tValue );
int nBytes = 1;
uValue >>= 7;
while ( uValue )
{
uValue >>= 7;
++nBytes;
}
return nBytes;
// (sphLog2(tValue)+6)/7 gives no branching, but stalled-cycles-frontend because of 'bsr' instruction. It works faster standalone, but slower in ZipValue
}
// big-endian (most significant septets first)
template<typename T, typename WRITER>
inline int ZipValueBE ( WRITER fnPut, T tValue )
{
int nBytes = sphCalcZippedLen ( tValue );
for ( int i = nBytes - 1; i >= 0; --i )
fnPut ( ( 0x7f & ( tValue >> ( 7 * i ) ) ) | ( i ? 0x80 : 0 ) );
return nBytes;
}
// big-endian (most significant septets first)
template<typename T>
inline int ZipToPtrBE ( BYTE* pData, T tValue )
{
return ZipValueBE ( [pData] ( BYTE b ) mutable { *pData++ = b; }, tValue );
}
template<typename T, typename READER>
inline T UnzipValueBE_reference ( READER&& fnGet )
{
#if PARANOID
DWORD b = 0;
T v = 0;
int it = 0;
do {
b = fnGet();
v = ( v << 7 ) + ( b & 0x7f );
it++;
} while ( b & 0x80 );
assert ( ( it - 1 ) * 7 <= sizeof ( _type ) * 8 );
return v;
#else
BYTE b = fnGet();
T res = 0;
while ( b & 0x80 )
{
res = ( res << 7 ) | ( b & 0x7f );
b = fnGet();
}
res = ( res << 7 ) | b;
return res;
#endif
}
template<typename T, typename READER>
inline std::enable_if_t<sizeof ( T ) == 4, T> UnzipValueBE ( READER&& fnGet )
{
BYTE b = fnGet();
T res = b & 0x7f;
if ( ( b & 0x80 ) == 0 ) LIKELY
return res;
b = fnGet();
res = ( res << 7 ) | ( b & 0x7f );
if ( ( b & 0x80 ) == 0 ) LIKELY
return res;
b = fnGet();
res = ( res << 7 ) | ( b & 0x7f );
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res = ( res << 7 ) | ( b & 0x7f );
if ( ( b & 0x80 ) == 0 )
return res;
return ( res << 7 ) | fnGet();
}
// reference implementation
template<typename T, typename READER>
inline std::enable_if_t<sizeof ( T ) == 8, T> UnzipValueBE ( READER&& fnGet )
{
#if PARANOID
DWORD b = 0;
T v = 0;
int it = 0;
do {
b = fnGet();
v = ( v << 7 ) + ( b & 0x7f );
it++;
} while ( b & 0x80 );
assert ( ( it - 1 ) * 7 <= sizeof ( _type ) * 8 );
return v;
#else
BYTE b = fnGet();
T res = 0;
while ( b & 0x80 )
{
res = ( res << 7 ) | ( b & 0x7f );
b = fnGet();
}
res = ( res << 7 ) | b;
return res;
#endif
}
inline DWORD UnzipIntBE ( const BYTE*& pBuf )
{
return UnzipValueBE<DWORD> ( [&pBuf]() mutable { return *pBuf++; } );
}
inline SphOffset_t UnzipOffsetBE ( const BYTE*& pBuf )
{
return UnzipValueBE<SphOffset_t> ( [&pBuf]() mutable { return *pBuf++; } );
}
template<typename T, typename WRITER>
inline int ZipValueLE ( WRITER fnPut, T tValue )
{
auto uValue = static_cast<std::make_unsigned_t<T>> ( tValue );
int nBytes = 0;
do
{
BYTE bOut = (BYTE)( uValue & 0x7f );
uValue >>= 7;
if ( uValue )
bOut |= 0x80;
fnPut ( bOut );
++nBytes;
} while ( uValue );
return nBytes;
}
template<typename T>
inline int ZipToPtrLE ( BYTE* pData, T tValue )
{
return ZipValueLE ( [pData] ( BYTE b ) mutable { *pData++ = b; }, tValue );
}
template<typename T, typename READER>
inline T UnzipValueLE_reference ( READER fnGet )
{
BYTE b;
T res = 0;
BYTE iOff = 0;
do
{
b = fnGet();
res += ( T ( b & 0x7FU ) ) << iOff;
iOff += 7;
} while ( b & 0x80U );
return res;
}
template<typename T, typename READER>
inline std::enable_if_t<sizeof ( T ) == 4, T> UnzipValueLE ( READER fnGet )
{
BYTE b = fnGet();
DWORD res = b & 0x7f;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= ( b & 0x7f ) << 7;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= ( b & 0x7f ) << 14;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
if ( ( b & 0x80 ) == 0 )
return res | ( b & 0x7f ) << 21;
return res | ( b & 0x7f ) << 21 | fnGet() << 28;
}
template<typename T, typename READER>
inline std::enable_if_t<sizeof ( T ) == 8, T> UnzipValueLE ( READER fnGet )
{
BYTE b = fnGet();
T res = b & 0x7f;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 7;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 14;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 21;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 28;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 35;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 42;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
res |= T ( b & 0x7f ) << 49;
if ( ( b & 0x80 ) == 0 )
return res;
b = fnGet();
if ( ( b & 0x80 ) == 0 )
return res | T ( b & 0x7f ) << 56;
return res | T ( b & 0x7f ) << 56 | T ( fnGet() ) << 63;
}
inline DWORD UnzipIntLE ( const BYTE*& pBuf )
{
return UnzipValueLE<DWORD> ( [&pBuf]() mutable { return *pBuf++; } );
}
inline SphOffset_t UnzipOffsetLE ( const BYTE*& pBuf )
{
return UnzipValueLE<SphOffset_t> ( [&pBuf]() mutable { return *pBuf++; } );
}
| 5,552
|
C++
|
.h
| 227
| 22.537445
| 154
| 0.589067
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,320
|
accessor_impl.h
|
manticoresoftware_manticoresearch/src/std/accessor_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include "generics.h"
template<typename T>
typename SphAccessor_T<T>::MEDIAN_TYPE& SphAccessor_T<T>::Key (T* a) const
{
return *a;
}
template<typename T>
void SphAccessor_T<T>::CopyKey ( SphAccessor_T<T>::MEDIAN_TYPE* pMed, T* pVal ) const
{
*pMed = Key ( pVal );
}
template<typename T>
void SphAccessor_T<T>::Swap ( T* a, T* b ) const
{
::Swap ( *a, *b );
}
template<typename T>
T* SphAccessor_T<T>::Add ( T* p, int i ) const
{
return p + i;
}
template<typename T>
int SphAccessor_T<T>::Sub ( T* b, T* a ) const
{
return (int)( b - a );
}
| 1,026
|
C++
|
.h
| 37
| 26.432432
| 85
| 0.704985
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,321
|
buffer_impl.h
|
manticoresoftware_manticoresearch/src/std/buffer_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include <cassert>
#include <cerrno>
#include "mm.h"
template<typename T>
CSphBufferTrait<T>::~CSphBufferTrait()
{
assert ( !m_bMemLocked && !m_pData );
}
template<typename T>
void CSphBufferTrait<T>::Set ( T* pData, int64_t iCount )
{
m_pData = pData;
m_iCount = iCount;
}
template<typename T>
bool CSphBufferTrait<T>::MemLock ( CSphString& sWarning )
{
m_bMemLocked = mmlock ( m_pData, GetLengthBytes() );
if ( !m_bMemLocked )
sWarning.SetSprintf ( "mlock() failed: %s", strerror ( errno ) );
return m_bMemLocked;
}
template<typename T>
void CSphBufferTrait<T>::MemUnlock()
{
if ( !m_bMemLocked )
return;
m_bMemLocked = false;
Debug ( bool bOk = ) mmunlock ( m_pData, GetLengthBytes() );
assert ( bOk && "munlock() failed: %s" );
}
| 1,231
|
C++
|
.h
| 42
| 27.785714
| 80
| 0.723116
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,322
|
widest.h
|
manticoresoftware_manticoresearch/src/std/widest.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
// magic to determine widest from provided types and initialize whole unions
// for example,
/*
* union foo {
* BYTE a;
* char b;
* DWORD c;
* WORDID w;
* sphDocid_t d;
* void* p;
* WIDEST<BYTE,char,DWORD,WORDID,sphDocid_t,void*>::T _init = 0;
* };
*/
template<typename T1, typename T2, bool = ( sizeof ( T1 ) < sizeof ( T2 ) )>
struct WIDER
{
using T = T2;
};
template<typename T1, typename T2>
struct WIDER<T1, T2, false>
{
using T = T1;
};
template<typename T1, typename... TYPES>
struct WIDEST
{
using T = typename WIDER<T1, typename WIDEST<TYPES...>::T>::T;
};
template<typename T1, typename T2>
struct WIDEST<T1, T2>
{
using T = typename WIDER<T1, T2>::T;
};
| 1,178
|
C++
|
.h
| 45
| 24.777778
| 80
| 0.705934
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,323
|
sharedptr_impl.h
|
manticoresoftware_manticoresearch/src/std/sharedptr_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include "sharedptr.h"
template<typename T, typename DELETER, typename REFCOUNTED>
template<typename DELL, bool STATEFUL_DELETER>
template<typename DEL>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedState_T<DELL, STATEFUL_DELETER>::SharedState_T ( DEL&& fnDelete )
: m_fnDelete ( std::forward<DEL> ( fnDelete ) )
{}
template<typename T, typename DELETER, typename REFCOUNTED>
template<typename DELL, bool STATEFUL_DELETER>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedState_T<DELL, STATEFUL_DELETER>::~SharedState_T ()
{
m_fnDelete.Delete ( (void*)m_pPtr );
}
template<typename T, typename DELETER, typename REFCOUNTED>
template<typename DELL>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedState_T<DELL, false>::~SharedState_T()
{
DELL::Delete ( (void*)m_pPtr );
m_pPtr = nullptr;
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedPtr_T ( SharedPtr_T::PTR pPtr )
: m_tState ( new SharedState_t() )
{
m_tState->m_pPtr = pPtr;
}
template<typename T, typename DELETER, typename REFCOUNTED>
template<typename DEL>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedPtr_T ( SharedPtr_T::PTR pPtr, DEL&& fn )
: m_tState ( new SharedState_t ( std::forward<DEL> ( fn ) ) )
{
m_tState->m_pPtr = pPtr;
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedPtr_T ( const SharedPtr_T& rhs )
: m_tState ( rhs.m_tState )
{
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>::SharedPtr_T ( SharedPtr_T&& rhs ) noexcept
{
Swap ( rhs );
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>& SharedPtr_T<T, DELETER, REFCOUNTED>::operator= ( SharedPtr_T rhs )
{
Swap ( rhs );
return *this;
}
template<typename T, typename DELETER, typename REFCOUNTED>
void SharedPtr_T<T, DELETER, REFCOUNTED>::Swap ( SharedPtr_T& rhs ) noexcept
{
::Swap ( m_tState, rhs.m_tState );
}
template<typename T, typename DELETER, typename REFCOUNTED>
typename SharedPtr_T<T, DELETER, REFCOUNTED>::PTR SharedPtr_T<T, DELETER, REFCOUNTED>::operator->() const
{
return m_tState->m_pPtr;
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>::operator bool() const
{
return m_tState && m_tState->m_pPtr != nullptr;
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>::operator PTR() const
{
return m_tState ? m_tState->m_pPtr : nullptr;
}
template<typename T, typename DELETER, typename REFCOUNTED>
SharedPtr_T<T, DELETER, REFCOUNTED>& SharedPtr_T<T, DELETER, REFCOUNTED>::operator= ( SharedPtr_T::PTR pPtr )
{
m_tState = new SharedState_t;
m_tState->m_pPtr = pPtr;
return *this;
}
| 3,220
|
C++
|
.h
| 87
| 35.586207
| 109
| 0.753451
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,324
|
largebuffer_impl.h
|
manticoresoftware_manticoresearch/src/std/largebuffer_impl.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#include "ints.h"
#include "mm.h"
#include "mem.h"
#include "string.h"
#include <cassert>
namespace detail {
#if SPH_ALLOCS_PROFILER
inline void MemStatMMapAdd ( int64_t iSize ) { sphMemStatMMapAdd(iSize); }
inline void MemStatMMapDel ( int64_t iSize ) { sphMemStatMMapDel(iSize); }
#else
inline void MemStatMMapAdd ( int64_t ) {}
inline void MemStatMMapDel ( int64_t ) {}
#endif
};
template<typename T, bool SHARED>
CSphLargeBuffer<T,SHARED>::~CSphLargeBuffer()
{
this->Reset();
}
/// allocate storage
template<typename T, bool SHARED>
bool CSphLargeBuffer<T, SHARED>::Alloc ( int64_t iEntries, CSphString& sError )
{
assert ( !this->GetWritePtr() );
int64_t uCheck = sizeof ( T );
uCheck *= iEntries;
int64_t iLength = (size_t)uCheck;
if ( uCheck != iLength )
{
sError.SetSprintf ( "impossible to mmap() over 4 GB on 32-bit system" );
return false;
}
auto* pData = (T*)mmalloc ( iLength, Mode_e::RW, SHARED ? Share_e::ANON_SHARED : Share_e::ANON_PRIVATE );
if ( !mmapvalid ( pData ) )
{
if ( iLength > (int64_t)0x7fffffffUL )
sError.SetSprintf ( "mmap() failed: %s (length=" INT64_FMT " is over 2GB, impossible on some 32-bit systems)",
strerror ( errno ),
iLength );
else
sError.SetSprintf ( "mmap() failed: %s (length=" INT64_FMT ")", strerror ( errno ), iLength );
return false;
}
mmadvise ( pData, iLength, Advise_e::NODUMP );
if ( !SHARED )
mmadvise ( pData, iLength, Advise_e::NOFORK );
detail::MemStatMMapAdd ( iLength );
assert ( pData );
this->Set ( pData, iEntries );
return true;
}
/// deallocate storage
template<typename T, bool SHARED>
void CSphLargeBuffer<T, SHARED>::Reset()
{
this->MemUnlock();
if ( !this->GetWritePtr() )
return;
Debug ( int iRes = ) mmfree ( this->GetWritePtr(), this->GetLengthBytes() );
assert ( !iRes && "munmap() failed" );
detail::MemStatMMapDel ( this->GetLengthBytes() );
this->Set ( NULL, 0 );
}
| 2,385
|
C++
|
.h
| 74
| 30.310811
| 113
| 0.706318
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,325
|
fastlog.h
|
manticoresoftware_manticoresearch/src/std/fastlog.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "ints.h"
#include "generics.h"
#include "string.h"
#include "stringbuilder.h"
// fast diagnostic logging.
// Being a macro, it will be optimized out by compiler when not in use
enum ESphLogLevel : BYTE; // values are in sphinxutils.h
struct LogMessage_t
{
LogMessage_t ( BYTE uLevel = 5 ); // LOG_VERBOSE_DEBUG
~LogMessage_t();
template<typename T>
LogMessage_t& operator<< ( T&& t );
private:
StringBuilder_c m_dLog;
ESphLogLevel m_eLevel;
};
// for LOG (foo, bar) -> define LOG_LEVEL_foo as boolean, define LOG_COMPONENT_bar as expression
#define LOG_MSG LogMessage_t {}
#define LOG( Level, Component ) \
if_const ( LOG_LEVEL_##Level ) \
LOG_MSG << LOG_COMPONENT_##Component
#define LOGINFO( Level, Component ) \
if_const ( LOG_LEVEL_##Level ) \
LogMessage_t { SPH_LOG_INFO } << LOG_COMPONENT_##Component
#define LOGMSG( Verbosity, Level, Component ) \
if_const ( LOG_LEVEL_##Level ) \
LogMessage_t { SPH_LOG_##Verbosity } << LOG_COMPONENT_##Component
// flag to trace all threads creation/deletion (set to true and rebuild)
#define LOG_LEVEL_TPLIFE false
class LocMessages_c;
class LocMessage_c
{
friend class LocMessages_c;
LocMessage_c ( LocMessages_c* pOwner );
public:
void Swap ( LocMessage_c& rhs ) noexcept;
LocMessage_c ( const LocMessage_c& rhs );
MOVE_BYSWAP ( LocMessage_c )
~LocMessage_c();
template<typename T>
LocMessage_c& operator<< ( T&& t );
private:
StringBuilder_c m_dLog;
LocMessages_c* m_pOwner = nullptr;
};
struct MsgList
{
CSphString m_sMsg = nullptr;
MsgList* m_pNext = nullptr;
};
class LocMessages_c: public ISphNoncopyable
{
public:
~LocMessages_c();
LocMessage_c GetLoc();
int Print() const;
void Append ( StringBuilder_c& dMsg );
void Swap ( LocMessages_c& rhs ) noexcept;
// CSphMutex m_tLock;
MsgList* m_sMsgs = nullptr;
int m_iMsgs = 0;
};
/*
* unit logger.
* Use LOC_ADD to add logger to a class/struct
* Use #define LOG_LEVEL_FOO 1 - to enable logging
* Use #define LOG_COMPONENT_BAR as informative prefix
* Use logger as LOC(FOO,BAR) << "my cool message" for logging
* Use m_dLogger.Print() either as direct call, either as 'evaluate expression' in debugger.
*/
#define LOC_ADD LocMessages_c m_tLogger
#define LOC_SWAP( RHS ) m_tLogger.Swap ( RHS.m_tLogger )
#define LOC_MSG m_tLogger.GetLoc()
#define LOC( Level, Component ) \
if_const ( LOG_LEVEL_##Level ) \
LOC_MSG << LOG_COMPONENT_##Component
#include "fastlog_impl.h"
| 2,948
|
C++
|
.h
| 90
| 30.788889
| 96
| 0.727594
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
17,326
|
refcounted_mt.h
|
manticoresoftware_manticoresearch/src/std/refcounted_mt.h
|
//
// Copyright (c) 2017-2024, Manticore Software LTD (https://manticoresearch.com)
// Copyright (c) 2001-2016, Andrew Aksyonoff
// Copyright (c) 2008-2016, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org
//
#pragma once
#include "generics.h"
#include <atomic>
#include "refptr.h"
#include "vector.h"
//////////////////////////////////////////////////////////////////////////
/// MT-aware refcounted base (uses atomics that sometimes m.b. slow because of inter-cpu sync)
struct ISphRefcountedMT: public ISphNoncopyable
{
protected:
virtual ~ISphRefcountedMT() = default;
public:
inline void AddRef() const noexcept;
inline void Release() const noexcept;
inline long GetRefcount() const;
inline bool IsLast() const;
private:
mutable std::atomic<long> m_iRefCount { 1 };
};
using cRefCountedRefPtrGeneric_t = cRefCountedRefPtr_T<ISphRefcountedMT>;
using RefCountedRefPtrGeneric_t = RefCountedRefPtr_T<ISphRefcountedMT>;
/// vector of refcounted pointers (safe-release each ptr in dtr)
template<class T>
struct VecRefPtrs_t: public ISphNoncopyable, public CSphVector<T>
{
using CSphVector<T>::SwapData;
VecRefPtrs_t() = default;
VecRefPtrs_t ( VecRefPtrs_t<T>&& rhs ) noexcept;
VecRefPtrs_t& operator= ( VecRefPtrs_t<T>&& rhs ) noexcept;
~VecRefPtrs_t();
};
#include "refcounted_mt_impl.h"
| 1,576
|
C++
|
.h
| 43
| 35.139535
| 94
| 0.733246
|
manticoresoftware/manticoresearch
| 8,893
| 493
| 500
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.