9
9
"fmt"
10
10
"math"
11
11
"sort"
12
+ "strings"
12
13
)
13
14
14
15
// Comparator compares two spatials and returns whether they are equal.
@@ -71,7 +72,7 @@ func (tree *Rtree) Size() int {
71
72
}
72
73
73
74
func (tree * Rtree ) String () string {
74
- return "foo"
75
+ return fmt . Sprintf ( `{"size":%d,"depth":%d,"root":%v}` , tree . size , tree . height , tree . root )
75
76
}
76
77
77
78
// Depth returns the maximum depth of tree.
@@ -223,7 +224,17 @@ type node struct {
223
224
}
224
225
225
226
func (n * node ) String () string {
226
- return fmt .Sprintf ("node{leaf: %v, entries: %v}" , n .leaf , n .entries )
227
+ format := func (v []entry ) string {
228
+ var s []string
229
+ for _ , e := range v {
230
+ s = append (s , fmt .Sprintf ("%v" , e ))
231
+ }
232
+ return fmt .Sprintf (`[%v]` , strings .Join (s , "," ))
233
+ }
234
+ if n .leaf {
235
+ return fmt .Sprintf (`{"leaf":%v,"entries":%v}` , n .leaf , format (n .entries ))
236
+ }
237
+ return fmt .Sprintf (`{"entries":%v}` , format (n .entries ))
227
238
}
228
239
229
240
// entry represents a spatial index record stored in a tree node.
@@ -235,9 +246,9 @@ type entry struct {
235
246
236
247
func (e entry ) String () string {
237
248
if e .child != nil {
238
- return fmt .Sprintf ("entry{bb: %v, child: %v}" , e .bb , e .child )
249
+ return fmt .Sprintf (`{"bb":"%v"," child": %v}` , e .bb , e .child )
239
250
}
240
- return fmt .Sprintf ("entry{bb: %v, obj: %v}" , e .bb , e . obj )
251
+ return fmt .Sprintf (`{"bb":"%v"}` , e .bb )
241
252
}
242
253
243
254
// Spatial is an interface for objects that can be stored in an Rtree and queried.
0 commit comments