aboutsummaryrefslogtreecommitdiff
path: root/content/maps/list.go
diff options
context:
space:
mode:
Diffstat (limited to 'content/maps/list.go')
-rw-r--r--content/maps/list.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/content/maps/list.go b/content/maps/list.go
new file mode 100644
index 0000000..02bea2c
--- /dev/null
+++ b/content/maps/list.go
@@ -0,0 +1,29 @@
+// 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.
+
+// +build OMIT
+
+package main
+
+import "fmt"
+
+func main() {
+ // START OMIT
+ type Node struct {
+ Next *Node
+ Value interface{}
+ }
+ var first *Node
+
+ visited := make(map[*Node]bool) // HL
+ for n := first; n != nil; n = n.Next {
+ if visited[n] { // HL
+ fmt.Println("cycle detected")
+ break
+ }
+ visited[n] = true // HL
+ fmt.Println(n.Value)
+ }
+ // END OMIT
+}