@@ -85,6 +85,7 @@ func (it *LinksTo) Tagger() *graph.Tagger {
85
85
func (it * LinksTo ) Clone () graph.Iterator {
86
86
out := NewLinksTo (it .qs , it .primaryIt .Clone (), it .dir )
87
87
out .tags .CopyFrom (it )
88
+ out .runstats .Size , out .runstats .ExactSize = it .runstats .Size , it .runstats .ExactSize
88
89
return out
89
90
}
90
91
@@ -211,21 +212,43 @@ func (it *LinksTo) Type() graph.Type { return graph.LinksTo }
211
212
func (it * LinksTo ) Stats () graph.IteratorStats {
212
213
subitStats := it .primaryIt .Stats ()
213
214
// TODO(barakmich): These should really come from the quadstore itself
214
- fanoutFactor := int64 (20 )
215
215
checkConstant := int64 (1 )
216
216
nextConstant := int64 (2 )
217
- return graph.IteratorStats {
217
+ st := graph.IteratorStats {
218
218
NextCost : nextConstant + subitStats .NextCost ,
219
219
ContainsCost : checkConstant + subitStats .ContainsCost ,
220
- Size : fanoutFactor * subitStats .Size ,
221
- ExactSize : false ,
222
220
Next : it .runstats .Next ,
223
221
Contains : it .runstats .Contains ,
224
222
ContainsNext : it .runstats .ContainsNext ,
225
223
}
224
+ st .Size , st .ExactSize = it .Size ()
225
+ return st
226
226
}
227
227
228
228
func (it * LinksTo ) Size () (int64 , bool ) {
229
- st := it .Stats ()
230
- return st .Size , st .ExactSize
229
+ if it .runstats .Size != 0 {
230
+ return it .runstats .Size , it .runstats .ExactSize
231
+ }
232
+ if fixed , ok := it .primaryIt .(* Fixed ); ok {
233
+ // get real sizes from sub iterators
234
+ var (
235
+ sz int64
236
+ exact = true
237
+ )
238
+ for _ , v := range fixed .Values () {
239
+ sit := it .qs .QuadIterator (it .dir , v )
240
+ n , ex := sit .Size ()
241
+ sit .Close ()
242
+ sz += n
243
+ exact = exact && ex
244
+ }
245
+ it .runstats .Size , it .runstats .ExactSize = sz , exact
246
+ return sz , exact
247
+ }
248
+ // TODO(barakmich): It should really come from the quadstore itself
249
+ const fanoutFactor = 20
250
+ sz , _ := it .primaryIt .Size ()
251
+ sz *= fanoutFactor
252
+ it .runstats .Size , it .runstats .ExactSize = sz , false
253
+ return sz , false
231
254
}
0 commit comments