mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -05:00
Leverage sort Interface to provide sortUnique function
This commit is contained in:
parent
9476e0b374
commit
53adfb38f4
@ -21,6 +21,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/minio-xl/pkg/probe"
|
"github.com/minio/minio-xl/pkg/probe"
|
||||||
@ -356,6 +357,6 @@ func (fs Filesystem) filterObjects(bucket string, content contentInfo, resources
|
|||||||
return ObjectMetadata{}, resources, err.Trace()
|
return ObjectMetadata{}, resources, err.Trace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortUnique(resources.CommonPrefixes)
|
sortUnique(sort.StringSlice(resources.CommonPrefixes))
|
||||||
return metadata, resources, nil
|
return metadata, resources, nil
|
||||||
}
|
}
|
||||||
|
@ -45,18 +45,23 @@ func sanitizeWindowsPaths(paths ...string) []string {
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
// sortUnique sort a slice in lexical order, removing duplicate elements
|
// sortUnique returns n, the number of distinct elements in data in sorted order.
|
||||||
func sortUnique(objects []string) []string {
|
func sortUnique(data sort.Interface) (n int) {
|
||||||
results := []string{}
|
if n = data.Len(); n < 2 {
|
||||||
seen := make(map[string]string)
|
return n
|
||||||
for _, val := range objects {
|
|
||||||
if _, ok := seen[val]; !ok {
|
|
||||||
results = append(results, val)
|
|
||||||
seen[val] = val
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sort.Strings(results)
|
sort.Sort(data)
|
||||||
return results
|
a, b := 0, 1
|
||||||
|
for b < n {
|
||||||
|
if data.Less(a, b) {
|
||||||
|
a++
|
||||||
|
if a != b {
|
||||||
|
data.Swap(a, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b++
|
||||||
|
}
|
||||||
|
return a + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
type contentInfo struct {
|
type contentInfo struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user