From 68a249e0fa2c9f2519c56c7421cce00ba8c3f8a0 Mon Sep 17 00:00:00 2001 From: visor Date: Wed, 14 Oct 2015 23:13:58 +0900 Subject: [PATCH] change the store directory layout. --- lib/util_string.cc | 36 ++++++++++++++++++++++++++++++++++++ lib/util_string.h | 33 +++++++++------------------------ modules/ml-store.cc | 7 +++---- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/lib/util_string.cc b/lib/util_string.cc index a1b2e25..a18993b 100644 --- a/lib/util_string.cc +++ b/lib/util_string.cc @@ -110,11 +110,47 @@ ustring c3 (const ustring& str) { } } +ustring to_ustring (int32_t v) { + return boost::lexical_cast (v); +} + +ustring to_ustring (uint32_t v) { + return boost::lexical_cast (v); +} + +ustring to_ustring (long int v) { + return boost::lexical_cast (v); +} + +ustring to_ustring (unsigned long int v) { + return boost::lexical_cast (v); +} + +ustring to_ustring (long long int v) { + return boost::lexical_cast (v); +} + +ustring to_ustring (unsigned long long int v) { + return boost::lexical_cast (v); +} + ustring to_ustring (double val) { char b[32]; return ustring (b, snprintf (b, 32, "%.*g", DBL_DIG, val)); } +int32_t to_int32 (const ustring& v) { + return boost::lexical_cast (v); +} + +uint32_t to_uint32 (const ustring& v) { + return boost::lexical_cast (v); +} + +uint64_t to_uint64 (const ustring& v) { + return boost::lexical_cast (v); +} + static int hex (char c) { if ('0' <= c && c <= '9') { return (c - '0'); diff --git a/lib/util_string.h b/lib/util_string.h index b98317a..c20c642 100644 --- a/lib/util_string.h +++ b/lib/util_string.h @@ -25,31 +25,16 @@ class UIConv { }; ustring c3 (const ustring& str); -inline ustring to_ustring (int32_t v) { - return boost::lexical_cast (v); -} -inline ustring to_ustring (uint32_t v) { - return boost::lexical_cast (v); -} -inline ustring to_ustring (long int v) { - return boost::lexical_cast (v); -} -inline ustring to_ustring (unsigned long int v) { - return boost::lexical_cast (v); -} -inline ustring to_ustring (long long int v) { - return boost::lexical_cast (v); -} -inline ustring to_ustring (unsigned long long int v) { - return boost::lexical_cast (v); -} +ustring to_ustring (int32_t v); +ustring to_ustring (uint32_t v); +ustring to_ustring (long int v); +ustring to_ustring (unsigned long int v); +ustring to_ustring (long long int v); +ustring to_ustring (unsigned long long int v); ustring to_ustring (double val); -inline int32_t to_int32 (const ustring& v) { - return boost::lexical_cast (v); -} -inline uint32_t to_uint32 (const ustring& v) { - return boost::lexical_cast (v); -} +int32_t to_int32 (const ustring& v); +uint32_t to_uint32 (const ustring& v); +uint64_t to_uint64 (const ustring& v); ustring percentHEX (int c); ustring urldecode_nonul (const ustring& str); ustring omitCtrl (const ustring& str); diff --git a/modules/ml-store.cc b/modules/ml-store.cc index b144f1a..789ae55 100644 --- a/modules/ml-store.cc +++ b/modules/ml-store.cc @@ -149,10 +149,9 @@ static bool splitRec (ustring& rec, ustring& uctime, ustring& uatime, ustring& void newStoreSerial (MlEnv* mlenv) { BDBHash db; FileMacro lock; - uint32_t srl; + uint64_t srl; ustring v, x, subdir, nw; time_t tm; - uint32_t n; ustring xs; tm = now (); @@ -163,17 +162,17 @@ void newStoreSerial (MlEnv* mlenv) { openDB (db, lock, mlenv); if (db.get (uDash, x)) { - srl = to_uint32 (x) + 1; + srl = to_uint64 (x) + 1; } else { srl = 1; } - n = srl; xs = randomKey (srl); x = to_ustring (srl); db.put (uDash, x); + subdir.append (to_ustring (srl & 0x000003FFF000ULL)).append (uSlash); subdir.append (x); v = nw; v.append (uColon).append (nw).append (uColon).append (x).append (uColon).append (subdir).append (uColon); -- 2.11.0