Fix Left() And Right() Panic Bug
@@ -346,16 +346,22 @@ func (tree *BTree) Left() *BTreeEntry {
tree.mu.RLock()
defer tree.mu.RUnlock()
node := tree.left(tree.root)
+ if node != nil {
return node.Entries[0]
}
+ return nil
+}
// Right returns the right-most (max) entry or nil if tree is empty.
func (tree *BTree) Right() *BTreeEntry {
tree.mu.RLock()
defer tree.mu.RUnlock()
node := tree.right(tree.root)
+ if node != nil {
return node.Entries[len(node.Entries)-1]
}
+ return nil
+}
// String returns a string representation of container (for debugging purposes)
func (tree *BTree) String() string {
@@ -931,7 +937,7 @@ func (tree *BTree) deleteChild(node *BTreeNode, index int) {
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (tree *BTree) MarshalJSON() ([]byte, error) {
- return json.Marshal(tree.Map())
+ return json.Marshal(tree.MapStrAny())
}
// getComparator returns the comparator if it's previously set,
