setmap

package module
v0.0.0-...-c1a8801 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 0 Imported by: 1

README

SetMap

A "set map" struct implemented by Golang. Just a practice for Golang generic.

What is "set map"?

map<K, set<V>>

How am I implement it?

type SetMap[K, V comparable] struct {
	m map[K]map[V]struct{}
}

How to use?

run setmap_test.go and you would see.

SetMapaMteS

A "set map" struct implemented by Golang, but can also get a list of key by the value.

How am I implement it?

type SetMapaMteS[K, V comparable] struct {
    SetMap[K, V]
    reverse SetMap[V, K]
}

How to use?

run setmap_test.go and you would see.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HalfIfaceSetMap

type HalfIfaceSetMap[K, V comparable] struct {
	IfaceSetMap[K, V]
}

HalfIfaceSetMap is map<K, set<V>>

func NewHalfIfaceSetMap

func NewHalfIfaceSetMap[K, V comparable]() HalfIfaceSetMap[K, V]

func (HalfIfaceSetMap[K, V]) Add

func (m HalfIfaceSetMap[K, V]) Add(key K, value IfaceSetMapItem[V])

Add a value to the set whose ID is key

func (HalfIfaceSetMap[K, V]) Exists

func (m HalfIfaceSetMap[K, V]) Exists(key K, value IfaceSetMapItem[V]) bool

Exists show if a value is in the set whose ID is key

func (HalfIfaceSetMap[K, V]) GetSet

func (m HalfIfaceSetMap[K, V]) GetSet(key K) []IfaceSetMapItem[V]

GetSet get all the values from the set whose ID is key

func (HalfIfaceSetMap[K, V]) Remove

func (m HalfIfaceSetMap[K, V]) Remove(key K, value IfaceSetMapItem[V])

Remove a value from the set whose ID is key

type HalfIfaceSetMapaMteS

type HalfIfaceSetMapaMteS[K, V comparable] struct {
	IfaceSetMapaMteS[K, V]
}

HalfIfaceSetMapaMteS consists of a IfaceSetMap map<K, set<V>> and a reverse IfaceSetMap map<V, set<K>> so it can show K和V之间的多对多关系

func NewHalfIfaceSetMapaMteS

func NewHalfIfaceSetMapaMteS[K, V comparable]() HalfIfaceSetMapaMteS[K, V]

func (HalfIfaceSetMapaMteS[K, V]) Add

func (m HalfIfaceSetMapaMteS[K, V]) Add(key K, value IfaceSetMapItem[V])

func (HalfIfaceSetMapaMteS[K, V]) Exists

func (m HalfIfaceSetMapaMteS[K, V]) Exists(key K, value IfaceSetMapItem[V]) bool

Exists show if a value is in the set whose ID is key

func (HalfIfaceSetMapaMteS[K, V]) GetKeys

func (m HalfIfaceSetMapaMteS[K, V]) GetKeys(value IfaceSetMapItem[V]) []IfaceSetMapItem[K]

func (HalfIfaceSetMapaMteS[K, V]) GetSet

func (m HalfIfaceSetMapaMteS[K, V]) GetSet(key K) []IfaceSetMapItem[V]

GetSet get all the values from the set whose ID is key

func (HalfIfaceSetMapaMteS[K, V]) GetUniqueKeys

func (m HalfIfaceSetMapaMteS[K, V]) GetUniqueKeys(value IfaceSetMapItem[V]) []K

GetUniqueKeys only get the value's keys that is not other value's key

func (HalfIfaceSetMapaMteS[K, V]) GetUniqueValues

func (m HalfIfaceSetMapaMteS[K, V]) GetUniqueValues(key K) []IfaceSetMapItem[V]

GetUniqueValues only get the key's values that is not exists in other key's set

func (HalfIfaceSetMapaMteS[K, V]) Remove

func (m HalfIfaceSetMapaMteS[K, V]) Remove(key K, value IfaceSetMapItem[V])

func (HalfIfaceSetMapaMteS[K, V]) RemoveKey

func (m HalfIfaceSetMapaMteS[K, V]) RemoveKey(key K)

func (HalfIfaceSetMapaMteS[K, V]) RemoveValue

func (m HalfIfaceSetMapaMteS[K, V]) RemoveValue(value IfaceSetMapItem[V])

type IfaceSetMap

type IfaceSetMap[K, V comparable] struct {
	// contains filtered or unexported fields
}

IfaceSetMap is map<K, set<V>>

func NewIfaceSetMap

func NewIfaceSetMap[K, V comparable]() IfaceSetMap[K, V]

func (IfaceSetMap[K, V]) Add

func (m IfaceSetMap[K, V]) Add(key IfaceSetMapItem[K], value IfaceSetMapItem[V])

Add a value to the set whose ID is key

func (IfaceSetMap[K, V]) Exists

func (m IfaceSetMap[K, V]) Exists(key IfaceSetMapItem[K], value IfaceSetMapItem[V]) bool

Exists show if a value is in the set whose ID is key

func (IfaceSetMap[K, V]) GetSet

func (m IfaceSetMap[K, V]) GetSet(key IfaceSetMapItem[K]) []IfaceSetMapItem[V]

GetSet get all the values from the set whose ID is key

func (IfaceSetMap[K, V]) Remove

func (m IfaceSetMap[K, V]) Remove(key IfaceSetMapItem[K], value IfaceSetMapItem[V])

Remove a value from the set whose ID is key

type IfaceSetMapItem

type IfaceSetMapItem[T comparable] interface {
	ID() T
}

type IfaceSetMapaMteS

type IfaceSetMapaMteS[K, V comparable] struct {
	IfaceSetMap[K, V]
	// contains filtered or unexported fields
}

IfaceSetMapaMteS consists of a IfaceSetMap map<K, set<V>> and a reverse IfaceSetMap map<V, set<K>> so it can show K和V之间的多对多关系

func NewIfaceSetMapaMteS

func NewIfaceSetMapaMteS[K, V comparable]() IfaceSetMapaMteS[K, V]

func (IfaceSetMapaMteS[K, V]) Add

func (m IfaceSetMapaMteS[K, V]) Add(key IfaceSetMapItem[K], value IfaceSetMapItem[V])

func (IfaceSetMapaMteS[K, V]) GetKeys

func (m IfaceSetMapaMteS[K, V]) GetKeys(value IfaceSetMapItem[V]) []IfaceSetMapItem[K]

func (IfaceSetMapaMteS[K, V]) GetUniqueKeys

func (m IfaceSetMapaMteS[K, V]) GetUniqueKeys(value IfaceSetMapItem[V]) []IfaceSetMapItem[K]

GetUniqueKeys only get the value's keys that is not other value's key

func (IfaceSetMapaMteS[K, V]) GetUniqueValues

func (m IfaceSetMapaMteS[K, V]) GetUniqueValues(key IfaceSetMapItem[K]) []IfaceSetMapItem[V]

GetUniqueValues only get the key's values that is not exists in other key's set

func (IfaceSetMapaMteS[K, V]) Remove

func (m IfaceSetMapaMteS[K, V]) Remove(key IfaceSetMapItem[K], value IfaceSetMapItem[V])

func (IfaceSetMapaMteS[K, V]) RemoveKey

func (m IfaceSetMapaMteS[K, V]) RemoveKey(key IfaceSetMapItem[K])

func (IfaceSetMapaMteS[K, V]) RemoveValue

func (m IfaceSetMapaMteS[K, V]) RemoveValue(value IfaceSetMapItem[V])

type SetMap

type SetMap[K, V comparable] struct {
	// contains filtered or unexported fields
}

SetMap is map<K, set<V>>

func NewSetMap

func NewSetMap[K, V comparable]() SetMap[K, V]

func (SetMap[K, V]) Add

func (m SetMap[K, V]) Add(key K, value V)

Add a value to the set whose ID is key

func (SetMap[K, V]) Exists

func (m SetMap[K, V]) Exists(key K, value V) bool

Exists show if a value is in the set whose ID is key

func (SetMap[K, V]) GetSet

func (m SetMap[K, V]) GetSet(key K) []V

GetSet get all the values from the set whose ID is key

func (SetMap[K, V]) Remove

func (m SetMap[K, V]) Remove(key K, value V)

Remove a value from the set whose ID is key

type SetMapaMteS

type SetMapaMteS[K, V comparable] struct {
	SetMap[K, V]
	// contains filtered or unexported fields
}

SetMapaMteS consists of a SetMap map<K, set<V>> and a reverse SetMap map<V, set<K>> so it can show K和V之间的多对多关系

func NewSetMapaMteS

func NewSetMapaMteS[K, V comparable]() SetMapaMteS[K, V]

func (SetMapaMteS[K, V]) Add

func (m SetMapaMteS[K, V]) Add(key K, value V)

func (SetMapaMteS[K, V]) GetKeys

func (m SetMapaMteS[K, V]) GetKeys(value V) []K

func (SetMapaMteS[K, V]) GetUniqueKeys

func (m SetMapaMteS[K, V]) GetUniqueKeys(value V) []K

GetUniqueKeys only get the value's keys that is not other value's key

func (SetMapaMteS[K, V]) GetUniqueValues

func (m SetMapaMteS[K, V]) GetUniqueValues(key K) []V

GetUniqueValues only get the key's values that is not exists in other key's set

func (SetMapaMteS[K, V]) Remove

func (m SetMapaMteS[K, V]) Remove(key K, value V)

func (SetMapaMteS[K, V]) RemoveKey

func (m SetMapaMteS[K, V]) RemoveKey(key K)

func (SetMapaMteS[K, V]) RemoveValue

func (m SetMapaMteS[K, V]) RemoveValue(value V)

type SimpleIfaceSetMapItem

type SimpleIfaceSetMapItem[T comparable] struct {
	T T
}

func (SimpleIfaceSetMapItem[T]) ID

func (s SimpleIfaceSetMapItem[T]) ID() T

Jump to

Keyboard shortcuts

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