stringset

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 3 Imported by: 3

README

StringSet

StringSet is a string cache used for storing a key up to once. This utility is useful when managing set-lists for unique keys.

Note: SortedSet has been removed. If you want this functionality, please check out https://github.com/gdbu/bst

Usage

New
func ExampleNew() {
	// Initialize new stringset
	testKeys = New()
}
StringSet.Set
func ExampleStringSet_Set() {
	// Set foo key
	testKeys.Set("foo")
	// Set bar key
	testKeys.Set("bar")
}
StringSet.Unset
func ExampleStringSet_Unset() {
	// Remove bar key
	testKeys.Unset("bar")
}
StringSet.Has
func ExampleStringSet_Has() {
	if testKeys.Has("foo") {
		fmt.Println("We have foo!")
	}

	if !testKeys.Has("bar") {
		fmt.Println("We do not have bar!")
	}
}
StringSet.Slice
func ExampleStringSet_Slice() {
	keys := testKeys.Slice()
	for _, key := range keys {
		fmt.Printf("Iterating key: %s\n", key)
	}
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Async added in v0.1.8

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

Async is a thread-safe wrapper for the stringset.Map

func NewAsyncMap added in v0.1.8

func NewAsyncMap(keys ...string) *Async

NewAsyncMap will create a new Map instance of Async

Example
// Initialize new stringset
testKeys = NewAsyncMap()

func (*Async) Has added in v0.1.8

func (a *Async) Has(key string) (has bool)

Has will return whether or not a key exists

Example
if testKeys.Has("foo") {
	fmt.Println("We have foo!")
}

if !testKeys.Has("bar") {
	fmt.Println("We do not have bar!")
}

func (*Async) HasAll added in v0.1.8

func (a *Async) HasAll(keys []string) (has bool)

HasAll will return whether or not all the provided keys exist

func (*Async) HasOne added in v0.1.8

func (a *Async) HasOne(keys []string) (has bool)

HasOne will return whether or not at least one of the provided keys exist

func (*Async) IsMatch added in v0.1.8

func (a *Async) IsMatch(in StringSet) (isMatch bool)

IsMatch will return whether or not two Asyncs are an identical match

func (*Async) Len added in v0.1.8

func (a *Async) Len() int

Len will return the length of the string set

func (*Async) MarshalJSON added in v0.1.8

func (a *Async) MarshalJSON() (bs []byte, err error)

MarshalJSON is a JSON encoding helper func

func (*Async) Set added in v0.1.8

func (a *Async) Set(key string)

Set will insert a single key

Example
// Set foo key
testKeys.Set("foo")
// Set bar key
testKeys.Set("bar")

func (*Async) SetAsString added in v0.1.8

func (a *Async) SetAsString(value string) (err error)

SetMany will insert multiple keys

func (*Async) SetMany added in v0.1.8

func (a *Async) SetMany(keys []string)

SetMany will insert multiple keys

func (*Async) Slice added in v0.1.8

func (a *Async) Slice() (keys []string)

Slice will return the keys as a slice

Example
keys := testKeys.Slice()
for _, key := range keys {
	fmt.Printf("Iterating key: %s\n", key)
}

func (*Async) UnmarshalJSON added in v0.1.8

func (a *Async) UnmarshalJSON(bs []byte) (err error)

UnmarshalJSON is a JSON decoding helper func

func (*Async) Unset added in v0.1.8

func (a *Async) Unset(key string)

Unset will remove a key

Example
// Remove bar key
testKeys.Unset("bar")

func (*Async) UnsetMany added in v0.1.8

func (a *Async) UnsetMany(keys []string)

UnsetMany will remove multiple keys

type Map

type Map map[string]struct{}

Map is the lower-level underlying type for storing a string set Note: This is not thread-safe. If you need thread-safety, please use StringSet type

func MakeMap

func MakeMap(keys ...string) (m Map)

MakeMap will initialize a new map

func (Map) Has

func (m Map) Has(key string) (has bool)

Has will return whether or not a key exists

func (Map) HasAll

func (m Map) HasAll(keys []string) (has bool)

HasAll will return whether or not all the provided keys exist

func (Map) HasOne

func (m Map) HasOne(keys []string) (has bool)

HasOne will return whether or not at least one of the provided keys exist

func (Map) IsMatch added in v0.1.5

func (m Map) IsMatch(in StringSet) (isMatch bool)

IsMatch will return whether or not two Maps are an identical match

func (Map) Len added in v0.1.8

func (m Map) Len() (n int)

Len will return the length of the map

func (Map) MarshalJSON

func (m Map) MarshalJSON() (bs []byte, err error)

MarshalJSON is a JSON encoding helper func

func (*Map) Set

func (m *Map) Set(key string)

Set will place a key

func (*Map) SetAsString added in v0.1.7

func (m *Map) SetAsString(value string) (err error)

SetAsString will set a map from a comma separated string value Note: This allows stringset to match the reflectio.Setter interface

func (*Map) SetMany

func (m *Map) SetMany(keys []string)

SetMany will place multiple keys

func (Map) Slice

func (m Map) Slice() (keys []string)

Slice will return the keys as a slice

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(bs []byte) (err error)

UnmarshalJSON is a JSON decoding helper func

func (Map) Unset

func (m Map) Unset(key string)

Unset will remove a key

func (Map) UnsetMany

func (m Map) UnsetMany(keys []string)

UnsetMany will remove multiple keys

type StringSet

type StringSet interface {
	Set(key string)
	SetMany(keys []string)
	Unset(key string)
	UnsetMany(keys []string)
	Has(key string) (has bool)
	HasAll(keys []string) (has bool)
	HasOne(keys []string) (has bool)
	Slice() (keys []string)
	IsMatch(in StringSet) (isMatch bool)
	SetAsString(value string) (err error)
	Len() (n int)
}

Jump to

Keyboard shortcuts

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