github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/internal/rangedel/truncate.go (about) 1 // Copyright 2019 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 6 7 import "github.com/petermattis/pebble/internal/base" 8 9 // Truncate creates a new iterator where every tombstone in the supplied 10 // iterator is truncated to be contained within the range [lower, upper). 11 func Truncate(cmp base.Compare, iter iterator, lower, upper []byte) *Iter { 12 var tombstones []Tombstone 13 for key, value := iter.First(); key != nil; key, value = iter.Next() { 14 t := Tombstone{ 15 Start: *key, 16 End: value, 17 } 18 if cmp(t.Start.UserKey, lower) < 0 { 19 t.Start.UserKey = lower 20 } 21 if cmp(t.End, upper) > 0 { 22 t.End = upper 23 } 24 if cmp(t.Start.UserKey, t.End) < 0 { 25 tombstones = append(tombstones, t) 26 } 27 } 28 return NewIter(cmp, tombstones) 29 }