gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/newCharHashsetMapCreator.go (about)

     1  package corestr
     2  
     3  import (
     4  	"gitlab.com/evatix-go/core/constants"
     5  )
     6  
     7  type newCharHashsetMapCreator struct{}
     8  
     9  // Cap
    10  //
    11  // CharHashsetMap.eachHashsetCapacity,
    12  // capacity minimum 10 will be set if lower than 10 is given.
    13  //
    14  // For lower than 5 use the Empty hashset definition.
    15  func (it *newCharHashsetMapCreator) Cap(
    16  	capacity, selfHashsetCapacity int,
    17  ) *CharHashsetMap {
    18  	const limit = constants.ArbitraryCapacity10
    19  
    20  	if capacity < limit {
    21  		capacity = limit
    22  	}
    23  
    24  	mapElements := make(
    25  		map[byte]*Hashset,
    26  		capacity)
    27  
    28  	if selfHashsetCapacity < limit {
    29  		selfHashsetCapacity = limit
    30  	}
    31  
    32  	return &CharHashsetMap{
    33  		items:               mapElements,
    34  		eachHashsetCapacity: selfHashsetCapacity,
    35  	}
    36  }
    37  
    38  func (it *newCharHashsetMapCreator) CapItemsPtr(
    39  	capacity, selfHashsetCapacity int,
    40  	items *[]string,
    41  ) *CharHashsetMap {
    42  	charHashsetMap := it.Cap(
    43  		capacity, selfHashsetCapacity)
    44  
    45  	return charHashsetMap.AddStringsPtr(items)
    46  }
    47  
    48  func (it *newCharHashsetMapCreator) CapItems(
    49  	capacity, selfHashsetCapacity int,
    50  	items []string,
    51  ) *CharHashsetMap {
    52  	charHashsetMap := it.Cap(
    53  		capacity, selfHashsetCapacity)
    54  
    55  	return charHashsetMap.AddStrings(items...)
    56  }
    57  
    58  func (it *newCharHashsetMapCreator) Strings(
    59  	selfHashsetCapacity int,
    60  	items []string,
    61  ) *CharHashsetMap {
    62  	if items == nil {
    63  		return it.Cap(
    64  			constants.ArbitraryCapacity5,
    65  			selfHashsetCapacity)
    66  	}
    67  
    68  	length := len(items)
    69  	charHashsetMap := it.Cap(
    70  		length,
    71  		selfHashsetCapacity)
    72  
    73  	charHashsetMap.AddStrings(items...)
    74  
    75  	return charHashsetMap
    76  }
    77  
    78  func (it *newCharHashsetMapCreator) StringsPtr(
    79  	selfHashsetCapacity int,
    80  	items *[]string,
    81  ) *CharHashsetMap {
    82  	if items == nil {
    83  		return it.Cap(
    84  			constants.ArbitraryCapacity5,
    85  			selfHashsetCapacity)
    86  	}
    87  
    88  	length := len(*items)
    89  	charHashsetMap := it.Cap(
    90  		length,
    91  		selfHashsetCapacity)
    92  
    93  	return charHashsetMap.AddStringsPtr(items)
    94  }