FAQ
NOTE: My English is not good enough, I'm not very familiar with the CL, and
those who feel that this issue useful, please help me to follow up. THANKS
   // Init initializes or clears list l.
   func (l *List) Init() *List {
+ for l.len > 0 {
+ // l must have been initialized
+ l.remove(l.root.next) // avoid memory leaks
+ }
    l.root.next = &l.root
    l.root.prev = &l.root
    l.len = 0
    return l
   }


   // MoveBefore moves element e to its new position before mark.
   // If e or mark is not an element of l, or e == mark, the list is not
modified.
   func (l *List) MoveBefore(e, mark *Element) {
- if e.list != l || e == mark || mark.list != l {
+ if e == mark || e == mark.prev || e.list != l || mark.list != l {
return
}
l.insert(l.remove(e), mark.prev)
  }

   // MoveAfter moves element e to its new position after mark.
   // If e or mark is not an element of l, or e == mark, the list is not
modified.
   func (l *List) MoveAfter(e, mark *Element) {
- if e.list != l || e == mark || mark.list != l {
+ if e == mark || e == mark.next || e.list != l || mark.list != l {
return
}
l.insert(l.remove(e), mark)
  }


add some helper function:

// RemoveFront removes the first element of list l,
// and returns the element value e.Value or nil if l is empty.
func (l *List) RemoveFront() interface{} {
if l.len == 0 {
return nil
}
return l.remove(l.root.next).Value
}

// RemoveBack removes the last element of list l,
// and returns the element value e.Value or nil if l is empty.
func (l *List) RemoveBack() interface{} {
if l.len == 0 {
return nil
}
return l.remove(l.root.prev).Value
}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at May 12, 2014 at 3:54 pm

    On Mon, May 12, 2014 at 7:51 AM, 产学红 wrote:
    NOTE: My English is not good enough, I'm not very familiar with the CL, and
    those who feel that this issue useful, please help me to follow up. THANKS
    Thanks for the patch. The contribution process is described at
    http://golang.org/doc/contribute.html .

    In this case it's not obvious to me why this patch is helpful. You
    provided the patch but no explanation.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • 产学红 at May 13, 2014 at 4:00 am
    hi

    the changes for function MoveBefore and Moverafter is to Improve
    performance, you can run go test -bench the file in the Attachment.

    the function RemoveFront and RemoveBack are helper function.

    and changes in the function List.Init(), So far, I have not found a
    suitable way to express.
    the principle likes that in the function List.remove():

         e.next = nil // avoid memory leaks

         e.prev = nil // avoid memory leaks




    在 2014年5月12日星期一UTC+8下午11时54分27秒,Ian Lance Taylor写道:
    On Mon, May 12, 2014 at 7:51 AM, 产学红 <chanx...@gmail.com <javascript:>>
    wrote:
    NOTE: My English is not good enough, I'm not very familiar with the CL, and
    those who feel that this issue useful, please help me to follow up.
    THANKS

    Thanks for the patch. The contribution process is described at
    http://golang.org/doc/contribute.html .

    In this case it's not obvious to me why this patch is helpful. You
    provided the patch but no explanation.

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 12, '14 at 2:59p
activeMay 13, '14 at 4:00a
posts3
users2
websitegolang.org

2 users in discussion

产学红: 2 posts Ian Lance Taylor: 1 post

People

Translate

site design / logo © 2022 Grokbase