Line data Source code
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 23369 : PatriciaNode(int klen, int koffset, void *knode, const void *key_ptr) : 16 23369 : klen_(klen), koffset_(koffset), knode_(knode), key_ptr_(key_ptr) { 17 23369 : } 18 : 19 : class Key { 20 : public: 21 230807 : static std::size_t BitLength(const PatriciaNode *key) { 22 230807 : return key->klen_*8; 23 : } 24 : 25 359092 : static char ByteValue(const PatriciaNode *key, std::size_t i) { 26 359092 : const char *ch = (const char *)key->key_ptr_; 27 359092 : 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_; 35 : Patricia::Node node_; 36 : }; 37 : 38 : template <class D, Patricia::Node D::* P, class K> 39 : class PatriciaMap : public Patricia::Tree<D, P, K> { 40 : public: 41 6850 : PatriciaMap(uint16_t klen, uint8_t koffset) : 42 6850 : Patricia::Tree<D, P, K>(), klen_(klen), koffset_(koffset) { 43 6850 : } 44 : 45 : uint16_t klen_; 46 : uint8_t koffset_; 47 : }; 48 : 49 : typedef PatriciaMap<PatriciaNode, &PatriciaNode::node_, PatriciaNode::Key> PatriciaMapTable; 50 : 51 : #endif /* vnsw_agent_patricia_map_h */