forked from u-root/u-root
/
dir.go
63 lines (48 loc) · 1.24 KB
/
dir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package store
import (
"sync"
"github.com/u-root/u-root/cmds/core/elvish/store/storedefs"
)
const (
scoreDecay = 0.986 // roughly 0.5^(1/50)
scoreIncrement = 10
scorePrecision = 6
)
type Dir struct {
Score float64
Name string
}
type DirHistory struct {
sync.Mutex
}
// we do not intend to store the directory history in a persisent manner any more.
func init() {
}
// AddDir adds a directory to the directory history.
func (*DirHistory) AddDir(d string, incFactor float64) error {
return nil
}
// AddDir adds a directory and its score to history.
func (s *DirHistory) AddDirRaw(d string, score float64) error {
return nil
}
// DelDir deletes a directory record from history.
func (s *DirHistory) DelDir(d string) error {
return nil
}
// Dirs lists all directories in the directory history whose names are not
// in the blacklist. The results are ordered by scores in descending order.
func (s *DirHistory) Dirs(blacklist map[string]struct{}) ([]storedefs.Dir, error) {
var dirs []storedefs.Dir
return dirs, nil
}
type dirList []storedefs.Dir
func (dl dirList) Len() int {
return len(dl)
}
func (dl dirList) Less(i, j int) bool {
return dl[i].Score < dl[j].Score
}
func (dl dirList) Swap(i, j int) {
dl[i], dl[j] = dl[j], dl[i]
}