You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+130-1Lines changed: 130 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ gocontainer implements some containers which exist in Java, but are missing in g
13
13
-[List](#list)
14
14
-[PriorityQueue](#priorityqueue)
15
15
-[LinkedMap](#linkedMap)
16
+
-[BTree](#bTree)
16
17
-[Others](#others)
17
18
-**[Utilities](#Utilities)**
18
19
-[Comparator](#Comparator)
@@ -491,7 +492,7 @@ func main() {
491
492
492
493
A utils.Comparator instance can be provided for a priorityQueue by method WithComparator, please get more detailed info in **[Comparator](#comparator)**.
493
494
```go
494
-
WithComparator(c gsort.Comparator) Interface
495
+
WithComparator(c utils.Comparator) Interface
495
496
```
496
497
497
498
A priorityQueue can be configured to use min-heap or max-heap using method WithMinHeap. If the parameter is true, then it's a min-heap, which is the default option as well; otherwise, it's a max-heap.
@@ -618,6 +619,134 @@ for hasPrev {
618
619
}
619
620
```
620
621
622
+
## **BTree**
623
+
BTree is a B-Tree implementation. It was originally copied from github.com/google/btree, but it is refactored to adapt to the interface convention in this repository. Some improvements are also applied on top of the original design & implementation, so that it's more user-friendly.
624
+
It implements the following interface. Click **[here](examples/btree_example.go)** to find examples on how to use a BTree.
625
+
```go
626
+
// Interface is a type of btree, and bTree implements this interface
627
+
typeInterfaceinterface {
628
+
collection.Interface
629
+
630
+
// WithComparator sets an utils.Comparator instance for the btree.
631
+
// It's used to impose a total ordering on the elements in the btree.
632
+
WithComparator(c utils.Comparator) Interface
633
+
634
+
// Clone clones the btree, lazily. The internal tree structure is marked read-only and
635
+
// shared between the old and new btree. Writes to both the old and the new btree use copy-on-write logic.
636
+
Clone() Interface
637
+
// ReplaceOrInsert adds the given item to the tree. If an item in the tree
638
+
// already equals the given one, it is removed from the tree and returned.
639
+
// Otherwise, nil is returned.
640
+
ReplaceOrInsert(item interface{}) interface{}
641
+
// Delete removes an item equal to the passed in item from the tree, returning
642
+
// it. If no such item exists, returns nil.
643
+
Delete(item interface{}) interface{}
644
+
// DeleteMin removes the smallest item in the tree and returns it.
645
+
// If no such item exists, returns nil.
646
+
DeleteMin() interface{}
647
+
// DeleteMax removes the largest item in the tree and returns it.
648
+
// If no such item exists, returns nil.
649
+
DeleteMax() interface{}
650
+
651
+
// AscendRange calls the iterator for every value in the tree within the range
652
+
// [greaterOrEqual, lessThan), until iterator returns false.
0 commit comments