MCPcopy Create free account
hub / github.com/dgraph-io/dgraph-benchmarks / grep

Function grep

finder/entity.go:111–144  ·  view source on GitHub ↗
(tr *trie.Trie)

Source from the content-addressed store, hash-verified

109}
110
111func grep(tr *trie.Trie) {
112 f, scanner := getScanner(*rdf)
113 defer f.Close()
114
115 out, err := os.Create(*output)
116 if err != nil {
117 glog.WithError(err).Fatal("Unable to open output file.")
118 }
119 wr, err := gzip.NewWriterLevel(out, gzip.BestCompression)
120 if err != nil {
121 glog.WithError(err).Fatal("Unable to create gzip writer.")
122 }
123 sw := new(SyncWriter)
124 sw.wr = wr
125
126 ch := make(chan string, 100<<20) // 100 Million
127 wg := new(sync.WaitGroup)
128 for i := 0; i < *numroutines; i++ {
129 wg.Add(1)
130 go findAndWrite(i, *tr, ch, sw, wg)
131 }
132 for scanner.Scan() {
133 ch <- scanner.Text()
134 }
135 close(ch)
136 wg.Wait()
137
138 if err := wr.Close(); err != nil {
139 glog.WithError(err).Fatal("Unable to close output writer.")
140 }
141 if err := out.Close(); err != nil {
142 glog.WithError(err).Fatal("Unable to close output file.")
143 }
144}
145
146func main() {
147 flag.Parse()

Callers 1

mainFunction · 0.85

Calls 4

getScannerFunction · 0.85
findAndWriteFunction · 0.85
AddMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected