Decompressor: fast .Count method(#226)

This commit is contained in:
Alex Sharov 2022-01-09 17:32:56 +07:00 committed by GitHub
parent a8c2481967
commit f92c12855d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,17 +189,7 @@ func (g *Getter) nextPattern() []byte {
return g.pattern()
}
func (d *Decompressor) Count() int {
//TODO: likely it can be optimized by don't decompress values, or even by storing count in file
counterGetter := d.MakeGetter()
word := make([]byte, 0, 64)
count := 0
for counterGetter.HasNext() {
word, _ = counterGetter.Next(word[:0])
count++
}
return count
}
func (d *Decompressor) Count() int { return int(d.count) }
// MakeGetter creates an object that can be used to access words in the decompressor's file
// Getter is not thread-safe, but there can be multiple getters used simultaneously and concrently