1 // Copyright 2015 go-swagger maintainers
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
24 // indexOfInitialisms is a thread-safe implementation of the sorted index of initialisms.
25 // Before go1.9, this may be implemented with a mutex on the map.
26 type indexOfInitialisms struct {
31 func newIndexOfInitialisms() *indexOfInitialisms {
32 return &indexOfInitialisms{
33 getMutex: new(sync.Mutex),
34 index: make(map[string]bool, 50),
38 func (m *indexOfInitialisms) load(initial map[string]bool) *indexOfInitialisms {
40 defer m.getMutex.Unlock()
41 for k, v := range initial {
47 func (m *indexOfInitialisms) isInitialism(key string) bool {
49 defer m.getMutex.Unlock()
54 func (m *indexOfInitialisms) add(key string) *indexOfInitialisms {
56 defer m.getMutex.Unlock()
61 func (m *indexOfInitialisms) sorted() (result []string) {
63 defer m.getMutex.Unlock()
64 for k := range m.index {
65 result = append(result, k)
67 sort.Sort(sort.Reverse(byInitialism(result)))