mirror of
https://github.com/emirpasic/gods
synced 2024-11-08 13:10:26 +00:00
24 lines
815 B
Go
24 lines
815 B
Go
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package examples
|
|
|
|
import "github.com/emirpasic/gods/sets/hashset"
|
|
|
|
// HashSetExample to demonstrate basic usage of HashSet
|
|
func HashSetExample() {
|
|
set := hashset.New() // empty (keys are of type int)
|
|
set.Add(1) // 1
|
|
set.Add(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored)
|
|
set.Remove(4) // 5, 3, 2, 1 (random order)
|
|
set.Remove(2, 3) // 1, 5 (random order)
|
|
set.Contains(1) // true
|
|
set.Contains(1, 5) // true
|
|
set.Contains(1, 6) // false
|
|
_ = set.Values() // []int{5,1} (random order)
|
|
set.Clear() // empty
|
|
set.Empty() // true
|
|
set.Size() // 0
|
|
}
|