Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
71623b67
Commit
71623b67
authored
Aug 18, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize pq
parent
6a511aef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
17 deletions
+26
-17
lib/nghttp2_pq.c
lib/nghttp2_pq.c
+26
-17
No files found.
lib/nghttp2_pq.c
View file @
71623b67
...
...
@@ -52,14 +52,14 @@ static void swap(nghttp2_pq *pq, size_t i, size_t j) {
}
static
void
bubble_up
(
nghttp2_pq
*
pq
,
size_t
index
)
{
if
(
index
==
0
)
{
size_t
parent
;
while
(
index
!=
0
)
{
parent
=
(
index
-
1
)
/
2
;
if
(
!
pq
->
less
(
pq
->
q
[
index
],
pq
->
q
[
parent
]))
{
return
;
}
else
{
size_t
parent
=
(
index
-
1
)
/
2
;
if
(
pq
->
less
(
pq
->
q
[
index
],
pq
->
q
[
parent
]))
{
swap
(
pq
,
parent
,
index
);
bubble_up
(
pq
,
parent
);
}
swap
(
pq
,
parent
,
index
);
index
=
parent
;
}
}
...
...
@@ -94,8 +94,10 @@ nghttp2_pq_entry *nghttp2_pq_top(nghttp2_pq *pq) {
}
static
void
bubble_down
(
nghttp2_pq
*
pq
,
size_t
index
)
{
size_t
i
,
j
=
index
*
2
+
1
;
size_t
minindex
=
index
;
size_t
i
,
j
,
minindex
;
for
(;;)
{
j
=
index
*
2
+
1
;
minindex
=
index
;
for
(
i
=
0
;
i
<
2
;
++
i
,
++
j
)
{
if
(
j
>=
pq
->
length
)
{
break
;
...
...
@@ -104,9 +106,11 @@ static void bubble_down(nghttp2_pq *pq, size_t index) {
minindex
=
j
;
}
}
if
(
minindex
!=
index
)
{
if
(
minindex
==
index
)
{
return
;
}
swap
(
pq
,
index
,
minindex
);
bubble_down
(
pq
,
minindex
)
;
index
=
minindex
;
}
}
...
...
@@ -122,6 +126,11 @@ void nghttp2_pq_pop(nghttp2_pq *pq) {
void
nghttp2_pq_remove
(
nghttp2_pq
*
pq
,
nghttp2_pq_entry
*
item
)
{
assert
(
pq
->
q
[
item
->
index
]
==
item
);
if
(
item
->
index
==
0
)
{
nghttp2_pq_pop
(
pq
);
return
;
}
if
(
item
->
index
==
pq
->
length
-
1
)
{
--
pq
->
length
;
return
;
...
...
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