github.com/mre-fog/trillianxx@v1.1.2-0.20180615153820-ae375a99d36a/storage/memory/tree_debug.go (about) 1 // Copyright 2017 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package memory 16 17 import ( 18 "github.com/golang/glog" 19 "github.com/google/btree" 20 "github.com/google/trillian/storage" 21 "github.com/google/trillian/storage/storagepb" 22 ) 23 24 // This file contains utilities that are not part of the Storage API contracts but may 25 // be useful for development or debugging. 26 27 // Dump ascends the tree, logging the items contained. 28 func Dump(t *btree.BTree) { 29 t.Ascend(func(i btree.Item) bool { 30 glog.Infof("%#v", i) 31 return true 32 }) 33 } 34 35 // DumpSubtrees will traverse the the BTree and execute a callback on each subtree proto 36 // that it contains. The traversal will be 'in order' according to the BTree keys, which 37 // may not be useful at the application level. 38 func DumpSubtrees(ls storage.LogStorage, treeID int64, callback func(string, *storagepb.SubtreeProto)) { 39 m := ls.(*memoryLogStorage) 40 tree := m.trees[treeID] 41 pi := subtreeKey(treeID, 0, storage.NewEmptyNodeID(64)) 42 43 tree.store.AscendGreaterOrEqual(pi, func(bi btree.Item) bool { 44 i := bi.(*kv) 45 46 if _, ok := i.v.(*storagepb.SubtreeProto); !ok { 47 // Then we've finished iterating over subtrees 48 return false 49 } 50 callback(i.k, i.v.(*storagepb.SubtreeProto)) 51 return true 52 }) 53 }