Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
6fa9ffeb
Commit
6fa9ffeb
authored
Jan 03, 2012
by
Staffan Gimåker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prune redundant nodes in the mtrie.
Signed-off-by:
Staffan Gimåker
<
staffan@spotify.com
>
parent
6f32361f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
mtrie.cpp
src/mtrie.cpp
+32
-3
mtrie.hpp
src/mtrie.hpp
+3
-0
No files found.
src/mtrie.cpp
View file @
6fa9ffeb
/*
Copyright (c) 2011 250bpm s.r.o.
Copyright (c) 2011-2012 Spotify AB
Copyright (c) 2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
...
...
@@ -34,7 +35,8 @@
zmq
::
mtrie_t
::
mtrie_t
()
:
min
(
0
),
count
(
0
)
count
(
0
),
live_nodes
(
0
)
{
}
...
...
@@ -118,6 +120,7 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
if
(
count
==
1
)
{
if
(
!
next
.
node
)
{
next
.
node
=
new
(
std
::
nothrow
)
mtrie_t
;
++
live_nodes
;
zmq_assert
(
next
.
node
);
}
return
next
.
node
->
add_helper
(
prefix_
+
1
,
size_
-
1
,
pipe_
);
...
...
@@ -125,6 +128,7 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
else
{
if
(
!
next
.
table
[
c
-
min
])
{
next
.
table
[
c
-
min
]
=
new
(
std
::
nothrow
)
mtrie_t
;
++
live_nodes
;
zmq_assert
(
next
.
table
[
c
-
min
]);
}
return
next
.
table
[
c
-
min
]
->
add_helper
(
prefix_
+
1
,
size_
-
1
,
pipe_
);
...
...
@@ -167,6 +171,11 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
buffsize_
++
;
next
.
node
->
rm_helper
(
pipe_
,
buff_
,
buffsize_
,
maxbuffsize_
,
func_
,
arg_
);
if
(
next
.
node
->
is_redundant
())
{
delete
next
.
node
;
next
.
node
=
0
;
--
live_nodes
;
}
return
;
}
...
...
@@ -176,7 +185,12 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
if
(
next
.
table
[
c
])
next
.
table
[
c
]
->
rm_helper
(
pipe_
,
buff_
,
buffsize_
+
1
,
maxbuffsize_
,
func_
,
arg_
);
}
if
(
next
.
table
[
c
]
->
is_redundant
())
{
delete
next
.
table
[
c
];
next
.
table
[
c
]
=
0
;
--
live_nodes
;
}
}
}
bool
zmq
::
mtrie_t
::
rm
(
unsigned
char
*
prefix_
,
size_t
size_
,
pipe_t
*
pipe_
)
...
...
@@ -203,7 +217,18 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
if
(
!
next_node
)
return
false
;
return
next_node
->
rm_helper
(
prefix_
+
1
,
size_
-
1
,
pipe_
);
bool
ret
=
next_node
->
rm_helper
(
prefix_
+
1
,
size_
-
1
,
pipe_
);
if
(
next_node
->
is_redundant
())
{
delete
next_node
;
if
(
count
==
1
)
next
.
node
=
0
;
else
next
.
table
[
c
-
min
]
=
0
;
--
live_nodes
;
}
return
ret
;
}
void
zmq
::
mtrie_t
::
match
(
unsigned
char
*
data_
,
size_t
size_
,
...
...
@@ -247,3 +272,7 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
}
}
bool
zmq
::
mtrie_t
::
is_redundant
()
const
{
return
pipes
.
empty
()
&&
live_nodes
==
0
;
}
src/mtrie.hpp
View file @
6fa9ffeb
/*
Copyright (c) 2011 250bpm s.r.o.
Copyright (c) 2011-2012 Spotify AB
Copyright (c) 2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
...
...
@@ -69,12 +70,14 @@ namespace zmq
void
*
arg_
);
bool
rm_helper
(
unsigned
char
*
prefix_
,
size_t
size_
,
zmq
::
pipe_t
*
pipe_
);
bool
is_redundant
()
const
;
typedef
std
::
set
<
zmq
::
pipe_t
*>
pipes_t
;
pipes_t
pipes
;
unsigned
char
min
;
unsigned
short
count
;
unsigned
short
live_nodes
;
union
{
class
mtrie_t
*
node
;
class
mtrie_t
**
table
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment