gitee.com/quant1x/gox@v1.21.2/util/examples/hashset/hashset.go (about)

     1  // Copyright (c) 2015, Emir Pasic. 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  package main
     6  
     7  import "gitee.com/quant1x/gox/util/hashset"
     8  
     9  // HashSetExample to demonstrate basic usage of HashSet
    10  func main() {
    11  	set := hashset.New()   // empty (keys are of type int)
    12  	set.Add(1)             // 1
    13  	set.Add(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored)
    14  	set.Remove(4)          // 5, 3, 2, 1 (random order)
    15  	set.Remove(2, 3)       // 1, 5 (random order)
    16  	set.Contains(1)        // true
    17  	set.Contains(1, 5)     // true
    18  	set.Contains(1, 6)     // false
    19  	_ = set.Values()       // []int{5,1} (random order)
    20  	set.Clear()            // empty
    21  	set.Empty()            // true
    22  	set.Size()             // 0
    23  }