Path: blob/main/vendor/github.com/spf13/afero/mem/dirmap.go
2880 views
// Copyright © 2015 Steve Francia <[email protected]>.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5// http://www.apache.org/licenses/LICENSE-2.06//7// Unless required by applicable law or agreed to in writing, software8// distributed under the License is distributed on an "AS IS" BASIS,9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10// See the License for the specific language governing permissions and11// limitations under the License.1213package mem1415import "sort"1617type DirMap map[string]*FileData1819func (m DirMap) Len() int { return len(m) }20func (m DirMap) Add(f *FileData) { m[f.name] = f }21func (m DirMap) Remove(f *FileData) { delete(m, f.name) }22func (m DirMap) Files() (files []*FileData) {23for _, f := range m {24files = append(files, f)25}26sort.Sort(filesSorter(files))27return files28}2930// implement sort.Interface for []*FileData31type filesSorter []*FileData3233func (s filesSorter) Len() int { return len(s) }34func (s filesSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }35func (s filesSorter) Less(i, j int) bool { return s[i].name < s[j].name }3637func (m DirMap) Names() (names []string) {38for x := range m {39names = append(names, x)40}41return names42}434445