44 "encoding/binary"
55 "sort"
66
7+ datastructures "github.com/deepfabric/go-datastructures"
78 "github.com/keegancsmith/nth"
89)
910
@@ -12,12 +13,6 @@ type Point struct {
1213 UserData uint64
1314}
1415
15- // PointMinHeap is a min-heap of points.
16- type PointMinHeap []Point
17-
18- // PointMaxHeap is a max-heap of points.
19- type PointMaxHeap []Point
20-
2116type PointArray interface {
2217 sort.Interface
2318 GetPoint (idx int ) Point
@@ -41,6 +36,17 @@ type PointArrayExt struct {
4136 pointSize int
4237}
4338
39+ // Compare is part of datastructures.Comparable interface
40+ func (p Point ) Compare (other datastructures.Comparable ) int {
41+ rhs := other .(Point )
42+ for dim := 0 ; dim < len (p .Vals ); dim ++ {
43+ if p .Vals [dim ] != rhs .Vals [dim ] {
44+ return int (p .Vals [dim ] - rhs .Vals [dim ])
45+ }
46+ }
47+ return int (p .UserData - rhs .UserData )
48+ }
49+
4450func (p * Point ) Inside (lowPoint , highPoint Point ) (isInside bool ) {
4551 for dim := 0 ; dim < len (p .Vals ); dim ++ {
4652 if p .Vals [dim ] < lowPoint .Vals [dim ] || p .Vals [dim ] > highPoint .Vals [dim ] {
@@ -111,68 +117,6 @@ func (p *Point) Decode(b []byte, numDims int, bytesPerDim int) {
111117 return
112118}
113119
114- // Len is part of sort.Interface.
115- func (s PointMinHeap ) Len () int {
116- return len (s )
117- }
118-
119- // Swap is part of sort.Interface.
120- func (s PointMinHeap ) Swap (i , j int ) {
121- s [i ], s [j ] = s [j ], s [i ]
122- }
123-
124- // Less is part of sort.Interface.
125- func (s PointMinHeap ) Less (i , j int ) bool {
126- return s [i ].LessThan (s [j ])
127- }
128-
129- // Push is part of heap.Interface.
130- func (s * PointMinHeap ) Push (x interface {}) {
131- // Push and Pop use pointer receivers because they modify the slice's length,
132- // not just its contents.
133- * s = append (* s , x .(Point ))
134- }
135-
136- // Pop is part of heap.Interface.
137- func (s * PointMinHeap ) Pop () interface {} {
138- old := * s
139- n := len (old )
140- x := old [n - 1 ]
141- * s = old [0 : n - 1 ]
142- return x
143- }
144-
145- // Len is part of sort.Interface.
146- func (s PointMaxHeap ) Len () int {
147- return len (s )
148- }
149-
150- // Swap is part of sort.Interface.
151- func (s PointMaxHeap ) Swap (i , j int ) {
152- s [i ], s [j ] = s [j ], s [i ]
153- }
154-
155- // Less is part of sort.Interface.
156- func (s PointMaxHeap ) Less (i , j int ) bool {
157- return s [j ].LessThan (s [i ])
158- }
159-
160- // Push is part of heap.Interface.
161- func (s * PointMaxHeap ) Push (x interface {}) {
162- // Push and Pop use pointer receivers because they modify the slice's length,
163- // not just its contents.
164- * s = append (* s , x .(Point ))
165- }
166-
167- // Pop is part of heap.Interface.
168- func (s * PointMaxHeap ) Pop () interface {} {
169- old := * s
170- n := len (old )
171- x := old [n - 1 ]
172- * s = old [0 : n - 1 ]
173- return x
174- }
175-
176120// Len is part of sort.Interface.
177121func (s * PointArrayMem ) Len () int {
178122 return len (s .points )
0 commit comments