From 3acd38e70c81e859d02b48163945cd24fef95c9b Mon Sep 17 00:00:00 2001 From: IoTcat Date: Tue, 21 May 2019 19:42:23 +0800 Subject: [PATCH] add rand to math --- src/ovo.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ovo.h b/src/ovo.h index 11a39a8..eba2175 100644 --- a/src/ovo.h +++ b/src/ovo.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #ifdef _pthread @@ -100,6 +102,25 @@ namespace ovo{ */ class math { + public: + math(){ + srand(time(NULL)); + } + + /* rand */ + public: + unsigned long randNum; + inline int rand(const int& a, const int& b){ + return (clock() + (randNum++) * std::rand()) % std::abs(b - a + 1) + a; + } + + inline string randStr(const unsigned int length = 0){ + if(!length){ + return md5(to_string(clock()) + to_string(this->randNum++)); + } + return (sha256(to_string(clock()) + to_string(this->randNum++))).substr(0, length); + } + /*** md5 ***/ public: inline string md5 (const string message) const { @@ -401,6 +422,9 @@ namespace ovo{ if(method == "AES") this->_AES = true; else this->_AES = false; } + + /* no-sql */ + /* push data to database */ void pushData(data& data, const string& key); /* add data to database */ @@ -417,6 +441,13 @@ namespace ovo{ /* del data */ void del(const string& key); + /* sql */ + void _createTable(const string& tableName, std::vector v){ + ovo::data d; + + }; + + private: ovo::math m; string _path; @@ -430,6 +461,14 @@ namespace ovo{ string cmd = "if not exist " + _path + " md " + _path; system(cmd.c_str()); } + + inline string generateTableName(const string& tableName){ + return m.sha256("__OVO_DB_TABLE__" + tableName); + } + + inline string generateIndex(const string& salt = ""){ + return m.sha256(m.randStr() + salt); + } }; }