![]() |
libzmq master
The Intelligent Transport Layer
|
00001 /* 00002 Copyright (c) 2009-2011 250bpm s.r.o. 00003 Copyright (c) 2007-2009 iMatix Corporation 00004 Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file 00005 00006 This file is part of 0MQ. 00007 00008 0MQ is free software; you can redistribute it and/or modify it under 00009 the terms of the GNU Lesser General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 0MQ is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 #ifndef __ZMQ_TRIE_HPP_INCLUDED__ 00023 #define __ZMQ_TRIE_HPP_INCLUDED__ 00024 00025 #include <stddef.h> 00026 00027 #include "stdint.hpp" 00028 00029 namespace zmq 00030 { 00031 00032 class trie_t 00033 { 00034 public: 00035 00036 trie_t (); 00037 ~trie_t (); 00038 00039 // Add key to the trie. Returns true if this is a new item in the trie 00040 // rather than a duplicate. 00041 bool add (unsigned char *prefix_, size_t size_); 00042 00043 // Remove key from the trie. Returns true if the item is actually 00044 // removed from the trie. 00045 bool rm (unsigned char *prefix_, size_t size_); 00046 00047 // Check whether particular key is in the trie. 00048 bool check (unsigned char *data_, size_t size_); 00049 00050 // Apply the function supplied to each subscription in the trie. 00051 void apply (void (*func_) (unsigned char *data_, size_t size_, 00052 void *arg_), void *arg_); 00053 00054 private: 00055 00056 void apply_helper ( 00057 unsigned char **buff_, size_t buffsize_, size_t maxbuffsize_, 00058 void (*func_) (unsigned char *data_, size_t size_, void *arg_), 00059 void *arg_); 00060 00061 uint32_t refcnt; 00062 unsigned char min; 00063 unsigned short count; 00064 union { 00065 class trie_t *node; 00066 class trie_t **table; 00067 } next; 00068 00069 trie_t (const trie_t&); 00070 const trie_t &operator = (const trie_t&); 00071 }; 00072 00073 } 00074 00075 #endif 00076