OXIESEC PANEL
- Current Dir:
/
/
opt
/
golang
/
1.22.0
/
src
/
sort
Server IP: 191.96.63.230
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
example_interface_test.go
1.47 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
example_keys_test.go
2.68 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
example_multi_test.go
4.05 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
example_search_test.go
2.12 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
example_test.go
2.85 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
example_wrapper_test.go
1.63 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
export_test.go
314 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
gen_sort_variants.go
19.61 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
search.go
5.67 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
search_test.go
6.78 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
slice.go
1.81 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sort.go
10.14 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sort_impl_120.go
602 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sort_impl_go121.go
876 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sort_slices_benchmark_test.go
3.92 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sort_test.go
16.91 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
zsortfunc.go
11.49 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
zsortinterface.go
11.22 KB
02/02/2024 06:09:55 PM
rw-r--r--
Editing: example_wrapper_test.go
Close
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package sort_test import ( "fmt" "sort" ) type Grams int func (g Grams) String() string { return fmt.Sprintf("%dg", int(g)) } type Organ struct { Name string Weight Grams } type Organs []*Organ func (s Organs) Len() int { return len(s) } func (s Organs) Swap(i, j int) { s[i], s[j] = s[j], s[i] } // ByName implements sort.Interface by providing Less and using the Len and // Swap methods of the embedded Organs value. type ByName struct{ Organs } func (s ByName) Less(i, j int) bool { return s.Organs[i].Name < s.Organs[j].Name } // ByWeight implements sort.Interface by providing Less and using the Len and // Swap methods of the embedded Organs value. type ByWeight struct{ Organs } func (s ByWeight) Less(i, j int) bool { return s.Organs[i].Weight < s.Organs[j].Weight } func Example_sortWrapper() { s := []*Organ{ {"brain", 1340}, {"heart", 290}, {"liver", 1494}, {"pancreas", 131}, {"prostate", 62}, {"spleen", 162}, } sort.Sort(ByWeight{s}) fmt.Println("Organs by weight:") printOrgans(s) sort.Sort(ByName{s}) fmt.Println("Organs by name:") printOrgans(s) // Output: // Organs by weight: // prostate (62g) // pancreas (131g) // spleen (162g) // heart (290g) // brain (1340g) // liver (1494g) // Organs by name: // brain (1340g) // heart (290g) // liver (1494g) // pancreas (131g) // prostate (62g) // spleen (162g) } func printOrgans(s []*Organ) { for _, o := range s { fmt.Printf("%-8s (%v)\n", o.Name, o.Weight) } }