|
1 /* |
|
2 * Copyright (C) 2014-2018 Mikael Berthe <mikael@lilotux.net> |
|
3 * |
|
4 * This program is free software; you can redistribute it and/or modify |
|
5 * it under the terms of the GNU General Public License as published by |
|
6 * the Free Software Foundation; either version 2 of the License, or (at |
|
7 * your option) any later version. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, but |
|
10 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
17 * USA |
|
18 */ |
|
19 |
|
20 package main |
|
21 |
|
22 // Implement a sort interface for the list of duplicate groups |
|
23 type byGroupFileSize foListList |
|
24 |
|
25 func (a byGroupFileSize) Len() int { return len(a) } |
|
26 func (a byGroupFileSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
|
27 func (a byGroupFileSize) Less(i, j int) bool { |
|
28 // Since this is supposed to be used for duplicate lists, |
|
29 // we use the size of the first file of the group. |
|
30 if a[i][0].Size() == a[j][0].Size() { |
|
31 return a[i][0].FilePath < a[j][0].FilePath |
|
32 } |
|
33 return a[i][0].Size() < a[j][0].Size() |
|
34 } |
|
35 |
|
36 // Implement a sort interface for a slice of files |
|
37 type byFilePathName FileObjList |
|
38 |
|
39 func (a byFilePathName) Len() int { return len(a) } |
|
40 func (a byFilePathName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
|
41 func (a byFilePathName) Less(i, j int) bool { |
|
42 return a[i].FilePath < a[j].FilePath |
|
43 } |