forked from runshenzhu/palmtree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
184e5f0
commit 1679525
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |