|
Revision 569, 1.4 kB
(checked in by ahu, 3 years ago)
|
some module g++ 4.1 cleanups
|
- Property svn:eol-style set to
native
- Property svn:keywords set to
author date id revision
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
#include <string> |
|---|
| 9 |
#include <sys/types.h> |
|---|
| 10 |
#include <cstdlib> |
|---|
| 11 |
#include <stdint.h> |
|---|
| 12 |
|
|---|
| 13 |
using namespace std; |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
typedef struct node_t { |
|---|
| 17 |
node_t *child[2]; |
|---|
| 18 |
short value; |
|---|
| 19 |
} node_t; |
|---|
| 20 |
|
|---|
| 21 |
class IPPrefTree{ |
|---|
| 22 |
|
|---|
| 23 |
public: |
|---|
| 24 |
IPPrefTree(); |
|---|
| 25 |
~IPPrefTree(); |
|---|
| 26 |
|
|---|
| 27 |
void add(const string &prefix, const short value); |
|---|
| 28 |
void add(const uint32_t ip, const int preflen, const short value); |
|---|
| 29 |
|
|---|
| 30 |
short lookup(const string &prefix) const; |
|---|
| 31 |
short lookup(const uint32_t ip, const int preflen) const; |
|---|
| 32 |
|
|---|
| 33 |
void clear(); |
|---|
| 34 |
|
|---|
| 35 |
int getNodeCount() const; |
|---|
| 36 |
int getMemoryUsage() const; |
|---|
| 37 |
|
|---|
| 38 |
private: |
|---|
| 39 |
node_t *root; |
|---|
| 40 |
int nodecount; |
|---|
| 41 |
|
|---|
| 42 |
void addNode(node_t * node, const uint32_t ip, const uint32_t mask, const short value); |
|---|
| 43 |
node_t * allocateNode(); |
|---|
| 44 |
const node_t * findDeepestFilledNode(const node_t *root, const uint32_t ip, const uint32_t mask) const; |
|---|
| 45 |
void removeNode(node_t * node); |
|---|
| 46 |
|
|---|
| 47 |
inline uint32_t preflenToNetmask(const int preflen) const; |
|---|
| 48 |
inline void parsePrefix(const string &prefix, uint32_t &ip, int &preflen) const; |
|---|
| 49 |
}; |
|---|
| 50 |
|
|---|
| 51 |
class ParsePrefixException |
|---|
| 52 |
{ |
|---|
| 53 |
public: |
|---|
| 54 |
ParsePrefixException() { reason = ""; }; |
|---|
| 55 |
ParsePrefixException(string r) { reason = r; }; |
|---|
| 56 |
|
|---|
| 57 |
string reason; |
|---|
| 58 |
}; |
|---|