Implement GCP Cloud Function
This commit is contained in:
parent
794b873ddd
commit
15d4b66afa
13 changed files with 242686 additions and 38 deletions
|
@ -10,6 +10,18 @@ import (
|
|||
|
||||
type DB interface {
|
||||
FindAnagrams(s string) []string
|
||||
Add(s string)
|
||||
}
|
||||
|
||||
type HashDBImpl map[string][]string
|
||||
|
||||
func New() HashDBImpl {
|
||||
return make(HashDBImpl)
|
||||
}
|
||||
|
||||
func (db HashDBImpl) Add(s string) {
|
||||
k := toKey(s)
|
||||
db[k] = append(db[k], s)
|
||||
}
|
||||
|
||||
func toKey(s string) string {
|
||||
|
@ -18,15 +30,11 @@ func toKey(s string) string {
|
|||
return string(xs)
|
||||
}
|
||||
|
||||
type HashDBImpl map[string][]string
|
||||
|
||||
func Load(r io.Reader) (DB, error) {
|
||||
db := make(HashDBImpl)
|
||||
db := New()
|
||||
sc := bufio.NewScanner(r)
|
||||
for sc.Scan() {
|
||||
s := sc.Text()
|
||||
k := toKey(s)
|
||||
db[k] = append(db[k], s)
|
||||
db.Add(sc.Text())
|
||||
|
||||
}
|
||||
if err := sc.Err(); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue