Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
0ee18ca8
Commit
0ee18ca8
authored
Sep 16, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add heap.Remove
R=gri DELTA=14 (14 added, 0 deleted, 0 changed) OCL=34636 CL=34687
parent
1bbc044d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
0 deletions
+14
-0
heap.go
src/pkg/container/heap/heap.go
+14
-0
No files found.
src/pkg/container/heap/heap.go
View file @
0ee18ca8
...
@@ -52,6 +52,20 @@ func Pop(h HeapInterface) interface{} {
...
@@ -52,6 +52,20 @@ func Pop(h HeapInterface) interface{} {
}
}
// Remove removes the element at index i from the heap.
// The complexity is O(log(n)) where n = h.Len().
//
func
Remove
(
h
HeapInterface
,
i
int
)
interface
{}
{
n
:=
h
.
Len
()
-
1
;
if
n
!=
i
{
h
.
Swap
(
n
,
i
);
down
(
h
,
i
,
n
);
up
(
h
,
i
);
}
return
h
.
Pop
();
}
func
up
(
h
HeapInterface
,
j
int
)
{
func
up
(
h
HeapInterface
,
j
int
)
{
for
{
for
{
i
:=
(
j
-
1
)
/
2
;
i
:=
(
j
-
1
)
/
2
;
...
...
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