Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
de782dd1
Commit
de782dd1
authored
Sep 28, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
container/list: slightly better code factoring
R=golang-dev, adg CC=golang-dev
https://golang.org/cl/6569077
parent
0e9daef2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
src/pkg/container/list/list.go
src/pkg/container/list/list.go
+13
-9
No files found.
src/pkg/container/list/list.go
View file @
de782dd1
...
...
@@ -83,8 +83,7 @@ func (l *List) Back() *Element {
// lazyInit lazily initializes a zero List value.
func
(
l
*
List
)
lazyInit
()
{
if
l
.
root
.
next
==
nil
{
l
.
root
.
next
=
&
l
.
root
l
.
root
.
prev
=
&
l
.
root
l
.
Init
()
}
}
...
...
@@ -100,6 +99,11 @@ func (l *List) insert(e, at *Element) *Element {
return
e
}
// insertValue is a convenience wrapper for insert(&Element{Value: v}, at).
func
(
l
*
List
)
insertValue
(
v
interface
{},
at
*
Element
)
*
Element
{
return
l
.
insert
(
&
Element
{
Value
:
v
},
at
)
}
// remove removes e from its list, decrements l.len, and returns e.
func
(
l
*
List
)
remove
(
e
*
Element
)
*
Element
{
e
.
prev
.
next
=
e
.
next
...
...
@@ -123,13 +127,13 @@ func (l *List) Remove(e *Element) interface{} {
// Pushfront inserts a new element e with value v at the front of list l and returns e.
func
(
l
*
List
)
PushFront
(
v
interface
{})
*
Element
{
l
.
lazyInit
()
return
l
.
insert
(
&
Element
{
Value
:
v
}
,
&
l
.
root
)
return
l
.
insert
Value
(
v
,
&
l
.
root
)
}
// PushBack inserts a new element e with value v at the back of list l and returns e.
func
(
l
*
List
)
PushBack
(
v
interface
{})
*
Element
{
l
.
lazyInit
()
return
l
.
insert
(
&
Element
{
Value
:
v
}
,
l
.
root
.
prev
)
return
l
.
insert
Value
(
v
,
l
.
root
.
prev
)
}
// InsertBefore inserts a new element e with value v immediately before mark and returns e.
...
...
@@ -139,17 +143,17 @@ func (l *List) InsertBefore(v interface{}, mark *Element) *Element {
return
nil
}
// see comment in List.Remove about initialization of l
return
l
.
insert
(
&
Element
{
Value
:
v
}
,
mark
.
prev
)
return
l
.
insert
Value
(
v
,
mark
.
prev
)
}
// InsertAfter inserts a new element e with value v immediately after mark and returns e.
// If mark is not an element of l, the list is not modified.
func
(
l
*
List
)
InsertAfter
(
v
alue
interface
{},
mark
*
Element
)
*
Element
{
func
(
l
*
List
)
InsertAfter
(
v
interface
{},
mark
*
Element
)
*
Element
{
if
mark
.
list
!=
l
{
return
nil
}
// see comment in List.Remove about initialization of l
return
l
.
insert
(
&
Element
{
Value
:
value
}
,
mark
)
return
l
.
insert
Value
(
v
,
mark
)
}
// MoveToFront moves element e to the front of list l.
...
...
@@ -177,7 +181,7 @@ func (l *List) MoveToBack(e *Element) {
func
(
l
*
List
)
PushBackList
(
other
*
List
)
{
l
.
lazyInit
()
for
i
,
e
:=
other
.
Len
(),
other
.
Front
();
i
>
0
;
i
,
e
=
i
-
1
,
e
.
Next
()
{
l
.
insert
(
&
Element
{
Value
:
e
.
Value
}
,
l
.
root
.
prev
)
l
.
insert
Value
(
e
.
Value
,
l
.
root
.
prev
)
}
}
...
...
@@ -186,6 +190,6 @@ func (l *List) PushBackList(other *List) {
func
(
l
*
List
)
PushFrontList
(
other
*
List
)
{
l
.
lazyInit
()
for
i
,
e
:=
other
.
Len
(),
other
.
Back
();
i
>
0
;
i
,
e
=
i
-
1
,
e
.
Prev
()
{
l
.
insert
(
&
Element
{
Value
:
e
.
Value
}
,
&
l
.
root
)
l
.
insert
Value
(
e
.
Value
,
&
l
.
root
)
}
}
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