commit d0ff4d309b63710801091127f83372ac18453be1 Author: huangsimin Date: Thu Aug 1 18:21:41 2019 +0800 测试树 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9348895 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vscode +main +.attach_* +*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5193e0e --- /dev/null +++ b/Makefile @@ -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) \ No newline at end of file diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/include/.gitignore b/include/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..63ce472 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +using namespace std; +using chrono::high_resolution_clock; + + + +void Case1() +{ + std::map 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(); +} \ No newline at end of file diff --git a/src/vbtree.hpp b/src/vbtree.hpp new file mode 100644 index 0000000..b4c0299 --- /dev/null +++ b/src/vbtree.hpp @@ -0,0 +1,80 @@ + + +#include +#include + +using namespace std; +using std::cout, std::endl; + +template +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 */ +};