podman

Форк
0
68 строк · 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
// Since go1.9, this may be implemented with sync.Map.
27
type indexOfInitialisms struct {
28
	sortMutex *sync.Mutex
29
	index     *sync.Map
30
}
31

32
func newIndexOfInitialisms() *indexOfInitialisms {
33
	return &indexOfInitialisms{
34
		sortMutex: new(sync.Mutex),
35
		index:     new(sync.Map),
36
	}
37
}
38

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

48
func (m *indexOfInitialisms) isInitialism(key string) bool {
49
	_, ok := m.index.Load(key)
50
	return ok
51
}
52

53
func (m *indexOfInitialisms) add(key string) *indexOfInitialisms {
54
	m.index.Store(key, true)
55
	return m
56
}
57

58
func (m *indexOfInitialisms) sorted() (result []string) {
59
	m.sortMutex.Lock()
60
	defer m.sortMutex.Unlock()
61
	m.index.Range(func(key, value interface{}) bool {
62
		k := key.(string)
63
		result = append(result, k)
64
		return true
65
	})
66
	sort.Sort(sort.Reverse(byInitialism(result)))
67
	return
68
}
69

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

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

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

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