InvoDB/invodb/btree/btree_node.h

58 lines
1.1 KiB
C
Raw Normal View History

2021-10-24 20:21:04 +08:00
//
// Created by i on 2021/10/24.
//
#ifndef INVODB_BTREE_NODE_H
#define INVODB_BTREE_NODE_H
#include <iostream>
#include <cstring>
2021-10-25 22:07:18 +08:00
#include <algorithm>
#include <map>
#include "file/page_manager.h"
2021-10-24 20:21:04 +08:00
/**
2021-10-26 12:29:59 +08:00
* m = 27
2021-10-25 22:07:18 +08:00
* value string max
* (32 + 4)*28 + 5 = 1013
2021-10-24 20:21:04 +08:00
*/
2021-10-25 22:07:18 +08:00
2021-10-28 23:15:15 +08:00
class NodeUUID {
2021-10-24 20:21:04 +08:00
public:
2021-10-28 23:15:15 +08:00
static NodeUUID* getNode(const int& address);
static NodeUUID* release(const int& address);
int insert(const std::string& uuid);
int findPos(const std::string& uuid);
2021-10-26 12:29:59 +08:00
void print();
2021-10-28 23:15:15 +08:00
void release();
2021-10-26 12:29:59 +08:00
void clear();
void save();
2021-10-28 23:15:15 +08:00
//static const int m = 27;
static const int m = 3;
static const int maxCount = m - 1;
static const int minLeafCount = m / 2;
static const int minLinkCount = (m - 1) / 2;
bool enough() {
if(leaf) return size >= minLeafCount;
else return size >= minLinkCount;
}
bool full() {
return size == maxCount;
}
2021-10-26 12:29:59 +08:00
std::string key[m+1];
2021-10-25 23:15:15 +08:00
int val[m+1];
2021-10-25 22:07:18 +08:00
int parent;
2021-10-26 12:29:59 +08:00
int left;
int right;
bool leaf;
int size;
int address;
2021-10-24 20:21:04 +08:00
private:
2021-10-28 23:15:15 +08:00
NodeUUID(const int& address);
static std::map<int, NodeUUID*> map;
2021-10-26 12:29:59 +08:00
2021-10-24 20:21:04 +08:00
};
#endif //INVODB_BTREE_NODE_H