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
Hide 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) {
...
@@ -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
)
{
static
void
bubble_up
(
nghttp2_pq
*
pq
,
size_t
index
)
{
if
(
index
==
0
)
{
size_t
parent
;
return
;
while
(
index
!=
0
)
{
}
else
{
parent
=
(
index
-
1
)
/
2
;
size_t
parent
=
(
index
-
1
)
/
2
;
if
(
!
pq
->
less
(
pq
->
q
[
index
],
pq
->
q
[
parent
]))
{
if
(
pq
->
less
(
pq
->
q
[
index
],
pq
->
q
[
parent
]))
{
return
;
swap
(
pq
,
parent
,
index
);
bubble_up
(
pq
,
parent
);
}
}
swap
(
pq
,
parent
,
index
);
index
=
parent
;
}
}
}
}
...
@@ -94,19 +94,23 @@ nghttp2_pq_entry *nghttp2_pq_top(nghttp2_pq *pq) {
...
@@ -94,19 +94,23 @@ nghttp2_pq_entry *nghttp2_pq_top(nghttp2_pq *pq) {
}
}
static
void
bubble_down
(
nghttp2_pq
*
pq
,
size_t
index
)
{
static
void
bubble_down
(
nghttp2_pq
*
pq
,
size_t
index
)
{
size_t
i
,
j
=
index
*
2
+
1
;
size_t
i
,
j
,
minindex
;
size_t
minindex
=
index
;
for
(;;)
{
for
(
i
=
0
;
i
<
2
;
++
i
,
++
j
)
{
j
=
index
*
2
+
1
;
if
(
j
>=
pq
->
length
)
{
minindex
=
index
;
break
;
for
(
i
=
0
;
i
<
2
;
++
i
,
++
j
)
{
if
(
j
>=
pq
->
length
)
{
break
;
}
if
(
pq
->
less
(
pq
->
q
[
j
],
pq
->
q
[
minindex
]))
{
minindex
=
j
;
}
}
}
if
(
pq
->
less
(
pq
->
q
[
j
],
pq
->
q
[
minindex
])
)
{
if
(
minindex
==
index
)
{
minindex
=
j
;
return
;
}
}
}
if
(
minindex
!=
index
)
{
swap
(
pq
,
index
,
minindex
);
swap
(
pq
,
index
,
minindex
);
bubble_down
(
pq
,
minindex
)
;
index
=
minindex
;
}
}
}
}
...
@@ -122,6 +126,11 @@ void nghttp2_pq_pop(nghttp2_pq *pq) {
...
@@ -122,6 +126,11 @@ void nghttp2_pq_pop(nghttp2_pq *pq) {
void
nghttp2_pq_remove
(
nghttp2_pq
*
pq
,
nghttp2_pq_entry
*
item
)
{
void
nghttp2_pq_remove
(
nghttp2_pq
*
pq
,
nghttp2_pq_entry
*
item
)
{
assert
(
pq
->
q
[
item
->
index
]
==
item
);
assert
(
pq
->
q
[
item
->
index
]
==
item
);
if
(
item
->
index
==
0
)
{
nghttp2_pq_pop
(
pq
);
return
;
}
if
(
item
->
index
==
pq
->
length
-
1
)
{
if
(
item
->
index
==
pq
->
length
-
1
)
{
--
pq
->
length
;
--
pq
->
length
;
return
;
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