summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/blevesearch/bleve/analysis/freq.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/blevesearch/bleve/analysis/freq.go')
-rw-r--r--vendor/github.com/blevesearch/bleve/analysis/freq.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/blevesearch/bleve/analysis/freq.go b/vendor/github.com/blevesearch/bleve/analysis/freq.go
index e1ca2cd6fd..198c149b2b 100644
--- a/vendor/github.com/blevesearch/bleve/analysis/freq.go
+++ b/vendor/github.com/blevesearch/bleve/analysis/freq.go
@@ -14,6 +14,22 @@
package analysis
+import (
+ "reflect"
+
+ "github.com/blevesearch/bleve/size"
+)
+
+var reflectStaticSizeTokenLocation int
+var reflectStaticSizeTokenFreq int
+
+func init() {
+ var tl TokenLocation
+ reflectStaticSizeTokenLocation = int(reflect.TypeOf(tl).Size())
+ var tf TokenFreq
+ reflectStaticSizeTokenFreq = int(reflect.TypeOf(tf).Size())
+}
+
// TokenLocation represents one occurrence of a term at a particular location in
// a field. Start, End and Position have the same meaning as in analysis.Token.
// Field and ArrayPositions identify the field value in the source document.
@@ -26,6 +42,12 @@ type TokenLocation struct {
Position int
}
+func (tl *TokenLocation) Size() int {
+ rv := reflectStaticSizeTokenLocation
+ rv += len(tl.ArrayPositions) * size.SizeOfUint64
+ return rv
+}
+
// TokenFreq represents all the occurrences of a term in all fields of a
// document.
type TokenFreq struct {
@@ -34,6 +56,15 @@ type TokenFreq struct {
frequency int
}
+func (tf *TokenFreq) Size() int {
+ rv := reflectStaticSizeTokenFreq
+ rv += len(tf.Term)
+ for _, loc := range tf.Locations {
+ rv += loc.Size()
+ }
+ return rv
+}
+
func (tf *TokenFreq) Frequency() int {
return tf.frequency
}
@@ -42,6 +73,16 @@ func (tf *TokenFreq) Frequency() int {
// fields.
type TokenFrequencies map[string]*TokenFreq
+func (tfs TokenFrequencies) Size() int {
+ rv := size.SizeOfMap
+ rv += len(tfs) * (size.SizeOfString + size.SizeOfPtr)
+ for k, v := range tfs {
+ rv += len(k)
+ rv += v.Size()
+ }
+ return rv
+}
+
func (tfs TokenFrequencies) MergeAll(remoteField string, other TokenFrequencies) {
// walk the new token frequencies
for tfk, tf := range other {