-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaatree.hpp
62 lines (57 loc) · 1.43 KB
/
aatree.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Description
*
* @file aatree.hpp
* @date 2014-10-09 23:56:00
* @author FightingMan <[email protected]>
* @copyright (c) 2014 FightingMan.
*/
#ifndef _AATREE_HPP
#define _AATREE_HPP
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <cstdio>
namespace HPHP {
/* {{{ class AATree */
class AATree {
public:
AATree();
~AATree();
struct ipLocation {
uint64_t start;
uint64_t end;
std::string country;
std::string province;
std::string area;
std::string city;
std::string isp;
};
struct node {
ipLocation* key;
int level;
node *right;
node *left;
node *parent;
};
int lookup(const std::string &);
node *search(const std::string &);
int countnode();
void makeEmpty();
private:
node *root;
int count;
uint64_t ip_str2long(const char*);
void ip_trim(char*);
void skew(node *);
bool split(node *);
void rebal(node *);
node *insert(node *, node *);
void print(node *);
void makeEmpty(node *);
};
/* }}} */
}
#endif
/* vim: set ts=4 sw=4 sts=4 tw=100 et: */