Skip to content

Commit 98261e2

Browse files
Merge pull request #113 from Workiva/inclusive_rangetree_ranges
Make rangetree ranges inclusive.
2 parents b6b2f46 + 029fc16 commit 98261e2

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

rangetree/interface.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type Entry interface {
3535
ValueAtDimension(dimension uint64) int64
3636
}
3737

38-
// Interval describes the methods required to query the rangetree.
38+
// Interval describes the methods required to query the rangetree. Note that
39+
// all ranges are inclusive.
3940
type Interval interface {
4041
// LowAtDimension returns an integer representing the lower bound
4142
// at the requested dimension.
@@ -60,7 +61,7 @@ type RangeTree interface {
6061
// a nil is returned for that entry's index in the provided cells.
6162
Delete(entries ...Entry) Entries
6263
// Query will return a list of entries that fall within
63-
// the provided interval.
64+
// the provided interval. The values at dimensions are inclusive.
6465
Query(interval Interval) Entries
6566
// Apply will call the provided function with each entry that exists
6667
// within the provided range, in order. Return false at any time to

rangetree/ordered.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (nodes orderedNodes) apply(low, high int64, fn func(*node) bool) bool {
8585
}
8686

8787
for ; index < len(nodes); index++ {
88-
if nodes[index].value >= high {
88+
if nodes[index].value > high {
8989
break
9090
}
9191

rangetree/ordered_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestApply(t *testing.T) {
8181

8282
results := make(nodes, 0, 2)
8383

84-
ns.apply(1, 2, func(n *node) bool {
84+
ns.apply(1, 1, func(n *node) bool {
8585
results = append(results, n)
8686
return true
8787
})
@@ -90,15 +90,15 @@ func TestApply(t *testing.T) {
9090

9191
results = results[:0]
9292

93-
ns.apply(0, 1, func(n *node) bool {
93+
ns.apply(0, 0, func(n *node) bool {
9494
results = append(results, n)
9595
return true
9696
})
9797

9898
assert.Len(t, results, 0)
9999
results = results[:0]
100100

101-
ns.apply(2, 4, func(n *node) bool {
101+
ns.apply(2, 3, func(n *node) bool {
102102
results = append(results, n)
103103
return true
104104
})

rangetree/orderedtree.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
1716
package rangetree
1817

1918
func isLastDimension(value, test uint64) bool {

rangetree/orderedtree_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestOTRootAddMultipleDimensions(t *testing.T) {
4343

4444
assert.Equal(t, uint64(1), tree.Len())
4545

46-
result := tree.Query(constructMockInterval(dimension{0, 1}, dimension{0, 1}))
46+
result := tree.Query(constructMockInterval(dimension{0, 0}, dimension{0, 0}))
4747
assert.Equal(t, Entries{entries[0]}, result)
4848
}
4949

@@ -52,7 +52,7 @@ func TestOTMultipleAddMultipleDimensions(t *testing.T) {
5252

5353
assert.Equal(t, uint64(4), tree.Len())
5454

55-
result := tree.Query(constructMockInterval(dimension{0, 1}, dimension{0, 1}))
55+
result := tree.Query(constructMockInterval(dimension{0, 0}, dimension{0, 0}))
5656
assert.Equal(t, Entries{entries[0]}, result)
5757

5858
result = tree.Query(constructMockInterval(dimension{3, 4}, dimension{3, 4}))
@@ -61,7 +61,7 @@ func TestOTMultipleAddMultipleDimensions(t *testing.T) {
6161
result = tree.Query(constructMockInterval(dimension{0, 4}, dimension{0, 4}))
6262
assert.Equal(t, entries, result)
6363

64-
result = tree.Query(constructMockInterval(dimension{1, 3}, dimension{1, 3}))
64+
result = tree.Query(constructMockInterval(dimension{1, 2}, dimension{1, 2}))
6565
assert.Equal(t, Entries{entries[1], entries[2]}, result)
6666

6767
result = tree.Query(constructMockInterval(dimension{0, 2}, dimension{10, 20}))
@@ -70,10 +70,10 @@ func TestOTMultipleAddMultipleDimensions(t *testing.T) {
7070
result = tree.Query(constructMockInterval(dimension{10, 20}, dimension{0, 2}))
7171
assert.Len(t, result, 0)
7272

73-
result = tree.Query(constructMockInterval(dimension{0, 2}, dimension{0, 1}))
73+
result = tree.Query(constructMockInterval(dimension{0, 1}, dimension{0, 0}))
7474
assert.Equal(t, Entries{entries[0]}, result)
7575

76-
result = tree.Query(constructMockInterval(dimension{0, 1}, dimension{0, 2}))
76+
result = tree.Query(constructMockInterval(dimension{0, 0}, dimension{0, 1}))
7777
assert.Equal(t, Entries{entries[0]}, result)
7878
}
7979

@@ -218,7 +218,7 @@ func TestOTDeleteMultiDimensions(t *testing.T) {
218218
result = tree.Query(constructMockInterval(dimension{3, 4}, dimension{3, 4}))
219219
assert.Equal(t, Entries{entries[3]}, result)
220220

221-
result = tree.Query(constructMockInterval(dimension{0, 3}, dimension{0, 3}))
221+
result = tree.Query(constructMockInterval(dimension{0, 2}, dimension{0, 2}))
222222
assert.Equal(t, Entries{entries[0], entries[1]}, result)
223223
}
224224

0 commit comments

Comments
 (0)