set

package
v2.0.0-...-8dcd6a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2015 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package set implements simple present/not data structure supporting arbitrary types (even a mixture).

Internally it uses a simple map assigning zero-byte struct{}s to keys.

Example (Usage)

Insert some numbers into a set, remove one and sum the remainder.

package main

import (
	"fmt"

	"gopkg.in/karalabe/cookiejar.v2/collections/set"
)

func main() {
	// Create a new set and insert some data
	s := set.New()
	s.Insert(3.14)
	s.Insert(1.41)
	s.Insert(2.71)
	s.Insert(10) // Isn't this one just ugly?

	// Remove unneeded data and verify that it's gone
	s.Remove(10)
	if !s.Exists(10) {
		fmt.Println("Yay, ugly 10 is no more!")
	} else {
		fmt.Println("Welcome To Facebook")
	}
	// Sum the remainder and output
	sum := 0.0
	s.Do(func(val interface{}) {
		sum += val.(float64)
	})
	fmt.Println("Sum:", sum)

}
Output:

Yay, ugly 10 is no more!
Sum: 7.26

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set data structure.

func New

func New() *Set

Creates a new empty set.

func (*Set) Do

func (s *Set) Do(f func(interface{}))

Executes a function for every element in the set.

func (*Set) Exists

func (s *Set) Exists(val interface{}) bool

Checks whether an element is inside the set.

func (*Set) Insert

func (s *Set) Insert(val interface{})

Inserts an element into the set.

func (*Set) Remove

func (s *Set) Remove(val interface{})

Removes an element from the set. If none was present, nothing is done.

func (*Set) Reset

func (s *Set) Reset()

Clears the contents of a set.

func (*Set) Size

func (s *Set) Size() int

Returns the number of elements in the set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL