Skip to content

Commit

Permalink
fineTree init
Browse files Browse the repository at this point in the history
  • Loading branch information
runshenzhu committed May 5, 2016
1 parent 184e5f0 commit 1679525
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fineTree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.5)
project(fineTree)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(fineTree ${SOURCE_FILES})
12 changes: 12 additions & 0 deletions fineTree/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CFLAGS=-Werror -Wall -std=c++11 -mavx2 -pedantic -O3 -I/usr/local/include

LDFLAGS=-L/usr/local/lib -lboost_atomic-mt -lboost_system-mt -lboost_thread-mt -lglog #-ljemalloc
CC=g++

all: fineTree_test

fineTree_test: main.cpp fineTree.h
$(CC) $(CFLAGS) -o palmtree_test main.cpp $(LDFLAGS)

clean:
rm -rf fineTree_test *.o
139 changes: 139 additions & 0 deletions fineTree/fineTree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
//
// Created by Zrs_y on 5/5/16.
//

#ifndef FINETREE_FINETREE_H
#define FINETREE_FINETREE_H

#define UNUSED __attribute__((unused))

enum NodeType {
INNERNODE = 0,
LEAFNODE
};

static std::atomic<int> NODE_NUM(0);

template <typename KeyType,
typename ValueType,
typename PairType = std::pair<KeyType, ValueType>,
typename KeyComparator = std::less<KeyType> >
class fineTree {

public:
fineTree(KeyType min_key) {
this->min_key = min_key;
}

int search(KeyType UNUSED key) {
return 0;
}

void insert(KeyType UNUSED key, ValueType UNUSED val) {

}

private:
KeyType min_key;
// Max number of slots per inner node
static const int INNER_MAX_SLOT = 256;
// Max number of slots per leaf node
static const int LEAF_MAX_SLOT = 64;

struct Node {
// Number of actually used slots
int slot_used;
int id;
int level;
KeyType lower_bound;
Node *parent;


Node() = delete;
Node(Node *p, int lvl): slot_used(0), level(lvl), parent(p) {
id = NODE_NUM++;
};
virtual ~Node() {};
virtual std::string to_string() = 0;
virtual NodeType type() const = 0;
virtual bool is_few() = 0;
};

struct InnerNode : public Node {
InnerNode() = delete;
InnerNode(Node *parent, int level): Node(parent, level){};
virtual ~InnerNode() {};
// Keys for values
KeyType keys[LEAF_MAX_SLOT];
// Pointers for child nodes
Node *values[LEAF_MAX_SLOT];

virtual NodeType type() const {
return INNERNODE;
}

virtual std::string to_string() {
std::string res;
res += "InnerNode[" + std::to_string(Node::id) + " @ " + std::to_string(Node::level) + "] ";
// res += std::to_string(Node::slot_used);
for (int i = 0 ; i < Node::slot_used ; i++) {
res += " " + std::to_string(keys[i]) + ":" + std::to_string(values[i]->id);
}
return res;
}

inline bool is_full() const {
return Node::slot_used == MAX_SLOT();
}


inline size_t MAX_SLOT() const {
return LEAF_MAX_SLOT;
}

virtual inline bool is_few() {
return Node::slot_used < MAX_SLOT()/4 || Node::slot_used == 0;
}

};

struct LeafNode : public Node {
LeafNode() = delete;
LeafNode(Node *parent, int level): Node(parent, level){};
virtual ~LeafNode() {};

// Keys and values for leaf node
KeyType keys[INNER_MAX_SLOT];
ValueType values[INNER_MAX_SLOT];

virtual NodeType type() const {
return LEAFNODE;
}

virtual std::string to_string() {
std::string res;
res += "LeafNode[" + std::to_string(Node::id) + " @ " + std::to_string(Node::level) + "] ";

for (int i = 0 ; i < Node::slot_used ; i++) {
res += " " + std::to_string(keys[i]) + ":" + std::to_string(values[i]);
}
return res;
}

inline bool is_full() const {
return Node::slot_used == MAX_SLOT();
}

inline size_t MAX_SLOT() const {
return INNER_MAX_SLOT;
}

virtual inline bool is_few() {
return Node::slot_used < MAX_SLOT()/4 || Node::slot_used == 0;
}
};

};


#endif //FINETREE_FINETREE_H
12 changes: 12 additions & 0 deletions fineTree/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include "fineTree.h"
using namespace std;

int main() {
cout << "Hello, World!" << endl;

fineTree<int, int> fTree(0xffffffff);
auto res = fTree.search(1);

return res;
}

0 comments on commit 1679525

Please sign in to comment.