diff options
Diffstat (limited to 'dot-oh-my-zsh/custom/plugins/fzf/src/cache.go')
| m--------- | dot-oh-my-zsh | 0 | ||||
| -rw-r--r-- | dot-oh-my-zsh/custom/plugins/fzf/src/cache.go | 81 |
2 files changed, 0 insertions, 81 deletions
diff --git a/dot-oh-my-zsh b/dot-oh-my-zsh new file mode 160000 +Subproject 6fe84bf5c82da7b1f6d7c5ec3e5c447721ac8ce diff --git a/dot-oh-my-zsh/custom/plugins/fzf/src/cache.go b/dot-oh-my-zsh/custom/plugins/fzf/src/cache.go deleted file mode 100644 index df1a6ab7..00000000 --- a/dot-oh-my-zsh/custom/plugins/fzf/src/cache.go +++ /dev/null @@ -1,81 +0,0 @@ -package fzf - -import "sync" - -// queryCache associates strings to lists of items -type queryCache map[string][]Result - -// ChunkCache associates Chunk and query string to lists of items -type ChunkCache struct { - mutex sync.Mutex - cache map[*Chunk]*queryCache -} - -// NewChunkCache returns a new ChunkCache -func NewChunkCache() ChunkCache { - return ChunkCache{sync.Mutex{}, make(map[*Chunk]*queryCache)} -} - -// Add adds the list to the cache -func (cc *ChunkCache) Add(chunk *Chunk, key string, list []Result) { - if len(key) == 0 || !chunk.IsFull() || len(list) > queryCacheMax { - return - } - - cc.mutex.Lock() - defer cc.mutex.Unlock() - - qc, ok := cc.cache[chunk] - if !ok { - cc.cache[chunk] = &queryCache{} - qc = cc.cache[chunk] - } - (*qc)[key] = list -} - -// Lookup is called to lookup ChunkCache -func (cc *ChunkCache) Lookup(chunk *Chunk, key string) []Result { - if len(key) == 0 || !chunk.IsFull() { - return nil - } - - cc.mutex.Lock() - defer cc.mutex.Unlock() - - qc, ok := cc.cache[chunk] - if ok { - list, ok := (*qc)[key] - if ok { - return list - } - } - return nil -} - -func (cc *ChunkCache) Search(chunk *Chunk, key string) []Result { - if len(key) == 0 || !chunk.IsFull() { - return nil - } - - cc.mutex.Lock() - defer cc.mutex.Unlock() - - qc, ok := cc.cache[chunk] - if !ok { - return nil - } - - for idx := 1; idx < len(key); idx++ { - // [---------| ] | [ |---------] - // [--------| ] | [ |--------] - // [-------| ] | [ |-------] - prefix := key[:len(key)-idx] - suffix := key[idx:] - for _, substr := range [2]string{prefix, suffix} { - if cached, found := (*qc)[substr]; found { - return cached - } - } - } - return nil -} |
