From 24f1516fd5164ecc0001bd2563480af2d0cb0f1c Mon Sep 17 00:00:00 2001 From: hexxa Date: Thu, 23 Jun 2022 20:29:04 +0800 Subject: [PATCH] feat(fileindex): add file index top dependencies --- go.mod | 1 + go.sum | 2 ++ src/depidx/deps.go | 10 ++++++++++ src/search/fileindex/trie_tree.go | 26 ++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 src/search/fileindex/trie_tree.go diff --git a/go.mod b/go.mod index 1afea94..83dd225 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/ihexxa/gocfg v0.0.1 github.com/ihexxa/multipart v0.0.0-20210916083128-8584a3f00d1d + github.com/ihexxa/q-radix/v3 v3.0.4 // indirect github.com/jessevdk/go-flags v1.4.0 github.com/json-iterator/go v1.1.11 // indirect github.com/mattn/go-isatty v0.0.13 // indirect diff --git a/go.sum b/go.sum index 4793167..68f3f43 100644 --- a/go.sum +++ b/go.sum @@ -47,6 +47,8 @@ github.com/ihexxa/gocfg v0.0.1 h1:3zsCHY/SYdqKSoo3pwTBWMgivEB7/ctpPPHL3p43UBg= github.com/ihexxa/gocfg v0.0.1/go.mod h1:oqDTq1ywx4Qi9DdhFwwMHoPCYv6Txrfj2SY5WWcgiJs= github.com/ihexxa/multipart v0.0.0-20210916083128-8584a3f00d1d h1:+v33khYHVDPEuuWO/JE1IzhoIu5uNvEcSs5GmXc5Sjw= github.com/ihexxa/multipart v0.0.0-20210916083128-8584a3f00d1d/go.mod h1:rhOAe/52S/J1fq1VnXvKX8FHuo65I+IcYUozW4M7+wE= +github.com/ihexxa/q-radix/v3 v3.0.4 h1:Hk+Av57Q+fwFtHobd5uQjOFdY/V31nl4p+K4mO3crDg= +github.com/ihexxa/q-radix/v3 v3.0.4/go.mod h1:DYXQuLlICQ2pCdPQOzyovzSPq0P8sKwxv5HhVQAwSVQ= github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= diff --git a/src/depidx/deps.go b/src/depidx/deps.go index 788cedf..3353e7d 100644 --- a/src/depidx/deps.go +++ b/src/depidx/deps.go @@ -14,6 +14,7 @@ import ( "github.com/ihexxa/quickshare/src/idgen" "github.com/ihexxa/quickshare/src/iolimiter" "github.com/ihexxa/quickshare/src/kvstore" + "github.com/ihexxa/quickshare/src/search/fileindex" "github.com/ihexxa/quickshare/src/worker" ) @@ -38,6 +39,7 @@ type Deps struct { workers worker.IWorkerPool boltStore *boltstore.BoltStore cron cron.ICron + fileIndex fileindex.IFileIndex } func NewDeps(cfg gocfg.ICfg) *Deps { @@ -139,3 +141,11 @@ func (deps *Deps) Cron() cron.ICron { func (deps *Deps) SetCron(cronImp cron.ICron) { deps.cron = cronImp } + +func (deps *Deps) FileIndex() fileindex.IFileIndex { + return deps.fileIndex +} + +func (deps *Deps) SetFileIndex(fileIndex fileindex.IFileIndex) { + deps.fileIndex = fileIndex +} diff --git a/src/search/fileindex/trie_tree.go b/src/search/fileindex/trie_tree.go new file mode 100644 index 0000000..c3710f4 --- /dev/null +++ b/src/search/fileindex/trie_tree.go @@ -0,0 +1,26 @@ +package fileindex + +import ( + qradix "github.com/ihexxa/q-radix/v3" +) + +type FileTreeIndex struct { + *qradix.RTree +} + +func NewFileTreeIndex() *FileTreeIndex { + return &FileTreeIndex{ + RTree: qradix.NewRTree(), + } +} + +type IFileIndex interface { + FromString(input chan string) error + Get(key string) (interface{}, error) + GetAllPrefixMatches(key string) map[string]interface{} + GetBestMatch(key string) (string, interface{}, bool) + Insert(key string, val interface{}) (interface{}, error) + Remove(key string) bool + Size() int + String() chan string +}