github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/blog/content/go-maps-in-action/list.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build OMIT 6 7 package main 8 9 import "fmt" 10 11 func main() { 12 // START OMIT 13 type Node struct { 14 Next *Node 15 Value interface{} 16 } 17 var first *Node 18 19 visited := make(map[*Node]bool) // HL 20 for n := first; n != nil; n = n.Next { 21 if visited[n] { // HL 22 fmt.Println("cycle detected") 23 break 24 } 25 visited[n] = true // HL 26 fmt.Println(n.Value) 27 } 28 // END OMIT 29 }