[go] container/ring: add ring example

80 views
Skip to first unread message

Blain Smith (Gerrit)

unread,
Jul 18, 2017, 8:45:07 AM7/18/17
to Ian Lance Taylor, golang-co...@googlegroups.com

Blain Smith has uploaded this change for review.

View Change

container/ring: add ring example

Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
---
A src/container/ring/example_test.go
1 file changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/container/ring/example_test.go b/src/container/ring/example_test.go
new file mode 100644
index 0000000..eee9135
--- /dev/null
+++ b/src/container/ring/example_test.go
@@ -0,0 +1,45 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ring_test
+
+import (
+ "container/ring"
+ "fmt"
+ "strconv"
+)
+
+func Example() {
+ // Create 2 new rings.
+ r10 := ring.New(10)
+ r5 := ring.New(5)
+
+ // Fill r10 with numbers 1 to 10
+ for i := 1; i <= r10.Len(); i++ {
+ r10.Value = i
+ r10 = r10.Next()
+ }
+
+ // Fill r5 with string numbers "Num: 11" to "Num: 15"
+ for i := 1; i <= r5.Len(); i++ {
+ r5.Value = fmt.Sprintf("Num: %s", strconv.Itoa(i+10))
+ r5 = r5.Next()
+ }
+
+ r10 = r10.Move(2) // r10 points to Value: 3
+ r5 = r5.Move(4) // r5 points to Value: "Num: 15"
+
+ // Link the 2 rings together. r5 will get appended to r10 and the
+ // new ring will point to the next position (Value: 4) of the append
+ // point.
+ r15 := r10.Link(r5) // r15 points to Value: 4
+
+ for i := 1; i <= r15.Len(); i++ {
+ fmt.Printf("%v, ", r15.Value)
+ r15 = r15.Next()
+ }
+
+ // Output:
+ // 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, Num: 15, Num: 11, Num: 12, Num: 13, Num: 14,
+}

To view, visit change 49431. To unsubscribe, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
Gerrit-Change-Number: 49431
Gerrit-PatchSet: 1
Gerrit-Owner: Blain Smith <blain...@gmail.com>

Brad Fitzpatrick (Gerrit)

unread,
Jul 18, 2017, 12:05:35 PM7/18/17
to Blain Smith, Brad Fitzpatrick, golang-co...@googlegroups.com

Brad Fitzpatrick posted comments on this change.

View Change

Patch set 1:

R=go1.10

(1 comment)

To view, visit change 49431. To unsubscribe, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
Gerrit-Change-Number: 49431
Gerrit-PatchSet: 1
Gerrit-Owner: Blain Smith <blain...@gmail.com>
Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Comment-Date: Tue, 18 Jul 2017 16:05:32 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: No

Blain Smith (Gerrit)

unread,
Jul 18, 2017, 1:21:02 PM7/18/17
to Brad Fitzpatrick, golang-co...@googlegroups.com

Blain Smith uploaded patch set #2 to this change.

View Change

container/ring: add ring example

Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
---
A src/container/ring/example_test.go
1 file changed, 45 insertions(+), 0 deletions(-)

To view, visit change 49431. To unsubscribe, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
Gerrit-Change-Number: 49431
Gerrit-PatchSet: 2

Blain Smith (Gerrit)

unread,
Jul 20, 2017, 9:55:24 PM7/20/17
to Brad Fitzpatrick, golang-co...@googlegroups.com

Blain Smith posted comments on this change.

View Change

Patch set 2:

Patch Set 1:

(1 comment)

R=go1.10

Copy and paste mistake.

    To view, visit change 49431. To unsubscribe, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-MessageType: comment
    Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
    Gerrit-Change-Number: 49431
    Gerrit-PatchSet: 2
    Gerrit-Owner: Blain Smith <blain...@gmail.com>
    Gerrit-Reviewer: Blain Smith <blain...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Fri, 21 Jul 2017 01:55:08 +0000
    Gerrit-HasComments: No
    Gerrit-HasLabels: No

    Didier Spezia (Gerrit)

    unread,
    Jul 23, 2017, 1:55:06 PM7/23/17
    to Blain Smith, Brad Fitzpatrick, golang-co...@googlegroups.com

    Didier Spezia posted comments on this change.

    View Change

    Patch set 2:Code-Review -1

    I have nothing against adding more examples, but they should not promote bad programming practices. Perhaps a better example can be found ...

    (3 comments)

    To view, visit change 49431. To unsubscribe, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-MessageType: comment
    Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
    Gerrit-Change-Number: 49431
    Gerrit-PatchSet: 2
    Gerrit-Owner: Blain Smith <blain...@gmail.com>
    Gerrit-Reviewer: Blain Smith <blain...@gmail.com>
    Gerrit-Reviewer: Didier Spezia <didi...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Sun, 23 Jul 2017 17:54:59 +0000
    Gerrit-HasComments: Yes
    Gerrit-HasLabels: Yes

    Blain Smith (Gerrit)

    unread,
    Jul 25, 2017, 11:29:13 AM7/25/17
    to Didier Spezia, Brad Fitzpatrick, golang-co...@googlegroups.com

    Blain Smith uploaded patch set #3 to this change.

    View Change

    container/ring: add ring example

    Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
    ---
    A src/container/ring/example_test.go
    1 file changed, 47 insertions(+), 0 deletions(-)

    To view, visit change 49431. To unsubscribe, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-MessageType: newpatchset
    Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
    Gerrit-Change-Number: 49431
    Gerrit-PatchSet: 3

    Blain Smith (Gerrit)

    unread,
    Jul 25, 2017, 11:30:35 AM7/25/17
    to Didier Spezia, Brad Fitzpatrick, golang-co...@googlegroups.com

    Blain Smith posted comments on this change.

    View Change

    Patch set 3:

    Patch Set 2: Code-Review-1

    (3 comments)

    I have nothing against adding more examples, but they should not promote bad programming practices. Perhaps a better example can be found ...

    Good points. I updated the patched with the same basic example, but removed .Len() usage.

      To view, visit change 49431. To unsubscribe, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-MessageType: comment
      Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
      Gerrit-Change-Number: 49431
      Gerrit-PatchSet: 3
      Gerrit-Owner: Blain Smith <blain...@gmail.com>
      Gerrit-Reviewer: Blain Smith <blain...@gmail.com>
      Gerrit-Reviewer: Didier Spezia <didi...@gmail.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Comment-Date: Tue, 25 Jul 2017 15:30:31 +0000
      Gerrit-HasComments: No
      Gerrit-HasLabels: No

      Didier Spezia (Gerrit)

      unread,
      Jul 27, 2017, 11:22:45 AM7/27/17
      to Blain Smith, Brad Fitzpatrick, golang-co...@googlegroups.com

      Didier Spezia posted comments on this change.

      View Change

      Patch set 3:Code-Review +1

      LGTM

        To view, visit change 49431. To unsubscribe, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-MessageType: comment
        Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
        Gerrit-Change-Number: 49431
        Gerrit-PatchSet: 3
        Gerrit-Owner: Blain Smith <blain...@gmail.com>
        Gerrit-Reviewer: Blain Smith <blain...@gmail.com>
        Gerrit-Reviewer: Didier Spezia <didi...@gmail.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Comment-Date: Thu, 27 Jul 2017 15:22:39 +0000
        Gerrit-HasComments: No
        Gerrit-HasLabels: Yes

        Ian Lance Taylor (Gerrit)

        unread,
        Oct 25, 2017, 9:34:53 AM10/25/17
        to Blain Smith, goph...@pubsubhelper.golang.org, Didier Spezia, Brad Fitzpatrick, golang-co...@googlegroups.com

        Ian Lance Taylor abandoned this change.

        View Change

        Abandoned We wound up going with CL 73090 instead. Thanks, though.

        To view, visit change 49431. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-MessageType: abandon
        Gerrit-Change-Id: Idd7e89f115da69853d497bf278dd24af8696a9c4
        Gerrit-Change-Number: 49431
        Reply all
        Reply to author
        Forward
        0 new messages