github.com/mymmsc/gox@v1.3.33/util/examples/treeset/treeset.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 "github.com/mymmsc/gox/util/treeset"
     8  
     9  // TreeSetExample to demonstrate basic usage of TreeSet
    10  func main() {
    11  	set := treeset.NewWithIntComparator() // empty
    12  	set.Add(1)                            // 1
    13  	set.Add(2, 2, 3, 4, 5)                // 1, 2, 3, 4, 5 (in order, duplicates ignored)
    14  	set.Remove(4)                         // 1, 2, 3, 5 (in order)
    15  	set.Remove(2, 3)                      // 1, 5 (in order)
    16  	set.Contains(1)                       // true
    17  	set.Contains(1, 5)                    // true
    18  	set.Contains(1, 6)                    // false
    19  	_ = set.Values()                      // []int{1,5} (in order)
    20  	set.Clear()                           // empty
    21  	set.Empty()                           // true
    22  	set.Size()                            // 0
    23  }