gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/newCharCollectionMapCreator.go (about) 1 package corestr 2 3 import "gitlab.com/evatix-go/core/constants" 4 5 type newCharCollectionMapCreator struct{} 6 7 // CapSelfCap CharHashsetMap.eachCollectionCapacity, 8 // capacity minimum 10 will be set if lower than 10 is given. 9 // 10 // For lower than 5 use the Empty items definition. 11 func (it *newCharCollectionMapCreator) CapSelfCap( 12 capacity, selfCollectionCapacity int, 13 ) *CharCollectionMap { 14 if capacity < charCollectionDefaultCapacity { 15 capacity = charCollectionDefaultCapacity 16 } 17 18 mapElements := make(map[byte]*Collection, capacity) 19 20 if selfCollectionCapacity < charCollectionDefaultCapacity { 21 selfCollectionCapacity = charCollectionDefaultCapacity 22 } 23 24 return &CharCollectionMap{ 25 items: mapElements, 26 eachCollectionCapacity: selfCollectionCapacity, 27 } 28 } 29 30 // Empty eachCollectionCapacity = 0 31 func (it *newCharCollectionMapCreator) Empty() *CharCollectionMap { 32 mapElements := make(map[byte]*Collection, constants.Zero) 33 34 return &CharCollectionMap{ 35 items: mapElements, 36 eachCollectionCapacity: defaultEachCollectionCapacity, 37 } 38 } 39 40 func (it *newCharCollectionMapCreator) Items( 41 items []string, 42 ) *CharCollectionMap { 43 if items == nil { 44 return it.Empty() 45 } 46 47 return it.ItemsPtr( 48 &items) 49 } 50 51 func (it *newCharCollectionMapCreator) ItemsPtr( 52 items *[]string, 53 ) *CharCollectionMap { 54 if items == nil { 55 return it.Empty() 56 } 57 58 length := len(*items) 59 if length == 0 { 60 return it.Empty() 61 } 62 63 mapElements := make(map[byte]*Collection, length) 64 charCollectionMap := &CharCollectionMap{ 65 items: mapElements, 66 eachCollectionCapacity: constants.Zero, 67 } 68 69 charCollectionMap.AddStringsPtr(items) 70 71 return charCollectionMap 72 } 73 74 func (it *newCharCollectionMapCreator) ItemsPtrWithCap( 75 additionalCapacity int, 76 eachCollectionCap int, 77 items *[]string, 78 ) *CharCollectionMap { 79 isDefined := items != nil && *items != nil 80 length := 0 81 if items != nil && *items != nil { 82 length = len(*items) 83 additionalCapacity += length 84 } 85 86 mapElements := make( 87 map[byte]*Collection, 88 additionalCapacity) 89 90 charCollectionMap := &CharCollectionMap{ 91 items: mapElements, 92 eachCollectionCapacity: eachCollectionCap, 93 } 94 95 if !isDefined || length == 0 { 96 return charCollectionMap 97 } 98 99 return charCollectionMap. 100 AddStringsPtr(items) 101 }