Skip to content

Commit

Permalink
rename ring item
Browse files Browse the repository at this point in the history
Signed-off-by: bufferflies <[email protected]>
  • Loading branch information
bufferflies committed May 12, 2022
1 parent b62a319 commit 138c3f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bucket
package buckets

import (
"bytes"
Expand All @@ -32,13 +32,13 @@ func NewRing(degree int) *Ring {
}
}

// RingItem is a ring item.
type RingItem interface {
// BucketItem is a ring item.
type BucketItem interface {
Less(than btree.Item) bool
StartKey() []byte
EndKey() []byte
// Debris returns the debris after replacing the key range.
Debris(startKey, endKey []byte) []RingItem
Debris(startKey, endKey []byte) []BucketItem
String() string
}

Expand All @@ -51,12 +51,12 @@ func (r *Ring) Len() int {
// cache key range: |001-----100|100-----200|
// request key range: |005-----120|
// return items: |001-----100|100-----200|
func (r *Ring) GetRange(item RingItem) []RingItem {
var res []RingItem
func (r *Ring) GetRange(item BucketItem) []BucketItem {
var res []BucketItem

var first RingItem
var first BucketItem
r.tree.DescendLessOrEqual(item, func(i btree.Item) bool {
first = i.(RingItem)
first = i.(BucketItem)
return false
})

Expand All @@ -69,7 +69,7 @@ func (r *Ring) GetRange(item RingItem) []RingItem {

// find the next item util the item greater than end key.
r.tree.AscendGreaterOrEqual(first, func(i btree.Item) bool {
ringItem := i.(RingItem)
ringItem := i.(BucketItem)
if len(item.EndKey()) > 0 && bytes.Compare(ringItem.StartKey(), item.EndKey()) >= 0 {
return false
}
Expand All @@ -80,7 +80,7 @@ func (r *Ring) GetRange(item RingItem) []RingItem {
}

// Put puts a new item into the ring.
func (r *Ring) Put(item RingItem) {
func (r *Ring) Put(item BucketItem) {
overlaps := r.GetRange(item)
for _, overlap := range overlaps {
r.tree.Delete(overlap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bucket
package buckets

import (
"bytes"
Expand Down Expand Up @@ -51,13 +51,13 @@ func (s *simpleBucketItem) String() string {

// Less returns true if the start key of the item is less than the start key of the argument.
func (s *simpleBucketItem) Less(than btree.Item) bool {
return bytes.Compare(s.StartKey(), than.(RingItem).StartKey()) < 0
return bytes.Compare(s.StartKey(), than.(BucketItem).StartKey()) < 0
}

// Debris returns the debris of the item.
// details: https://leetcode.cn/problems/interval-list-intersections/
func (s simpleBucketItem) Debris(startKey, endKey []byte) []RingItem {
var res []RingItem
func (s simpleBucketItem) Debris(startKey, endKey []byte) []BucketItem {
var res []BucketItem

left := maxKey(startKey, s.startKey)
right := minKey(endKey, s.endKey)
Expand Down Expand Up @@ -135,7 +135,7 @@ func (bs *testBucketSuite) TestRingPutItem(c *C) {

func (bs *testBucketSuite) TestDebris(c *C) {
ringItem := newSimpleBucketItem([]byte("010"), []byte("090"))
var overlaps []RingItem
var overlaps []BucketItem
overlaps = ringItem.Debris([]byte("000"), []byte("100"))
c.Assert(overlaps, HasLen, 0)
overlaps = ringItem.Debris([]byte("000"), []byte("080"))
Expand Down

0 comments on commit 138c3f9

Please sign in to comment.