mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-01-27 15:10:57 +00:00
btree find
This commit is contained in:
parent
177cee9f91
commit
8fdec82448
@ -177,6 +177,26 @@ void BTreeUUID::innerPrint(BTreeNodeUUID *cur) {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BTreeUUID::find(std::string uuid) {
|
||||||
|
BTreeNodeUUID* cur = BTreeNodeUUID::getNode(root);
|
||||||
|
while(!cur->leaf) {
|
||||||
|
for(int i=0; i<cur->size; i++) {
|
||||||
|
if(uuid < cur->key[i]) {
|
||||||
|
cur = BTreeNodeUUID::getNode(cur->val[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(i == cur->size - 1) {
|
||||||
|
cur = BTreeNodeUUID::getNode(cur->val[i + 1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=0; i<cur->size; i++) {
|
||||||
|
if(uuid == cur->key[i]) return cur->val[i];
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
void BTreeUUID::innerInsert(BTreeNodeUUID* &p, BTreeNodeUUID* f, const char *uuid, int address) {
|
void BTreeUUID::innerInsert(BTreeNodeUUID* &p, BTreeNodeUUID* f, const char *uuid, int address) {
|
||||||
if(p == nullptr) {
|
if(p == nullptr) {
|
||||||
|
@ -11,9 +11,11 @@ class BTreeUUID {
|
|||||||
public:
|
public:
|
||||||
BTreeUUID(const int& address);
|
BTreeUUID(const int& address);
|
||||||
void insert(const char* uuid, int address);
|
void insert(const char* uuid, int address);
|
||||||
|
int find(std::string uuid);
|
||||||
void print();
|
void print();
|
||||||
private:
|
private:
|
||||||
void innerPrint(BTreeNodeUUID* cur);
|
void innerPrint(BTreeNodeUUID* cur);
|
||||||
|
|
||||||
void split(std::string uuid, int address, int parentAddr, int curAddr);
|
void split(std::string uuid, int address, int parentAddr, int curAddr);
|
||||||
void insertInternal(std::string uuid, int curAddr, int lLeafAddr, int rLeafAddr);
|
void insertInternal(std::string uuid, int curAddr, int lLeafAddr, int rLeafAddr);
|
||||||
int root;
|
int root;
|
||||||
|
@ -27,12 +27,18 @@ int main() {
|
|||||||
|
|
||||||
BTreeUUID *btree = new BTreeUUID(PageManager::Instance().allocate());
|
BTreeUUID *btree = new BTreeUUID(PageManager::Instance().allocate());
|
||||||
char uuid[32];
|
char uuid[32];
|
||||||
for(int i=0; i<1000000; i++) {
|
|
||||||
|
std::vector<std::string> v;
|
||||||
|
|
||||||
|
for(int i=0; i<10000; i++) {
|
||||||
generateUUID(uuid);
|
generateUUID(uuid);
|
||||||
|
v.push_back(std::string(uuid, 32));
|
||||||
btree->insert(uuid, PageManager::Instance().allocate());
|
btree->insert(uuid, PageManager::Instance().allocate());
|
||||||
}
|
}
|
||||||
|
|
||||||
btree->print();
|
btree->print();
|
||||||
|
|
||||||
|
printf("%d\n", btree->find("123"));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -8,6 +8,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <vector>
|
||||||
#include <models/collection.h>
|
#include <models/collection.h>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user