package nstd// ZeroMap returns a blank map which has the same type as the input map.//// * Usage 1: `ZeroMap[MapType](nil, 32)// * Usage 2: `ZeroMap(aMap, 8)func [ ~map[], comparable, any]( , int) {returnmake(, )}// CollectMapKeys collects all the keys in a map into a freshly// created result slice. The length and capacity of the result slice// are both equal to the length of the map.//// See: https://github.com/golang/go/issues/68261func [ comparable, any]( map[]) [] {iflen() == 0 {returnnil }var = make([], 0, len())for := range { = append(, ) }return}// AppendMapKeys appends all the keys in a map into the specified slice.func [ comparable, any]( [], map[]) [] {for := range { = append(, ) }return}// BoolKeyMap is an optimized version of map[K]E, where K is a bool type.typeBoolKeyMap[ ~bool, any] struct { trueE falseE }// Put puts an entry {k, e} into m.func ( *BoolKeyMap[, ]) ( , ) {if { .trueE = } else { .falseE = }}// Get returns the element indexed by key k.func ( *BoolKeyMap[, ]) ( ) {if {return .trueE } else {return .falseE }}// BoolElementMap is optimized version of map[K]E, where E is a bool type.// Entries with false element value will not be put in BoolElementMap maps.typeBoolElementMap[ comparable, ~bool] struct { m map[]blank}// Put puts an entry {k, e} into m.// Note, if e is false and the corresponding entry exists, the entry is deleted.func ( *BoolElementMap[, ]) ( , ) {if {if .m == nil { .m = make(map[]blank) } .m[] = blank{} } elseif .m != nil {delete(.m, ) }}// Get returns the element indexed by key k.func ( *BoolElementMap[, ]) ( ) { , := .m[]return ()}
The pages are generated with Goldsv0.7.3. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.