github.com/bcampbell/scrapeomat@v0.0.0-20220820232205-23e64141c89e/discover/linkset.go (about) 1 package discover 2 3 import ( 4 "errors" 5 "net/url" 6 ) 7 8 // thin map wrapper for some set operations 9 type LinkSet map[url.URL]bool 10 11 // remove and return a single item from the set 12 func (s *LinkSet) Pop() url.URL { 13 for u, _ := range *s { 14 delete(*s, u) 15 return u 16 } 17 // panic! 18 panic(errors.New("tried to Pop() on empty LinkSet")) 19 } 20 21 func (s *LinkSet) Add(link url.URL) { 22 (*s)[link] = true 23 } 24 25 func (s *LinkSet) Remove(link url.URL) { 26 delete(*s, link) 27 } 28 29 // merge the contents of other into this set 30 func (s *LinkSet) Merge(other LinkSet) { 31 for link, _ := range other { 32 (*s)[link] = true 33 } 34 }