Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
use github.com/high-moctane/go-readerer in searchOneGram function
Browse files Browse the repository at this point in the history
  • Loading branch information
high-moctane committed Dec 30, 2019
1 parent 1241e71 commit 9bfb551
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/high-moctane/nextword

go 1.13

require github.com/high-moctane/go-readerer v0.0.1
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/high-moctane/go-readerer v0.0.0-20191230143156-1ca39e735544 h1:Nly/VSTecrgGCX/KAX0fuqd2mEzSKqFrmEXLpw/4V2s=
github.com/high-moctane/go-readerer v0.0.0-20191230143156-1ca39e735544/go.mod h1:vODiwhB3mDG9W0/5RrP/UABW2IHZWdZaH7lxocx1PJg=
github.com/high-moctane/go-readerer v0.0.1 h1:joTTbd6W7Tascsrr3UnhsOBR20d7saT6fgzXtLIKR1g=
github.com/high-moctane/go-readerer v0.0.1/go.mod h1:vODiwhB3mDG9W0/5RrP/UABW2IHZWdZaH7lxocx1PJg=
20 changes: 10 additions & 10 deletions nextword.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"bufio"
"errors"
"fmt"
"github.com/high-moctane/go-readerer"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -198,20 +200,18 @@ func (nw *Nextword) searchOneGram(prefix string) (candidates []string, err error
}

// collect
for {
var line string
line, err = nw.readLine(f, offset)
if err != nil {
if err == io.EOF {
err = nil
}
return
}
r := readerer.FromReaderAt(f, offset)
sc := bufio.NewScanner(r)
for sc.Scan() {
line := sc.Text()
if !strings.HasPrefix(line, prefix) {
break
}
candidates = append(candidates, line)
offset += int64(len(line)) + 1 // "\n"
}
if sc.Err() != nil {
err = sc.Err()
return
}

return
Expand Down

0 comments on commit 9bfb551

Please sign in to comment.