Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTree Example #1496

Merged
merged 10 commits into from
Nov 26, 2021
12 changes: 9 additions & 3 deletions container/gtree/gtree_btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,21 @@ func (tree *BTree) Left() *BTreeEntry {
tree.mu.RLock()
defer tree.mu.RUnlock()
node := tree.left(tree.root)
return node.Entries[0]
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)
return node.Entries[len(node.Entries)-1]
if node != nil {
return node.Entries[len(node.Entries)-1]
}
return nil
}

// String returns a string representation of container (for debugging purposes)
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions container/gtree/gtree_z_example_avltree_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with gm file,
// You can obtain one at https://github.com/gogf/gf.

package gtree_test
Loading