| kccompare.h | | kccompare.h | |
| | | | |
| skipping to change at line 49 | | skipping to change at line 49 | |
| * equivalent. | | * equivalent. | |
| */ | | */ | |
| virtual int32_t compare(const char* akbuf, size_t aksiz, const char* bkbu
f, size_t bksiz) = 0; | | virtual int32_t compare(const char* akbuf, size_t aksiz, const char* bkbu
f, size_t bksiz) = 0; | |
| }; | | }; | |
| | | | |
| /** | | /** | |
| * Comparator in the lexical order. | | * Comparator in the lexical order. | |
| */ | | */ | |
| class LexicalComparator : public Comparator { | | class LexicalComparator : public Comparator { | |
| public: | | public: | |
|
| | | explicit LexicalComparator() {} | |
| int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_
t bksiz) { | | int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_
t bksiz) { | |
| _assert_(akbuf && bkbuf); | | _assert_(akbuf && bkbuf); | |
| size_t msiz = aksiz < bksiz ? aksiz : bksiz; | | size_t msiz = aksiz < bksiz ? aksiz : bksiz; | |
| for (size_t i = 0; i < msiz; i++) { | | for (size_t i = 0; i < msiz; i++) { | |
| if (((uint8_t*)akbuf)[i] != ((uint8_t*)bkbuf)[i]) | | if (((uint8_t*)akbuf)[i] != ((uint8_t*)bkbuf)[i]) | |
| return ((uint8_t*)akbuf)[i] - ((uint8_t*)bkbuf)[i]; | | return ((uint8_t*)akbuf)[i] - ((uint8_t*)bkbuf)[i]; | |
| } | | } | |
| return (int32_t)aksiz - (int32_t)bksiz; | | return (int32_t)aksiz - (int32_t)bksiz; | |
| } | | } | |
| }; | | }; | |
| | | | |
| /** | | /** | |
|
| | | * Comparator in the lexical descending order. | |
| | | */ | |
| | | class LexicalDescendingComparator : public Comparator { | |
| | | public: | |
| | | explicit LexicalDescendingComparator() : comp_() {} | |
| | | int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_ | |
| | | t bksiz) { | |
| | | return -comp_.compare(akbuf, aksiz, bkbuf, bksiz); | |
| | | } | |
| | | private: | |
| | | LexicalComparator comp_; | |
| | | }; | |
| | | | |
| | | /** | |
| * Comparator in the decimal order. | | * Comparator in the decimal order. | |
| */ | | */ | |
| class DecimalComparator : public Comparator { | | class DecimalComparator : public Comparator { | |
|
| | | public: | |
| | | explicit DecimalComparator() {} | |
| int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_
t bksiz) { | | int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_
t bksiz) { | |
| _assert_(akbuf && bkbuf); | | _assert_(akbuf && bkbuf); | |
| const int32_t LDBLCOLMAX = 16; | | const int32_t LDBLCOLMAX = 16; | |
| const unsigned char* arp = (unsigned char*)akbuf; | | const unsigned char* arp = (unsigned char*)akbuf; | |
| int32_t alen = aksiz; | | int32_t alen = aksiz; | |
| while (alen > 0 && (*arp <= ' ' || *arp == 0x7f)) { | | while (alen > 0 && (*arp <= ' ' || *arp == 0x7f)) { | |
| arp++; | | arp++; | |
| alen--; | | alen--; | |
| } | | } | |
| int64_t anum = 0; | | int64_t anum = 0; | |
| | | | |
| skipping to change at line 152 | | skipping to change at line 168 | |
| if (aflt < bflt) return -1; | | if (aflt < bflt) return -1; | |
| if (aflt > bflt) return 1; | | if (aflt > bflt) return 1; | |
| } | | } | |
| LexicalComparator lexcomp; | | LexicalComparator lexcomp; | |
| int32_t rv = lexcomp.compare(akbuf, aksiz, bkbuf, bksiz); | | int32_t rv = lexcomp.compare(akbuf, aksiz, bkbuf, bksiz); | |
| return rv; | | return rv; | |
| } | | } | |
| }; | | }; | |
| | | | |
| /** | | /** | |
|
| * Prepared variable of the comparator in the lexical order. | | * Comparator in the decimal descending order. | |
| */ | | */ | |
|
| extern LexicalComparator LEXICALCOMP; | | class DecimalDescendingComparator : public Comparator { | |
| | | public: | |
| | | explicit DecimalDescendingComparator() : comp_() {} | |
| | | int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_ | |
| | | t bksiz) { | |
| | | return -comp_.compare(akbuf, aksiz, bkbuf, bksiz); | |
| | | } | |
| | | private: | |
| | | DecimalComparator comp_; | |
| | | }; | |
| | | | |
| /** | | /** | |
|
| * Prepared variable of the comparator in the decimal order. | | * Prepared pointer of the comparator in the lexical order. | |
| */ | | */ | |
|
| extern DecimalComparator DECIMALCOMP; | | extern LexicalComparator* const LEXICALCOMP; | |
| | | | |
| | | /** | |
| | | * Prepared pointer of the comparator in the lexical descending order. | |
| | | */ | |
| | | extern LexicalDescendingComparator* const LEXICALDESCCOMP; | |
| | | | |
| | | /** | |
| | | * Prepared pointer of the comparator in the decimal order. | |
| | | */ | |
| | | extern DecimalComparator* const DECIMALCOMP; | |
| | | | |
| | | /** | |
| | | * Prepared pointer of the comparator in the decimal descending order. | |
| | | */ | |
| | | extern DecimalDescendingComparator* const DECIMALDESCCOMP; | |
| | | | |
| } // common namespace | | } // common namespace | |
| | | | |
| #endif // duplication check | | #endif // duplication check | |
| | | | |
| // END OF FILE | | // END OF FILE | |
| | | | |
End of changes. 7 change blocks. |
| 4 lines changed or deleted | | 45 lines changed or added | |
|
| kcdirdb.h | | kcdirdb.h | |
| | | | |
| skipping to change at line 377 | | skipping to change at line 377 | |
| FFATAL = 1 << 1 ///< dummy for compatibility | | FFATAL = 1 << 1 ///< dummy for compatibility | |
| }; | | }; | |
| /** | | /** | |
| * Default constructor. | | * Default constructor. | |
| */ | | */ | |
| explicit DirDB() : | | explicit DirDB() : | |
| mlock_(), rlock_(DDBRLOCKSLOT), error_(), logger_(NULL), logkinds_(0),
mtrigger_(NULL), | | mlock_(), rlock_(DDBRLOCKSLOT), error_(), logger_(NULL), logkinds_(0),
mtrigger_(NULL), | |
| omode_(0), writer_(false), autotran_(false), autosync_(false), recov_(f
alse), reorg_(false), | | omode_(0), writer_(false), autotran_(false), autosync_(false), recov_(f
alse), reorg_(false), | |
| file_(), curs_(), path_(""), | | file_(), curs_(), path_(""), | |
| libver_(LIBVER), librev_(LIBREV), fmtver_(FMTVER), chksum_(0), type_(TY
PEDIR), | | libver_(LIBVER), librev_(LIBREV), fmtver_(FMTVER), chksum_(0), type_(TY
PEDIR), | |
|
| flags_(0), opts_(0), count_(0), size_(0), opaque_(), embcomp_(&ZLIBRAWC
OMP), comp_(NULL), | | flags_(0), opts_(0), count_(0), size_(0), opaque_(), embcomp_(ZLIBRAWCO
MP), comp_(NULL), | |
| tran_(false), trhard_(false), trcount_(0), trsize_(0), walpath_(""), tm
ppath_("") { | | tran_(false), trhard_(false), trcount_(0), trsize_(0), walpath_(""), tm
ppath_("") { | |
| _assert_(true); | | _assert_(true); | |
| } | | } | |
| /** | | /** | |
| * Destructor. | | * Destructor. | |
| * @note If the database is not closed, it is closed implicitly. | | * @note If the database is not closed, it is closed implicitly. | |
| */ | | */ | |
| virtual ~DirDB() { | | virtual ~DirDB() { | |
| _assert_(true); | | _assert_(true); | |
| if (omode_ != 0) close(); | | if (omode_ != 0) close(); | |
| | | | |
End of changes. 1 change blocks. |
| 1 lines changed or deleted | | 1 lines changed or added | |
|
| kchashdb.h | | kchashdb.h | |
| | | | |
| skipping to change at line 489 | | skipping to change at line 489 | |
| * Default constructor. | | * Default constructor. | |
| */ | | */ | |
| explicit HashDB() : | | explicit HashDB() : | |
| mlock_(), rlock_(HDBRLOCKSLOT), flock_(), atlock_(), error_(), | | mlock_(), rlock_(HDBRLOCKSLOT), flock_(), atlock_(), error_(), | |
| logger_(NULL), logkinds_(0), mtrigger_(NULL), | | logger_(NULL), logkinds_(0), mtrigger_(NULL), | |
| omode_(0), writer_(false), autotran_(false), autosync_(false), reorg_(f
alse), trim_(false), | | omode_(0), writer_(false), autotran_(false), autosync_(false), reorg_(f
alse), trim_(false), | |
| file_(), fbp_(), curs_(), path_(""), | | file_(), fbp_(), curs_(), path_(""), | |
| libver_(0), librev_(0), fmtver_(0), chksum_(0), type_(TYPEHASH), | | libver_(0), librev_(0), fmtver_(0), chksum_(0), type_(TYPEHASH), | |
| apow_(HDBDEFAPOW), fpow_(HDBDEFFPOW), opts_(0), bnum_(HDBDEFBNUM), | | apow_(HDBDEFAPOW), fpow_(HDBDEFFPOW), opts_(0), bnum_(HDBDEFBNUM), | |
| flags_(0), flagopen_(false), count_(0), lsiz_(0), psiz_(0), opaque_(), | | flags_(0), flagopen_(false), count_(0), lsiz_(0), psiz_(0), opaque_(), | |
|
| msiz_(HDBDEFMSIZ), dfunit_(0), embcomp_(&ZLIBRAWCOMP), | | msiz_(HDBDEFMSIZ), dfunit_(0), embcomp_(ZLIBRAWCOMP), | |
| align_(0), fbpnum_(0), width_(0), linear_(false), | | align_(0), fbpnum_(0), width_(0), linear_(false), | |
| comp_(NULL), rhsiz_(0), boff_(0), roff_(0), dfcur_(0), frgcnt_(0), | | comp_(NULL), rhsiz_(0), boff_(0), roff_(0), dfcur_(0), frgcnt_(0), | |
| tran_(false), trhard_(false), trfbp_(), trcount_(0), trsize_(0) { | | tran_(false), trhard_(false), trfbp_(), trcount_(0), trsize_(0) { | |
| _assert_(true); | | _assert_(true); | |
| } | | } | |
| /** | | /** | |
| * Destructor. | | * Destructor. | |
| * @note If the database is not closed, it is closed implicitly. | | * @note If the database is not closed, it is closed implicitly. | |
| */ | | */ | |
| virtual ~HashDB() { | | virtual ~HashDB() { | |
| | | | |
End of changes. 1 change blocks. |
| 1 lines changed or deleted | | 1 lines changed or added | |
|
| kcplantdb.h | | kcplantdb.h | |
| | | | |
| skipping to change at line 1344 | | skipping to change at line 1344 | |
| create_leaf_cache(); | | create_leaf_cache(); | |
| create_inner_cache(); | | create_inner_cache(); | |
| lcnt_ = 0; | | lcnt_ = 0; | |
| create_leaf_node(0, 0); | | create_leaf_node(0, 0); | |
| root_ = 1; | | root_ = 1; | |
| first_ = 1; | | first_ = 1; | |
| last_ = 1; | | last_ = 1; | |
| lcnt_ = 1; | | lcnt_ = 1; | |
| icnt_ = 0; | | icnt_ = 0; | |
| count_ = 0; | | count_ = 0; | |
|
| if (!reccomp_.comp) reccomp_.comp = &LEXICALCOMP; | | if (!reccomp_.comp) reccomp_.comp = LEXICALCOMP; | |
| if (!dump_meta() || !flush_leaf_cache(true) || !load_meta()) { | | if (!dump_meta() || !flush_leaf_cache(true) || !load_meta()) { | |
| delete_inner_cache(); | | delete_inner_cache(); | |
| delete_leaf_cache(); | | delete_leaf_cache(); | |
| db_.close(); | | db_.close(); | |
| return false; | | return false; | |
| } | | } | |
| } else { | | } else { | |
| if (!load_meta()) { | | if (!load_meta()) { | |
| db_.close(); | | db_.close(); | |
| return false; | | return false; | |
| | | | |
| skipping to change at line 1675 | | skipping to change at line 1675 | |
| ScopedSpinRWLock lock(&mlock_, true); | | ScopedSpinRWLock lock(&mlock_, true); | |
| if (omode_ == 0) { | | if (omode_ == 0) { | |
| set_error(_KCCODELINE_, Error::INVALID, "not opened"); | | set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |
| return false; | | return false; | |
| } | | } | |
| if (!db_.status(strmap)) return false; | | if (!db_.status(strmap)) return false; | |
| (*strmap)["type"] = strprintf("%u", (unsigned)DBTYPE); | | (*strmap)["type"] = strprintf("%u", (unsigned)DBTYPE); | |
| (*strmap)["psiz"] = strprintf("%d", psiz_); | | (*strmap)["psiz"] = strprintf("%d", psiz_); | |
| (*strmap)["pccap"] = strprintf("%lld", (long long)pccap_); | | (*strmap)["pccap"] = strprintf("%lld", (long long)pccap_); | |
| const char* compname = "external"; | | const char* compname = "external"; | |
|
| if (reccomp_.comp == &LEXICALCOMP) { | | if (reccomp_.comp == LEXICALCOMP) { | |
| compname = "lexical"; | | compname = "lexical"; | |
|
| } else if (reccomp_.comp == &DECIMALCOMP) { | | } else if (reccomp_.comp == DECIMALCOMP) { | |
| compname = "decimal"; | | compname = "decimal"; | |
|
| | | } else if (reccomp_.comp == LEXICALDESCCOMP) { | |
| | | compname = "lexicaldesc"; | |
| | | } else if (reccomp_.comp == DECIMALDESCCOMP) { | |
| | | compname = "decimaldesc"; | |
| } | | } | |
| (*strmap)["rcomp"] = compname; | | (*strmap)["rcomp"] = compname; | |
| (*strmap)["root"] = strprintf("%lld", (long long)root_); | | (*strmap)["root"] = strprintf("%lld", (long long)root_); | |
| (*strmap)["first"] = strprintf("%lld", (long long)first_); | | (*strmap)["first"] = strprintf("%lld", (long long)first_); | |
| (*strmap)["last"] = strprintf("%lld", (long long)last_); | | (*strmap)["last"] = strprintf("%lld", (long long)last_); | |
| (*strmap)["lcnt"] = strprintf("%lld", (long long)lcnt_); | | (*strmap)["lcnt"] = strprintf("%lld", (long long)lcnt_); | |
| (*strmap)["icnt"] = strprintf("%lld", (long long)icnt_); | | (*strmap)["icnt"] = strprintf("%lld", (long long)icnt_); | |
| (*strmap)["count"] = strprintf("%lld", (long long)count_); | | (*strmap)["count"] = strprintf("%lld", (long long)count_); | |
| (*strmap)["bnum"] = strprintf("%lld", (long long)bnum_); | | (*strmap)["bnum"] = strprintf("%lld", (long long)bnum_); | |
| (*strmap)["pnum"] = strprintf("%lld", (long long)db_.count()); | | (*strmap)["pnum"] = strprintf("%lld", (long long)db_.count()); | |
| | | | |
| skipping to change at line 1888 | | skipping to change at line 1892 | |
| if (omode_ != 0) { | | if (omode_ != 0) { | |
| set_error(_KCCODELINE_, Error::INVALID, "already opened"); | | set_error(_KCCODELINE_, Error::INVALID, "already opened"); | |
| return false; | | return false; | |
| } | | } | |
| return db_.tune_compressor(comp); | | return db_.tune_compressor(comp); | |
| } | | } | |
| /** | | /** | |
| * Set the record comparator. | | * Set the record comparator. | |
| * @param rcomp the record comparator object. | | * @param rcomp the record comparator object. | |
| * @return true on success, or false on failure. | | * @return true on success, or false on failure. | |
|
| | | * @note Several built-in comparators are provided. LEXICALCOMP for the | |
| | | default lexical | |
| | | * comparator. DECIMALCOMP for the decimal comparator. LEXICALDESCCOMP | |
| | | for the lexical | |
| | | * descending comparator. DECIMALDESCCOMP for the lexical descending com | |
| | | parator. | |
| */ | | */ | |
| bool tune_comparator(Comparator* rcomp) { | | bool tune_comparator(Comparator* rcomp) { | |
| _assert_(rcomp); | | _assert_(rcomp); | |
| ScopedSpinRWLock lock(&mlock_, true); | | ScopedSpinRWLock lock(&mlock_, true); | |
| if (omode_ != 0) { | | if (omode_ != 0) { | |
| set_error(_KCCODELINE_, Error::INVALID, "already opened"); | | set_error(_KCCODELINE_, Error::INVALID, "already opened"); | |
| return false; | | return false; | |
| } | | } | |
| reccomp_.comp = rcomp; | | reccomp_.comp = rcomp; | |
| return true; | | return true; | |
| | | | |
| skipping to change at line 3006 | | skipping to change at line 3013 | |
| } | | } | |
| /** | | /** | |
| * Dump the meta data into the file. | | * Dump the meta data into the file. | |
| * @return true on success, or false on failure. | | * @return true on success, or false on failure. | |
| */ | | */ | |
| bool dump_meta() { | | bool dump_meta() { | |
| _assert_(true); | | _assert_(true); | |
| char head[PDBHEADSIZ]; | | char head[PDBHEADSIZ]; | |
| std::memset(head, 0, sizeof(head)); | | std::memset(head, 0, sizeof(head)); | |
| char* wp = head; | | char* wp = head; | |
|
| if (reccomp_.comp == &LEXICALCOMP) { | | if (reccomp_.comp == LEXICALCOMP) { | |
| *(uint8_t*)(wp++) = 0x10; | | *(uint8_t*)(wp++) = 0x10; | |
|
| } else if (reccomp_.comp == &DECIMALCOMP) { | | } else if (reccomp_.comp == DECIMALCOMP) { | |
| *(uint8_t*)(wp++) = 0x11; | | *(uint8_t*)(wp++) = 0x11; | |
|
| | | } else if (reccomp_.comp == LEXICALDESCCOMP) { | |
| | | *(uint8_t*)(wp++) = 0x18; | |
| | | } else if (reccomp_.comp == DECIMALDESCCOMP) { | |
| | | *(uint8_t*)(wp++) = 0x19; | |
| } else { | | } else { | |
| *(uint8_t*)(wp++) = 0xff; | | *(uint8_t*)(wp++) = 0xff; | |
| } | | } | |
| wp = head + PDBMOFFNUMS; | | wp = head + PDBMOFFNUMS; | |
| uint64_t num = hton64(psiz_); | | uint64_t num = hton64(psiz_); | |
| std::memcpy(wp, &num, sizeof(num)); | | std::memcpy(wp, &num, sizeof(num)); | |
| wp += sizeof(num); | | wp += sizeof(num); | |
| num = hton64(root_); | | num = hton64(root_); | |
| std::memcpy(wp, &num, sizeof(num)); | | std::memcpy(wp, &num, sizeof(num)); | |
| wp += sizeof(num); | | wp += sizeof(num); | |
| | | | |
| skipping to change at line 3061 | | skipping to change at line 3072 | |
| char head[PDBHEADSIZ]; | | char head[PDBHEADSIZ]; | |
| int32_t hsiz = db_.get(PDBMETAKEY, sizeof(PDBMETAKEY) - 1, head, sizeof
(head)); | | int32_t hsiz = db_.get(PDBMETAKEY, sizeof(PDBMETAKEY) - 1, head, sizeof
(head)); | |
| if (hsiz < 0) return false; | | if (hsiz < 0) return false; | |
| if (hsiz != sizeof(head)) { | | if (hsiz != sizeof(head)) { | |
| set_error(_KCCODELINE_, Error::BROKEN, "invalid meta data record"); | | set_error(_KCCODELINE_, Error::BROKEN, "invalid meta data record"); | |
| db_.report(_KCCODELINE_, Logger::WARN, "hsiz=%d", hsiz); | | db_.report(_KCCODELINE_, Logger::WARN, "hsiz=%d", hsiz); | |
| return false; | | return false; | |
| } | | } | |
| const char* rp = head; | | const char* rp = head; | |
| if (*(uint8_t*)rp == 0x10) { | | if (*(uint8_t*)rp == 0x10) { | |
|
| reccomp_.comp = &LEXICALCOMP; | | reccomp_.comp = LEXICALCOMP; | |
| linkcomp_.comp = &LEXICALCOMP; | | linkcomp_.comp = LEXICALCOMP; | |
| } else if (*(uint8_t*)rp == 0x11) { | | } else if (*(uint8_t*)rp == 0x11) { | |
|
| reccomp_.comp = &DECIMALCOMP; | | reccomp_.comp = DECIMALCOMP; | |
| linkcomp_.comp = &DECIMALCOMP; | | linkcomp_.comp = DECIMALCOMP; | |
| } else if (*(uint8_t*)rp != 0xff || !reccomp_.comp) { | | } else if (*(uint8_t*)rp == 0x18) { | |
| | | reccomp_.comp = LEXICALDESCCOMP; | |
| | | linkcomp_.comp = LEXICALDESCCOMP; | |
| | | } else if (*(uint8_t*)rp == 0x19) { | |
| | | reccomp_.comp = DECIMALDESCCOMP; | |
| | | linkcomp_.comp = DECIMALDESCCOMP; | |
| | | } else if (*(uint8_t*)rp == 0xff) { | |
| | | if (!reccomp_.comp) { | |
| | | set_error(_KCCODELINE_, Error::INVALID, "the custom comparator is n | |
| | | ot given"); | |
| | | return false; | |
| | | } | |
| | | linkcomp_.comp = reccomp_.comp; | |
| | | } else { | |
| set_error(_KCCODELINE_, Error::BROKEN, "comparator is invalid"); | | set_error(_KCCODELINE_, Error::BROKEN, "comparator is invalid"); | |
| return false; | | return false; | |
| } | | } | |
| rp = head + PDBMOFFNUMS; | | rp = head + PDBMOFFNUMS; | |
| uint64_t num; | | uint64_t num; | |
| std::memcpy(&num, rp, sizeof(num)); | | std::memcpy(&num, rp, sizeof(num)); | |
| psiz_ = ntoh64(num); | | psiz_ = ntoh64(num); | |
| rp += sizeof(num); | | rp += sizeof(num); | |
| std::memcpy(&num, rp, sizeof(num)); | | std::memcpy(&num, rp, sizeof(num)); | |
| root_ = ntoh64(num); | | root_ = ntoh64(num); | |
| | | | |
| skipping to change at line 3299 | | skipping to change at line 3322 | |
| * Reorganize the database file. | | * Reorganize the database file. | |
| * @param mode the connection mode of the internal database. | | * @param mode the connection mode of the internal database. | |
| * @return true on success, or false on failure. | | * @return true on success, or false on failure. | |
| */ | | */ | |
| bool reorganize_file(uint32_t mode) { | | bool reorganize_file(uint32_t mode) { | |
| _assert_(true); | | _assert_(true); | |
| if (!load_meta()) { | | if (!load_meta()) { | |
| if (reccomp_.comp) { | | if (reccomp_.comp) { | |
| linkcomp_.comp = reccomp_.comp; | | linkcomp_.comp = reccomp_.comp; | |
| } else { | | } else { | |
|
| reccomp_.comp = &LEXICALCOMP; | | reccomp_.comp = LEXICALCOMP; | |
| linkcomp_.comp = &LEXICALCOMP; | | linkcomp_.comp = LEXICALCOMP; | |
| } | | } | |
| } | | } | |
| const std::string& path = db_.path(); | | const std::string& path = db_.path(); | |
| const std::string& npath = path + File::EXTCHR + PDBTMPPATHEXT; | | const std::string& npath = path + File::EXTCHR + PDBTMPPATHEXT; | |
| PlantDB tdb; | | PlantDB tdb; | |
| tdb.tune_comparator(reccomp_.comp); | | tdb.tune_comparator(reccomp_.comp); | |
| if (!tdb.open(npath, OWRITER | OCREATE | OTRUNCATE)) { | | if (!tdb.open(npath, OWRITER | OCREATE | OTRUNCATE)) { | |
| set_error(_KCCODELINE_, tdb.error().code(), "opening the destination
failed"); | | set_error(_KCCODELINE_, tdb.error().code(), "opening the destination
failed"); | |
| return false; | | return false; | |
| } | | } | |
| | | | |
End of changes. 11 change blocks. |
| 12 lines changed or deleted | | 39 lines changed or added | |
|
| kcpolydb.h | | kcpolydb.h | |
| | | | |
| skipping to change at line 406 | | skipping to change at line 406 | |
| * the path of the log file, or "-" for the standard output, or "+" for t
he standard error. | | * the path of the log file, or "-" for the standard output, or "+" for t
he standard error. | |
| * "logkinds" specifies kinds of logged messages and the value can be "de
bug", "info", "warn", | | * "logkinds" specifies kinds of logged messages and the value can be "de
bug", "info", "warn", | |
| * or "error". "logpx" specifies the prefix of each log message. "opts"
is for "tune_options" | | * or "error". "logpx" specifies the prefix of each log message. "opts"
is for "tune_options" | |
| * and the value can contain "s" for the small option, "l" for the linear
option, and "c" for | | * and the value can contain "s" for the small option, "l" for the linear
option, and "c" for | |
| * the compress option. "bnum" corresponds to "tune_bucket". "zcomp" is
for "tune_compressor" | | * the compress option. "bnum" corresponds to "tune_bucket". "zcomp" is
for "tune_compressor" | |
| * and the value can be "zlib" for the ZLIB raw compressor, "def" for the
ZLIB deflate | | * and the value can be "zlib" for the ZLIB raw compressor, "def" for the
ZLIB deflate | |
| * compressor, "gz" for the ZLIB gzip compressor, "lzo" for the LZO compr
essor, "lzma" for the | | * compressor, "gz" for the ZLIB gzip compressor, "lzo" for the LZO compr
essor, "lzma" for the | |
| * LZMA compressor, or "arc" for the Arcfour cipher. "zkey" specifies th
e cipher key of the | | * LZMA compressor, or "arc" for the Arcfour cipher. "zkey" specifies th
e cipher key of the | |
| * compressor. "capcnt" is for "cap_count". "capsiz" is for "cap_size".
"psiz" is for | | * compressor. "capcnt" is for "cap_count". "capsiz" is for "cap_size".
"psiz" is for | |
| * "tune_page". "rcomp" is for "tune_comparator" and the value can be "l
ex" for the lexical | | * "tune_page". "rcomp" is for "tune_comparator" and the value can be "l
ex" for the lexical | |
|
| * comparator or "dec" for the decimal comparator. "pccap" is for "tune_ | | * comparator, "dec" for the decimal comparator, "lexdesc" for the lexica | |
| page_cache". "apow" | | l descending | |
| * is for "tune_alignment". "fpow" is for "tune_fbp". "msiz" is for "tu | | * comparator, or "decdesc" for the decimal descending comparator. "pcca | |
| ne_map". "dfunit" is | | p" is for | |
| * for "tune_defrag". Every opened database must be closed by the PolyDB | | * "tune_page_cache". "apow" is for "tune_alignment". "fpow" is for "tu | |
| ::close method when | | ne_fbp". "msiz" is | |
| * it is no longer in use. It is not allowed for two or more database ob | | * for "tune_map". "dfunit" is for "tune_defrag". Every opened database | |
| jects in the same | | must be closed by | |
| * process to keep their connections to the same database file at the sam | | * the PolyDB::close method when it is no longer in use. It is not allow | |
| e time. | | ed for two or more | |
| | | * database objects in the same process to keep their connections to the | |
| | | same database file at | |
| | | * the same time. | |
| */ | | */ | |
| bool open(const std::string& path = ":", uint32_t mode = OWRITER | OCREAT
E) { | | bool open(const std::string& path = ":", uint32_t mode = OWRITER | OCREAT
E) { | |
| _assert_(true); | | _assert_(true); | |
| if (type_ == TYPEMISC) { | | if (type_ == TYPEMISC) { | |
| if (logger_) db_->tune_logger(logger_, logkinds_); | | if (logger_) db_->tune_logger(logger_, logkinds_); | |
| if (mtrigger_) db_->tune_meta_trigger(mtrigger_); | | if (mtrigger_) db_->tune_meta_trigger(mtrigger_); | |
| return db_->open(path, mode); | | return db_->open(path, mode); | |
| } | | } | |
| if (type_ != TYPEVOID) { | | if (type_ != TYPEVOID) { | |
| set_error(_KCCODELINE_, Error::INVALID, "already opened"); | | set_error(_KCCODELINE_, Error::INVALID, "already opened"); | |
| | | | |
| skipping to change at line 574 | | skipping to change at line 576 | |
| } else if (!std::strcmp(key, "dfunit") || !std::strcmp(key, "defrag
")) { | | } else if (!std::strcmp(key, "dfunit") || !std::strcmp(key, "defrag
")) { | |
| dfunit = atoix(value); | | dfunit = atoix(value); | |
| } else if (!std::strcmp(key, "zcomp") || !std::strcmp(key, "compres
sor")) { | | } else if (!std::strcmp(key, "zcomp") || !std::strcmp(key, "compres
sor")) { | |
| zcompname = value; | | zcompname = value; | |
| } else if (!std::strcmp(key, "psiz") || !std::strcmp(key, "page"))
{ | | } else if (!std::strcmp(key, "psiz") || !std::strcmp(key, "page"))
{ | |
| psiz = atoix(value); | | psiz = atoix(value); | |
| } else if (!std::strcmp(key, "pccap") || !std::strcmp(key, "cache")
) { | | } else if (!std::strcmp(key, "pccap") || !std::strcmp(key, "cache")
) { | |
| pccap = atoix(value); | | pccap = atoix(value); | |
| } else if (!std::strcmp(key, "rcomp") || !std::strcmp(key, "compara
tor")) { | | } else if (!std::strcmp(key, "rcomp") || !std::strcmp(key, "compara
tor")) { | |
| if (!std::strcmp(value, "lex") || !std::strcmp(value, "lexical"))
{ | | if (!std::strcmp(value, "lex") || !std::strcmp(value, "lexical"))
{ | |
|
| rcomp = &LEXICALCOMP; | | rcomp = LEXICALCOMP; | |
| } else if (!std::strcmp(value, "dec") || !std::strcmp(value, "dec
imal")) { | | } else if (!std::strcmp(value, "dec") || !std::strcmp(value, "dec
imal")) { | |
|
| rcomp = &DECIMALCOMP; | | rcomp = DECIMALCOMP; | |
| | | } else if (!std::strcmp(value, "lexdesc") || !std::strcmp(value, | |
| | | "lexicaldesc")) { | |
| | | rcomp = LEXICALDESCCOMP; | |
| | | } else if (!std::strcmp(value, "decdesc") || !std::strcmp(value, | |
| | | "decimaldesc")) { | |
| | | rcomp = DECIMALDESCCOMP; | |
| } | | } | |
| } else if (!std::strcmp(key, "zkey") || !std::strcmp(key, "pass") |
| | | } else if (!std::strcmp(key, "zkey") || !std::strcmp(key, "pass") |
| | |
| !std::strcmp(key, "password")) { | | !std::strcmp(key, "password")) { | |
| zkey = value; | | zkey = value; | |
| } | | } | |
| } | | } | |
| it++; | | it++; | |
| } | | } | |
| delete stdlogger_; | | delete stdlogger_; | |
| delete stdlogstrm_; | | delete stdlogstrm_; | |
| | | | |
| skipping to change at line 658 | | skipping to change at line 664 | |
| zcomp_ = new LZMACompressor<LZMA::RAW>; | | zcomp_ = new LZMACompressor<LZMA::RAW>; | |
| } else if (zcompname == "lzmacrc" || zcompname == "xzcrc") { | | } else if (zcompname == "lzmacrc" || zcompname == "xzcrc") { | |
| zcomp_ = new LZMACompressor<LZMA::CRC>; | | zcomp_ = new LZMACompressor<LZMA::CRC>; | |
| } else if (zcompname == "lzmasha" || zcompname == "xzsha") { | | } else if (zcompname == "lzmasha" || zcompname == "xzsha") { | |
| zcomp_ = new LZMACompressor<LZMA::SHA>; | | zcomp_ = new LZMACompressor<LZMA::SHA>; | |
| } else if (zcompname == "arc" || zcompname == "rc4") { | | } else if (zcompname == "arc" || zcompname == "rc4") { | |
| arccomp = new ArcfourCompressor(); | | arccomp = new ArcfourCompressor(); | |
| zcomp_ = arccomp; | | zcomp_ = arccomp; | |
| } else if (zcompname == "arcz" || zcompname == "rc4z") { | | } else if (zcompname == "arcz" || zcompname == "rc4z") { | |
| arccomp = new ArcfourCompressor(); | | arccomp = new ArcfourCompressor(); | |
|
| arccomp->set_compressor(&ZLIBRAWCOMP); | | arccomp->set_compressor(ZLIBRAWCOMP); | |
| zcomp_ = arccomp; | | zcomp_ = arccomp; | |
| } | | } | |
| } | | } | |
| BasicDB *db; | | BasicDB *db; | |
| switch (type) { | | switch (type) { | |
| default: { | | default: { | |
| set_error(_KCCODELINE_, Error::INVALID, "unknown database type"); | | set_error(_KCCODELINE_, Error::INVALID, "unknown database type"); | |
| return false; | | return false; | |
| } | | } | |
| case TYPEPHASH: { | | case TYPEPHASH: { | |
| | | | |
| skipping to change at line 1053 | | skipping to change at line 1059 | |
| */ | | */ | |
| int64_t match_prefix(const std::string& prefix, std::vector<std::string>*
strvec, | | int64_t match_prefix(const std::string& prefix, std::vector<std::string>*
strvec, | |
| int64_t max = -1, ProgressChecker* checker = NULL) { | | int64_t max = -1, ProgressChecker* checker = NULL) { | |
| _assert_(strvec); | | _assert_(strvec); | |
| const char* pbuf = prefix.data(); | | const char* pbuf = prefix.data(); | |
| size_t psiz = prefix.size(); | | size_t psiz = prefix.size(); | |
| if (max < 0) max = INT64_MAX; | | if (max < 0) max = INT64_MAX; | |
| Comparator* comp; | | Comparator* comp; | |
| switch (type_) { | | switch (type_) { | |
| case TYPEPTREE: { | | case TYPEPTREE: { | |
|
| comp = &LEXICALCOMP; | | comp = LEXICALCOMP; | |
| break; | | break; | |
| } | | } | |
| case TYPEGRASS: { | | case TYPEGRASS: { | |
| comp = ((GrassDB*)db_)->rcomp(); | | comp = ((GrassDB*)db_)->rcomp(); | |
| break; | | break; | |
| } | | } | |
| case TYPETREE: { | | case TYPETREE: { | |
| comp = ((TreeDB*)db_)->rcomp(); | | comp = ((TreeDB*)db_)->rcomp(); | |
| break; | | break; | |
| } | | } | |
| | | | |
| skipping to change at line 1082 | | skipping to change at line 1088 | |
| } | | } | |
| bool err = false; | | bool err = false; | |
| int64_t allcnt = count(); | | int64_t allcnt = count(); | |
| if (checker && !checker->check("match_prefix", "beginning", 0, allcnt))
{ | | if (checker && !checker->check("match_prefix", "beginning", 0, allcnt))
{ | |
| set_error(_KCCODELINE_, Error::LOGIC, "checker failed"); | | set_error(_KCCODELINE_, Error::LOGIC, "checker failed"); | |
| err = true; | | err = true; | |
| } | | } | |
| strvec->clear(); | | strvec->clear(); | |
| Cursor* cur = cursor(); | | Cursor* cur = cursor(); | |
| int64_t curcnt = 0; | | int64_t curcnt = 0; | |
|
| if (comp == &LEXICALCOMP) { | | if (comp == LEXICALCOMP) { | |
| if (cur->jump(pbuf, psiz)) { | | if (cur->jump(pbuf, psiz)) { | |
| while ((int64_t)strvec->size() < max) { | | while ((int64_t)strvec->size() < max) { | |
| size_t ksiz; | | size_t ksiz; | |
| char* kbuf = cur->get_key(&ksiz, true); | | char* kbuf = cur->get_key(&ksiz, true); | |
| if (kbuf) { | | if (kbuf) { | |
| if (ksiz >= psiz && !std::memcmp(kbuf, pbuf, psiz)) { | | if (ksiz >= psiz && !std::memcmp(kbuf, pbuf, psiz)) { | |
| strvec->push_back(std::string(kbuf, ksiz)); | | strvec->push_back(std::string(kbuf, ksiz)); | |
| } else { | | } else { | |
| delete[] kbuf; | | delete[] kbuf; | |
| break; | | break; | |
| | | | |
| skipping to change at line 1229 | | skipping to change at line 1235 | |
| } | | } | |
| case TYPEFOREST: { | | case TYPEFOREST: { | |
| comp = ((ForestDB*)db_)->rcomp(); | | comp = ((ForestDB*)db_)->rcomp(); | |
| break; | | break; | |
| } | | } | |
| default: { | | default: { | |
| comp = NULL; | | comp = NULL; | |
| break; | | break; | |
| } | | } | |
| } | | } | |
|
| if (!comp) comp = &LEXICALCOMP; | | if (!comp) comp = LEXICALCOMP; | |
| std::priority_queue<MergeLine> lines; | | std::priority_queue<MergeLine> lines; | |
| int64_t allcnt = 0; | | int64_t allcnt = 0; | |
| for (size_t i = 0; i < srcnum; i++) { | | for (size_t i = 0; i < srcnum; i++) { | |
| MergeLine line; | | MergeLine line; | |
| line.cur = srcary[i]->cursor(); | | line.cur = srcary[i]->cursor(); | |
| line.comp = comp; | | line.comp = comp; | |
| line.cur->jump(); | | line.cur->jump(); | |
| line.kbuf = line.cur->get(&line.ksiz, &line.vbuf, &line.vsiz, true); | | line.kbuf = line.cur->get(&line.ksiz, &line.vbuf, &line.vsiz, true); | |
| if (line.kbuf) { | | if (line.kbuf) { | |
| lines.push(line); | | lines.push(line); | |
| | | | |
End of changes. 7 change blocks. |
| 16 lines changed or deleted | | 25 lines changed or added | |
|