github.com/hugelgupf/u-root@v0.0.0-20191023214958-4807c632154c/cmds/core/elvish/store/dir.go (about)

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