libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
mtrie.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_MTRIE_HPP_INCLUDED__
31 #define __ZMQ_MTRIE_HPP_INCLUDED__
32 
33 #include <stddef.h>
34 #include <set>
35 
36 #include "stdint.hpp"
37 
38 namespace zmq
39 {
40 
41  class pipe_t;
42 
43  // Multi-trie. Each node in the trie is a set of pointers to pipes.
44 
45  class mtrie_t
46  {
47  public:
48 
49  mtrie_t ();
50  ~mtrie_t ();
51 
52  // Add key to the trie. Returns true if it's a new subscription
53  // rather than a duplicate.
54  bool add (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
55 
56  // Remove all subscriptions for a specific peer from the trie.
57  // The call_on_uniq_ flag controls if the callback is invoked
58  // when there are no subscriptions left on some topics or on
59  // every removal.
60  void rm (zmq::pipe_t *pipe_,
61  void (*func_) (unsigned char *data_, size_t size_, void *arg_),
62  void *arg_, bool call_on_uniq_);
63 
64  // Remove specific subscription from the trie. Return true is it was
65  // actually removed rather than de-duplicated.
66  bool rm (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
67 
68  // Signal all the matching pipes.
69  void match (unsigned char *data_, size_t size_,
70  void (*func_) (zmq::pipe_t *pipe_, void *arg_), void *arg_);
71 
72  private:
73 
74  bool add_helper (unsigned char *prefix_, size_t size_,
75  zmq::pipe_t *pipe_);
76  void rm_helper (zmq::pipe_t *pipe_, unsigned char **buff_,
77  size_t buffsize_, size_t maxbuffsize_,
78  void (*func_) (unsigned char *data_, size_t size_, void *arg_),
79  void *arg_, bool call_on_uniq_);
80  bool rm_helper (unsigned char *prefix_, size_t size_,
81  zmq::pipe_t *pipe_);
82  bool is_redundant () const;
83 
84  typedef std::set <zmq::pipe_t*> pipes_t;
85  pipes_t *pipes;
86 
87  unsigned char min;
88  unsigned short count;
89  unsigned short live_nodes;
90  union {
91  class mtrie_t *node;
92  class mtrie_t **table;
93  } next;
94 
95  mtrie_t (const mtrie_t&);
96  const mtrie_t &operator = (const mtrie_t&);
97  };
98 
99 }
100 
101 #endif
102 
bool is_redundant() const
Definition: mtrie.cpp:438
void match(unsigned char *data_, size_t size_, void(*func_)(zmq::pipe_t *pipe_, void *arg_), void *arg_)
Definition: mtrie.cpp:395
pipes_t * pipes
Definition: mtrie.hpp:85
union zmq::mtrie_t::@48 next
class mtrie_t * node
Definition: mtrie.hpp:91
class mtrie_t ** table
Definition: mtrie.hpp:92
unsigned char min
Definition: mtrie.hpp:87
unsigned short live_nodes
Definition: mtrie.hpp:89
const mtrie_t & operator=(const mtrie_t &)
bool add(unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_)
Definition: mtrie.cpp:72
unsigned short count
Definition: mtrie.hpp:88
void rm_helper(zmq::pipe_t *pipe_, unsigned char **buff_, size_t buffsize_, size_t maxbuffsize_, void(*func_)(unsigned char *data_, size_t size_, void *arg_), void *arg_, bool call_on_uniq_)
Definition: mtrie.cpp:169
void rm(zmq::pipe_t *pipe_, void(*func_)(unsigned char *data_, size_t size_, void *arg_), void *arg_, bool call_on_uniq_)
Definition: mtrie.cpp:160
Definition: address.hpp:35
bool add_helper(unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_)
Definition: mtrie.cpp:77
std::set< zmq::pipe_t * > pipes_t
Definition: mtrie.hpp:84