github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/internal/rangedel/tombstone.go (about) 1 // Copyright 2018 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package rangedel // import "github.com/petermattis/pebble/internal/rangedel" 6 7 import ( 8 "fmt" 9 10 "github.com/petermattis/pebble/internal/base" 11 ) 12 13 // Tombstone is a range deletion tombstone. A range deletion tombstone deletes 14 // all of the keys in the range [start,end). Note that the start key is 15 // inclusive and the end key is exclusive. 16 type Tombstone struct { 17 Start base.InternalKey 18 End []byte 19 } 20 21 // Empty returns true if the tombstone does not cover any keys. 22 func (t Tombstone) Empty() bool { 23 return t.Start.Kind() != base.InternalKeyKindRangeDelete 24 } 25 26 // Contains returns true if the specified key resides within the range 27 // tombstone bounds. 28 func (t Tombstone) Contains(cmp base.Compare, key []byte) bool { 29 return cmp(t.Start.UserKey, key) <= 0 && cmp(key, t.End) < 0 30 } 31 32 // Deletes returns true if the tombstone deletes keys at seqNum. 33 func (t Tombstone) Deletes(seqNum uint64) bool { 34 return !t.Empty() && t.Start.SeqNum() > seqNum 35 } 36 37 func (t Tombstone) String() string { 38 if t.Empty() { 39 return "<empty>" 40 } 41 return fmt.Sprintf("%s-%s#%d", t.Start.UserKey, t.End, t.Start.SeqNum()) 42 }