测试树
This commit is contained in:
commit
d0ff4d309b
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.vscode
|
||||
main
|
||||
.attach_*
|
||||
*.o
|
26
Makefile
Normal file
26
Makefile
Normal file
|
@ -0,0 +1,26 @@
|
|||
CC := g++
|
||||
C_FLAGS := -std=c++17 -Wall -Wextra -g -O2
|
||||
|
||||
BIN := bin
|
||||
SRC := src
|
||||
INCLUDE := include
|
||||
LIB := lib
|
||||
|
||||
LIBRARIES :=
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
EXECUTABLE := main.exe
|
||||
else
|
||||
EXECUTABLE := main
|
||||
endif
|
||||
|
||||
all: $(BIN)/$(EXECUTABLE)
|
||||
|
||||
clean:
|
||||
$(RM) $(BIN)/$(EXECUTABLE)
|
||||
|
||||
run: all
|
||||
./$(BIN)/$(EXECUTABLE)
|
||||
|
||||
$(BIN)/$(EXECUTABLE): $(SRC)/*
|
||||
$(CC) $(C_FLAGS) -I$(INCLUDE) -L$(LIB) $^ -o $@ $(LIBRARIES)
|
0
bin/.gitignore
vendored
Normal file
0
bin/.gitignore
vendored
Normal file
0
include/.gitignore
vendored
Normal file
0
include/.gitignore
vendored
Normal file
0
lib/.gitignore
vendored
Normal file
0
lib/.gitignore
vendored
Normal file
36
src/main.cpp
Normal file
36
src/main.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <iostream>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
using namespace std;
|
||||
using chrono::high_resolution_clock;
|
||||
|
||||
|
||||
|
||||
void Case1()
|
||||
{
|
||||
std::map<int, int> m;
|
||||
|
||||
|
||||
default_random_engine e;
|
||||
std::uniform_int_distribution<> dist{0, 1000000000};
|
||||
double N = 1000000;
|
||||
|
||||
|
||||
high_resolution_clock::time_point t1 = high_resolution_clock::now(); //返回时间戳
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
auto v = dist(e);
|
||||
m[v] = v;
|
||||
}
|
||||
high_resolution_clock::time_point t2 = high_resolution_clock::now(); //返回时间戳
|
||||
|
||||
std::cout << (t2 - t1).count() / N << std::endl;
|
||||
std::cout << "end Push Case Benchmark" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Case1();
|
||||
}
|
80
src/vbtree.hpp
Normal file
80
src/vbtree.hpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
using std::cout, std::endl;
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class VBTree
|
||||
{
|
||||
public:
|
||||
typedef struct Node
|
||||
{
|
||||
Node *children[2];
|
||||
Node *parent;
|
||||
unsigned long size;
|
||||
TKey key;
|
||||
TValue value;
|
||||
/* data */
|
||||
} ;
|
||||
|
||||
public:
|
||||
void put(TKey key, TValue value) {
|
||||
Node *node = new Node();
|
||||
}
|
||||
|
||||
// if tree.root == nil {
|
||||
// tree.root = node
|
||||
// return
|
||||
// }
|
||||
|
||||
// for cur := tree.root; ; {
|
||||
|
||||
// if cur.size > 8 {
|
||||
// factor := cur.size / 10 // or factor = 1
|
||||
// ls, rs := cur.children[0].size, cur.children[1].size
|
||||
// if rs >= ls*2+factor || ls >= rs*2+factor {
|
||||
// tree.fixSize(cur, ls, rs)
|
||||
// }
|
||||
// }
|
||||
|
||||
// cur.size++
|
||||
|
||||
// c := tree.Compare(key, cur.key)
|
||||
// if c < 0 {
|
||||
// if cur.children[0] == nil {
|
||||
// cur.children[0] = node
|
||||
// node.parent = cur
|
||||
|
||||
// if cur.parent != nil && cur.parent.size == 3 {
|
||||
// if cur.parent.children[0] == nil {
|
||||
// tree.lrrotate3(cur.parent)
|
||||
// } else {
|
||||
// tree.rrotate3(cur.parent)
|
||||
// }
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// cur = cur.children[0]
|
||||
// } else {
|
||||
// if cur.children[1] == nil {
|
||||
// cur.children[1] = node
|
||||
// node.parent = cur
|
||||
|
||||
// if cur.parent != nil && cur.parent.size == 3 {
|
||||
// if cur.parent.children[1] == nil {
|
||||
// tree.rlrotate3(cur.parent)
|
||||
// } else {
|
||||
// tree.lrotate3(cur.parent)
|
||||
// }
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// cur = cur.children[1]
|
||||
// }
|
||||
// }
|
||||
|
||||
/* data */
|
||||
};
|
Loading…
Reference in New Issue
Block a user