mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-01-26 22:50:56 +00:00
add uuid generator
This commit is contained in:
parent
6056c0c4af
commit
f5a93fae0f
@ -8,4 +8,4 @@ include_directories(./invodb)
|
|||||||
|
|
||||||
add_executable(InvoDB
|
add_executable(InvoDB
|
||||||
invodb/main.cpp
|
invodb/main.cpp
|
||||||
invodb/main.h invodb/file/page_manager.cpp invodb/file/page_manager.h invodb/models/json.cpp invodb/models/json.h invodb/invodb.cpp invodb/invodb.h invodb/models/collection.cpp invodb/models/collection.h invodb/file/storage_page.cpp invodb/file/storage_page.h invodb/utils/logger.h invodb/utils/uuid.h)
|
invodb/main.h invodb/file/page_manager.cpp invodb/file/page_manager.h invodb/models/json.cpp invodb/models/json.h invodb/invodb.cpp invodb/invodb.h invodb/models/collection.cpp invodb/models/collection.h invodb/file/storage_page.cpp invodb/file/storage_page.h invodb/utils/logger.h invodb/utils/uuid.h invodb/btree/btree_node.cpp invodb/btree/btree_node.h)
|
||||||
|
5
invodb/btree/btree_node.cpp
Normal file
5
invodb/btree/btree_node.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by i on 2021/10/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "btree_node.h"
|
28
invodb/btree/btree_node.h
Normal file
28
invodb/btree/btree_node.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by i on 2021/10/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef INVODB_BTREE_NODE_H
|
||||||
|
#define INVODB_BTREE_NODE_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* m = 16
|
||||||
|
* value string max 56
|
||||||
|
* (56 + 4)*16 + 4 * 16 = 1024
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BTreeNode {
|
||||||
|
public:
|
||||||
|
BTreeNode() { memset(arr, 0, sizeof(arr)); }
|
||||||
|
private:
|
||||||
|
struct NodeValue {
|
||||||
|
char key[56];
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
std::pair<char *, int> arr[127];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //INVODB_BTREE_NODE_H
|
@ -47,7 +47,6 @@ void StoragePage::setStringStartFrom(const int &index, const char *str) {
|
|||||||
for(int i=0; i<strlen(str); i++) {
|
for(int i=0; i<strlen(str); i++) {
|
||||||
page[index+i] = str[i];
|
page[index+i] = str[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoragePage::save() {
|
void StoragePage::save() {
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
PageManager::loadDatabase("test.invodb");
|
PageManager::loadDatabase("test.invodb");
|
||||||
Collection::loadCollections();
|
Collection::loadCollections();
|
||||||
|
|
||||||
PageManager& manager = PageManager::Instance();
|
PageManager& manager = PageManager::Instance();
|
||||||
|
|
||||||
|
|
||||||
//Collection::createCollection("hello");
|
//Collection::createCollection("hello");
|
||||||
Collection &col = Collection::getCollection("hello");
|
Collection &col = Collection::getCollection("hello");
|
||||||
|
|
||||||
|
@ -11,17 +11,15 @@ Collection::Collection(const std::string &name, const int &firstPage) {
|
|||||||
|
|
||||||
void Collection::insert(JSON &json) {
|
void Collection::insert(JSON &json) {
|
||||||
|
|
||||||
if(!json.HasMember(" __Invo_ID__")) {
|
if(!json.HasMember("__Invo_ID__")) {
|
||||||
std::string uuid = generateUUID();
|
char uuid[32];
|
||||||
|
generateUUID(uuid);
|
||||||
Document::AllocatorType &allocator = json.GetAllocator();
|
Document::AllocatorType &allocator = json.GetAllocator();
|
||||||
Value invoid (kStringType);
|
Value invoid (kStringType);
|
||||||
invoid.SetString(uuid.c_str(), 3);
|
invoid.SetString(uuid, 32);
|
||||||
json.AddMember(" __Invo_ID__", invoid, allocator);
|
json.AddMember("__Invo_ID__", invoid, allocator);
|
||||||
}
|
}
|
||||||
|
Logger::info<std::string, std::string>("INSERT ", json.ToString());
|
||||||
|
|
||||||
|
|
||||||
Logger::info<std::string>(json.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,10 +10,8 @@
|
|||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void info(const T& msg);
|
static void info(const T& msg);
|
||||||
|
|
||||||
template<typename T, typename K>
|
template<typename T, typename K>
|
||||||
static void info(const T& first, const K& second);
|
static void info(const T& first, const K& second);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -8,16 +8,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::string generateUUID() {
|
void generateUUID(char *uuid) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
std::string uuid;
|
|
||||||
for(int i=0; i<32; i++) {
|
for(int i=0; i<32; i++) {
|
||||||
int randn = rand() % 36;
|
int randn = rand() % 36;
|
||||||
//0~35;
|
uuid[i] = (randn < 26 ? ('a' + randn) : ('0' + (randn - 26)));
|
||||||
uuid += (randn < 26 ? ('a' + randn) : ('0' + (randn - 26)));
|
|
||||||
}
|
}
|
||||||
std::cout << uuid << std::endl;
|
|
||||||
return uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //INVODB_UUID_H
|
#endif //INVODB_UUID_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user