65 Eco ecoStats_ [(1 + (1<<16)/131)*27];
66 Eco ecoGroup1_[(1 + (1<<16)/131)/100];
67 Eco ecoGroup2_[(1 + (1<<16)/131)/10];
68 Eco ecoGroup3_[(1 + (1<<16)/131)];
80 void add(
int result,
int eloW,
int eloB);
84 static double expVect_[1600];
92 const char* filename = 0,
103 std::vector<std::pair<const char*, std::string> >
getExtraInfo()
const {
104 return codec_->getExtraInfo();
110 if (std::strcmp(tagname,
"type") == 0)
114 if (std::strcmp(tagname,
"description") == 0)
117 if (std::strcmp(tagname,
"autoload") == 0)
120 auto len = std::strlen(tagname);
121 if (len == 5 && std::equal(tagname, tagname + 4,
"flag")) {
143 const byte* b = codec_->getGameData(ie->
GetOffset(), length);
144 if (b == 0) length = 0;
149 const byte* b = codec_->getGameData(ie->
GetOffset(), length);
166 const Progress& progress, std::string& errorMsg);
198 const std::string& maskFilter)
const;
201 return getFilterHelper(filterId,
false);
204 return getFilterHelper(filterId,
true);
210 if (nameFreq_[nt].
size() == 0)
212 return nameFreq_[nt][id];
216 unsigned long long* n_unused,
217 unsigned long long* n_sparse,
218 unsigned long long* n_badNameId);
278 if (duplicates_ != NULL) {
delete[] duplicates_; duplicates_ = NULL; }
279 duplicates_ = duplicates;
282 return (duplicates_ == NULL) ? 0 : duplicates_[gNum];
295 template <
typename TOper>
296 std::pair<errorT, size_t>
299 auto res = transformIndex_(hfilter, progress, entry_op);
301 res.first = (res.first ==
OK) ? err : res.first;
321 template <
typename TInitFunc,
typename TMapFunc>
322 std::pair<errorT, size_t>
324 const std::vector<std::string>& newNames, TInitFunc fnInit,
363 std::unique_ptr<ICodecDatabase> codec_;
365 std::string fileName_;
367 std::vector< std::pair<std::string, Filter*> > filters_;
368 mutable Stats* stats_;
371 std::vector< std::pair<std::string, SortCache*> > sortCaches_;
377 Filter* fetchFilter(
const std::string& filterId)
const;
378 HFilter getFilterHelper(
const std::string& filterId,
379 bool unmasked =
false)
const;
380 SortCache* getSortCache(
const char* criteria);
392 template <
typename TOper>
393 std::pair<errorT, size_t>
394 transformIndex_(
HFilter hfilter,
const Progress& progress, TOper entry_op) {
395 size_t nCorrections = 0;
397 size_t totProg = hfilter->
size();
398 for (
auto& gnum : hfilter) {
399 if ((++iProg % 8192 == 0) && !progress.
report(iProg, totProg))
403 if (!entry_op(newIE))
406 auto err = codec_->saveIndexEntry(newIE, gnum);
408 return std::make_pair(err, nCorrections);
412 return std::make_pair(
OK, nCorrections);
425 if (eloW == 0 || eloB == 0)
return;
426 int eloDiff = eloB - eloW;
427 if (eloDiff < 800 && eloDiff >= -800) {
428 exp += r - expVect_[eloDiff+800];
440 if (filter != 0 && filter->
get(i) == 0)
continue;
442 if (res !=
OK)
return res;
448 ASSERT(gNum < idx->GetNumGames());
452 if (stats_ != NULL) {
delete stats_; stats_ = NULL;}
461 if (filter != 0 && filter->
get(gNum) == 0)
continue;
462 res =
setFlag(value, flag, gNum);
463 if (res !=
OK)
return res;
469 template <
typename TInitFunc,
typename TMapFunc>
470 std::pair<errorT, size_t>
472 const std::vector<std::string>& newNames,
473 TInitFunc initFunc, TMapFunc getID) {
476 std::vector<idNumberT> nameIDs(newNames.size());
477 auto it = nameIDs.begin();
478 for (
auto&
name : newNames) {
479 auto id = codec_->addName(nt,
name.c_str());
480 if (
id.first !=
OK) {
482 return std::make_pair(
id.first,
size_t(0));
496 return ie.GetRound();
502 case NAME_SITE:
return ie.SetSite(newID);
505 return ie.SetRound(newID);
507 auto res = transformIndex_(hfilter, progress, [&](
IndexEntry& ie) {
509 auto oldID = fnGet(nt, ie);
510 auto newID = getID(oldID, ie_const);
511 bool b1 = (oldID != newID);
516 newBlack = getID(oldBlack, ie_const);
517 b2 = (oldBlack != newBlack);
523 fnSet(nt, ie, newID);
530 res.first = (res.first ==
OK) ? err : res.first;
errorT getGame(const IndexEntry *ie, ByteBuffer *destBuf) const
void SetBlack(idNumberT id)
const char * GetCustomFlagDesc(byte c) const
const IndexEntry * getIndexEntry(gamenumT g) const
errorT SetAutoLoad(gamenumT gnum)
const errorT ERROR_CodecUnsupFeat
void deleteFilter(const char *filterId)
errorT setExtraInfo(const char *tagname, const char *new_value)
Store an extra information about the database (type, description, etc..)
bool operator<(const TreeStat &cmp) const
FastGame getGame(const IndexEntry *ie) const
const uint NUM_RESULT_TYPES
UndoRedo< Game, 100 > gameAlterations
SortCache * createSortCache(const char *criteria)
Increment the reference count of a SortCache object matching criteria.
const Stats & getStats() const
Statistics.
std::array< std::vector< int >, NUM_NAME_TYPES > calcNameFreq(const NameBase &nb) const
Counts how many times every names contained in nb is used.
uint getNameFreq(nameT nt, idNumberT id)
const resultT RESULT_Black
HFilter getMainFilter(const std::string &filterId) const
const IndexEntry * GetEntry(gamenumT g) const
gamenumT GetNumGames() const
Header getter functions.
byte get(gamenumT gnum) const
Defines the ICodecDatabase interface, which encapsulates the data representation of databases...
errorT saveGame(Game *game, gamenumT replacedGameId=INVALID_GAMEID)
Add or replace a game into the database.
errorT endTransaction(gamenumT gameId=INVALID_GAMEID)
Update caches and flush the database's files.
const gamenumT INVALID_GAMEID
void setDuplicates(uint *duplicates)
static uint CharToFlag(char ch)
uint results[NUM_RESULT_TYPES]
void add(int result, int eloW, int eloB)
const resultT RESULT_Draw
errorT importGame(const scidBaseT *srcBase, uint gNum)
void beginTransaction()
This function must be called before modifying the games of the database.
std::pair< errorT, size_t > transformIndex(HFilter hfilter, const Progress &progress, TOper entry_op)
Transform the IndexEntries of the games included in hfilter.
static FastGame Create(const byte *v_begin, const byte *v_end)
void ProvideExternal(byte *data, size_t length)
std::string newFilter()
A Filter is a selection of games, usually obtained searching the database.
bool GetFlag(uint32_t mask) const
This class stores the database's names (players, events, sites and rounds).
const errorT ERROR_FileRead
errorT invertFlag(uint flag, uint gNum)
const std::string & getFileName() const
const errorT ERROR_UserCancel
errorT SetDescription(const char *str)
size_t sortedPosition(const char *criteria, const HFilter &filter, gamenumT gameId)
Get the sorted position of a game.
const resultT RESULT_White
std::pair< errorT, size_t > transformNames(nameT nt, HFilter hfilter, const Progress &progress, const std::vector< std::string > &newNames, TInitFunc fnInit, TMapFunc getID)
Transform the names of the games included in hfilter.
errorT saveGameHelper(Game *game, gamenumT gameId)
IndexEntry * FetchEntry(gamenumT g)
FetchEntry() - return a modifiable pointer to a game's IndexEntry.
Stats(const scidBaseT *dbase)
const Eco * getEcoStats(const char *ecoStr) const
errorT getCompactStat(unsigned long long *n_deleted, unsigned long long *n_unused, unsigned long long *n_sparse, unsigned long long *n_badNameId)
void releaseSortCache(const char *criteria)
Decrement the reference count of the SortCache object matching criteria.
uint getDuplicates(gamenumT gNum)
uint32_t strGetUnsigned(const char *str)
std::string composeFilter(const std::string &mainFilter, const std::string &maskFilter) const
idNumberT GetBlack() const
uint nResults[NUM_RESULT_TYPES]
uint flagCount[IndexEntry::IDX_NUM_FLAGS]
errorT importGames(const scidBaseT *srcBase, const HFilter &filter, const Progress &progress)
errorT compact(const Progress &progress)
This class sorts games contained into an Index.
bool report(size_t done, size_t total) const
errorT WriteEntry(const IndexEntry *ie, gamenumT idx)
WriteEntry() - modify a game in the Index.
std::vector< scidBaseT::TreeStat > getTreeStat(const HFilter &filter)
gamenumT numGames() const
std::pair< Game *, bool > deprecated_push_pop
HFilter getFilter(const std::string &filterId) const
errorT getGame(const IndexEntry &ie, Game &dest) const
void SetFlag(uint32_t flagMask, bool set)
uint32_t GetLength() const
const IndexEntry * getIndexEntry_bounds(gamenumT g) const
errorT Open(ICodecDatabase::Codec dbtype, fileModeT mode, const char *filename=0, const Progress &progress=Progress())
uint64_t GetOffset() const
const NameBase * getNameBase() const
std::vector< std::pair< const char *, std::string > > getExtraInfo() const
Returns a vector of tag pairs containing extra information about the database (type, description, autoload, etc..)
errorT SetCustomFlagDesc(byte c, const char *str)
errorT Decode(ByteBuffer *buf, byte flags)
size_t listGames(const char *criteria, size_t start, size_t count, const HFilter &filter, gamenumT *destCont)
Retrieve a list of ordered game indexes sorted by criteria.
bool getFlag(uint flag, uint gNum) const
errorT setFlag(bool value, uint flag, uint gNum)