MCPcopy
hub / github.com/MetaCubeX/mihomo / New

Function New

common/orderedmap/orderedmap.go:54–78  ·  view source on GitHub ↗

New creates a new OrderedMap. options can either be one or several InitOption[K, V], or a single integer, which is then interpreted as a capacity hint, à la make(map[K]V, capacity).

(options ...any)

Source from the content-addressed store, hash-verified

52// options can either be one or several InitOption[K, V], or a single integer,
53// which is then interpreted as a capacity hint, à la make(map[K]V, capacity).
54func New[K comparable, V any](options ...any) *OrderedMap[K, V] { //nolint:varnamelen
55 orderedMap := &OrderedMap[K, V]{}
56
57 var config initConfig[K, V]
58 for _, untypedOption := range options {
59 switch option := untypedOption.(type) {
60 case int:
61 if len(options) != 1 {
62 invalidOption()
63 }
64 config.capacity = option
65
66 case InitOption[K, V]:
67 option(&config)
68
69 default:
70 invalidOption()
71 }
72 }
73
74 orderedMap.initialize(config.capacity)
75 orderedMap.AddPairs(config.initialData...)
76
77 return orderedMap
78}
79
80const invalidOptionMessage = `when using orderedmap.New[K,V]() with options, either provide one or several InitOption[K, V]; or a single integer which is then interpreted as a capacity hint, à la make(map[K]V, capacity).` //nolint:lll
81

Callers 15

TestMarshalYAMLFunction · 0.70
TestUnmarshallYAMLFunction · 0.70
BenchmarkMarshalYAMLFunction · 0.70
TestMarshalJSONFunction · 0.70
TestUnmarshallJSONFunction · 0.70
BenchmarkMarshalJSONFunction · 0.70
TestBasicFeaturesFunction · 0.70
TestEmptyMapOperationsFunction · 0.70

Calls 4

invalidOptionFunction · 0.85
initializeMethod · 0.80
AddPairsMethod · 0.80
optionStruct · 0.50

Tested by 15

TestMarshalYAMLFunction · 0.56
TestUnmarshallYAMLFunction · 0.56
BenchmarkMarshalYAMLFunction · 0.56
TestMarshalJSONFunction · 0.56
TestUnmarshallJSONFunction · 0.56
BenchmarkMarshalJSONFunction · 0.56
TestBasicFeaturesFunction · 0.56
TestEmptyMapOperationsFunction · 0.56