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)  {
	return make(, )
}

// 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/68261
func [ comparable,  any]( map[]) [] {
	if len() == 0 {
		return nil
	}

	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.
type BoolKeyMap[ ~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.
type BoolElementMap[ 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{}
	} else if .m != nil {
		delete(.m, )
	}
}

// Get returns the element indexed by key k.
func ( *BoolElementMap[, ]) ( )  {
	,  := .m[]
	return ()
}