mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-01-25 22:20:58 +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) {
|
||||
if(p == nullptr) {
|
||||
|
@ -11,9 +11,11 @@ class BTreeUUID {
|
||||
public:
|
||||
BTreeUUID(const int& address);
|
||||
void insert(const char* uuid, int address);
|
||||
int find(std::string uuid);
|
||||
void print();
|
||||
private:
|
||||
void innerPrint(BTreeNodeUUID* cur);
|
||||
|
||||
void split(std::string uuid, int address, int parentAddr, int curAddr);
|
||||
void insertInternal(std::string uuid, int curAddr, int lLeafAddr, int rLeafAddr);
|
||||
int root;
|
||||
|
@ -27,12 +27,18 @@ int main() {
|
||||
|
||||
BTreeUUID *btree = new BTreeUUID(PageManager::Instance().allocate());
|
||||
char uuid[32];
|
||||
for(int i=0; i<1000000; i++) {
|
||||
|
||||
std::vector<std::string> v;
|
||||
|
||||
for(int i=0; i<10000; i++) {
|
||||
generateUUID(uuid);
|
||||
v.push_back(std::string(uuid, 32));
|
||||
btree->insert(uuid, PageManager::Instance().allocate());
|
||||
}
|
||||
|
||||
btree->print();
|
||||
|
||||
printf("%d\n", btree->find("123"));
|
||||
|
||||
return 0;
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include <models/collection.h>
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user