podman

Форк
0
70 строк · 1.7 Кб
1
// Copyright 2015 go-swagger maintainers
2
//
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
6
//
7
//    http://www.apache.org/licenses/LICENSE-2.0
8
//
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.
14

15
//go:build !go1.9
16
// +build !go1.9
17

18
package swag
19

20
import (
21
	"sort"
22
	"sync"
23
)
24

25
// indexOfInitialisms is a thread-safe implementation of the sorted index of initialisms.
26
// Before go1.9, this may be implemented with a mutex on the map.
27
type indexOfInitialisms struct {
28
	getMutex *sync.Mutex
29
	index    map[string]bool
30
}
31

32
func newIndexOfInitialisms() *indexOfInitialisms {
33
	return &indexOfInitialisms{
34
		getMutex: new(sync.Mutex),
35
		index:    make(map[string]bool, 50),
36
	}
37
}
38

39
func (m *indexOfInitialisms) load(initial map[string]bool) *indexOfInitialisms {
40
	m.getMutex.Lock()
41
	defer m.getMutex.Unlock()
42
	for k, v := range initial {
43
		m.index[k] = v
44
	}
45
	return m
46
}
47

48
func (m *indexOfInitialisms) isInitialism(key string) bool {
49
	m.getMutex.Lock()
50
	defer m.getMutex.Unlock()
51
	_, ok := m.index[key]
52
	return ok
53
}
54

55
func (m *indexOfInitialisms) add(key string) *indexOfInitialisms {
56
	m.getMutex.Lock()
57
	defer m.getMutex.Unlock()
58
	m.index[key] = true
59
	return m
60
}
61

62
func (m *indexOfInitialisms) sorted() (result []string) {
63
	m.getMutex.Lock()
64
	defer m.getMutex.Unlock()
65
	for k := range m.index {
66
		result = append(result, k)
67
	}
68
	sort.Sort(sort.Reverse(byInitialism(result)))
69
	return
70
}
71

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.