OpenSDN source code
patricia_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_patricia_map_h
7 #define vnsw_agent_patricia_map_h
8 
9 #include "base/patricia.h"
10 
11 #include <stdint.h>
12 
13 class PatriciaNode {
14 public:
15  PatriciaNode(int klen, int koffset, void *knode, const void *key_ptr) :
16  klen_(klen), koffset_(koffset), knode_(knode), key_ptr_(key_ptr) {
17  }
18 
19  class Key {
20  public:
21  static std::size_t BitLength(const PatriciaNode *key) {
22  return key->klen_*8;
23  }
24 
25  static char ByteValue(const PatriciaNode *key, std::size_t i) {
26  const char *ch = (const char *)key->key_ptr_;
27  return ch[key->koffset_ + key->klen_ - i - 1];
28  }
29  };
30 
31  int klen_;
32  int koffset_;
33  void *knode_;
34  const void *key_ptr_;
36 };
37 
38 template <class D, Patricia::Node D::* P, class K>
39 class PatriciaMap : public Patricia::Tree<D, P, K> {
40 public:
41  PatriciaMap(uint16_t klen, uint8_t koffset) :
42  Patricia::Tree<D, P, K>(), klen_(klen), koffset_(koffset) {
43  }
44 
45  uint16_t klen_;
46  uint8_t koffset_;
47 };
48 
50 
51 #endif /* vnsw_agent_patricia_map_h */
uint8_t koffset_
Definition: patricia_map.h:46
uint16_t klen_
Definition: patricia_map.h:45
PatriciaMap(uint16_t klen, uint8_t koffset)
Definition: patricia_map.h:41
static std::size_t BitLength(const PatriciaNode *key)
Definition: patricia_map.h:21
static char ByteValue(const PatriciaNode *key, std::size_t i)
Definition: patricia_map.h:25
PatriciaNode(int klen, int koffset, void *knode, const void *key_ptr)
Definition: patricia_map.h:15
Patricia::Node node_
Definition: patricia_map.h:35
void * knode_
Definition: patricia_map.h:33
const void * key_ptr_
Definition: patricia_map.h:34
PatriciaMap< PatriciaNode, &PatriciaNode::node_, PatriciaNode::Key > PatriciaMapTable
Definition: patricia_map.h:49