github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/structs/transporttrie/merge_test.go (about) 1 package transporttrie 2 3 import ( 4 "bytes" 5 6 "github.com/sirupsen/logrus" 7 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("trie package", func() { 13 Context("trie.Merge()", func() { 14 It("merges 2 tries", func() { 15 t1 := New() 16 t1.Insert([]byte("abc"), uint64(1)) 17 t1.Insert([]byte("abd"), uint64(2)) 18 19 t2 := New() 20 t2.Insert([]byte("abc"), uint64(1)) 21 t2.Insert([]byte("abd"), uint64(2)) 22 23 t3 := New() 24 t3.Insert([]byte("abc"), uint64(2)) 25 t3.Insert([]byte("abd"), uint64(4)) 26 27 var buf1 bytes.Buffer 28 var buf2 bytes.Buffer 29 t1.Serialize(&buf1) 30 t2.Serialize(&buf2) 31 32 logrus.Debug("t1", t1) 33 logrus.Debug("t2", t2) 34 logrus.Debug("t3", t3) 35 36 Expect(buf1.Bytes()).To(Equal(buf2.Bytes())) 37 t1.Merge(t2) 38 39 logrus.Debug("t1+2", t1) 40 41 var buf3 bytes.Buffer 42 var buf4 bytes.Buffer 43 t3.Serialize(&buf3) 44 t1.Serialize(&buf4) 45 Expect(buf4).To(Equal(buf3)) 46 }) 47 }) 48 })