Documentation
¶
Index ¶
- type BTree
- type BTreeNode
- type BinarySearchTree
- func (b *BinarySearchTree) Clear()
- func (b *BinarySearchTree) ConvertFromDoubleLinkedList(head *BinaryTreeNode, length int)
- func (b *BinarySearchTree) ConvertToDoubleLinkedList() (head *BinaryTreeNode, tail *BinaryTreeNode)
- func (b *BinarySearchTree) Delete(data interface{}) error
- func (b *BinarySearchTree) GetSize() int
- func (b *BinarySearchTree) Put(key, value interface{})
- func (b *BinarySearchTree) Search(key interface{}) (value interface{})
- func (b *BinarySearchTree) ToSortedSlice() []interface{}
- type BinaryTree
- type BinaryTreeNode
- type Heap
- type HeapType
- type IndexedPriorityQueue
- func (i *IndexedPriorityQueue) ChangeValue(index int, value interface{}) error
- func (i *IndexedPriorityQueue) Contains(index int) bool
- func (i *IndexedPriorityQueue) DeleteValue(index int) error
- func (i *IndexedPriorityQueue) GetValue(index int) (interface{}, error)
- func (i *IndexedPriorityQueue) Insert(index int, value interface{}) error
- func (i *IndexedPriorityQueue) IsEmpty() bool
- func (i *IndexedPriorityQueue) Peek() (index int, value interface{}, err error)
- func (i *IndexedPriorityQueue) Pop() (index int, value interface{}, err error)
- func (i *IndexedPriorityQueue) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BTree ¶
type BTree struct {
Root *BTreeNode // root has min 2 children if it's not leaf.
// contains filtered or unexported fields
}
BTree defines a B-Tree
func NewBTree ¶
func NewBTree(order int, comparator shared.Comparator) *BTree
NewBTree creates a new B-Tree
type BTreeNode ¶
type BTreeNode struct {
Keys []interface{} // The separation keys, for non-leaf node, count = count(children) - 1
Values []interface{}
Children []*BTreeNode // The childrens, maximum at order
Parent *BTreeNode
}
BTreeNode defines a B-Tree Node
type BinarySearchTree ¶
type BinarySearchTree struct {
BinaryTree
// contains filtered or unexported fields
}
BinarySearchTree defines a binary search tree
func (*BinarySearchTree) Clear ¶
func (b *BinarySearchTree) Clear()
Clear clears the binary search tree.
func (*BinarySearchTree) ConvertFromDoubleLinkedList ¶
func (b *BinarySearchTree) ConvertFromDoubleLinkedList(head *BinaryTreeNode, length int)
ConvertFromDoubleLinkedList converts double linked list back to
func (*BinarySearchTree) ConvertToDoubleLinkedList ¶
func (b *BinarySearchTree) ConvertToDoubleLinkedList() (head *BinaryTreeNode, tail *BinaryTreeNode)
ConvertToDoubleLinkedList converts the BST to A Double Linked List.
func (*BinarySearchTree) Delete ¶
func (b *BinarySearchTree) Delete(data interface{}) error
Delete deletes a data node from binary search tree.
func (*BinarySearchTree) GetSize ¶
func (b *BinarySearchTree) GetSize() int
GetSize gets the size of the tree.
func (*BinarySearchTree) Put ¶
func (b *BinarySearchTree) Put(key, value interface{})
Put puts a data node into the binary search tree, if the key exists already, update its value.
func (*BinarySearchTree) Search ¶
func (b *BinarySearchTree) Search(key interface{}) (value interface{})
Search searchs value by key.
func (*BinarySearchTree) ToSortedSlice ¶
func (b *BinarySearchTree) ToSortedSlice() []interface{}
ToSortedSlice traverse the tree and store the data into a sorted slice
type BinaryTree ¶
type BinaryTree struct {
Root *BinaryTreeNode
Comparator shared.Comparator
}
BinaryTree defines a general binary tree
func (*BinaryTree) BreadthFirstTraverse ¶
func (b *BinaryTree) BreadthFirstTraverse() []interface{}
BreadthFirstTraverse traverse the tree breadth-first way, a.k.a level by level. The idea is to use a QUEUE to store candidate left and right children along the way.
func (*BinaryTree) DepthFirstTraverse ¶
func (b *BinaryTree) DepthFirstTraverse() []interface{}
DepthFirstTraverse traverse the tree depth-first way. The idea is to use a STACK to store candidate right and left children along the way.
type BinaryTreeNode ¶
type BinaryTreeNode struct {
Key interface{}
Value interface{}
Left *BinaryTreeNode
Right *BinaryTreeNode
}
BinaryTreeNode defines a tree node of a binary search tree
type Heap ¶
type Heap struct {
HeapType HeapType
Comparator shared.Comparator
// contains filtered or unexported fields
}
Heap defines a heap
func (*Heap) GetValues ¶
func (h *Heap) GetValues() []interface{}
GetValues gets the values of the heap
type IndexedPriorityQueue ¶
type IndexedPriorityQueue struct {
// contains filtered or unexported fields
}
IndexedPriorityQueue defines an indexed priority queue based on a heap.
func NewIndexedPriorityQueue ¶
func NewIndexedPriorityQueue(capacity int, heapType HeapType, comparator shared.Comparator) *IndexedPriorityQueue
NewIndexedPriorityQueue creates a new indexed priority queue with capacity, heapType and value comparator specified
func (*IndexedPriorityQueue) ChangeValue ¶
func (i *IndexedPriorityQueue) ChangeValue(index int, value interface{}) error
ChangeValue changes the value at a given index, if the index is out of range or no value was added, error will be returned.
func (*IndexedPriorityQueue) Contains ¶
func (i *IndexedPriorityQueue) Contains(index int) bool
Contains check whether the queue contains a value with the given index.
func (*IndexedPriorityQueue) DeleteValue ¶
func (i *IndexedPriorityQueue) DeleteValue(index int) error
DeleteValue deletes the value at a given index, if the index is out of range or no value was added, error will be returned.
func (*IndexedPriorityQueue) GetValue ¶
func (i *IndexedPriorityQueue) GetValue(index int) (interface{}, error)
GetValue gets value at a given index, if index is out of range or no value was added, error will be returned.
func (*IndexedPriorityQueue) Insert ¶
func (i *IndexedPriorityQueue) Insert(index int, value interface{}) error
Insert inters a value into the queue with a given index, if the index is not valid or is taken, error will be return.
func (*IndexedPriorityQueue) IsEmpty ¶
func (i *IndexedPriorityQueue) IsEmpty() bool
IsEmpty returns whether the queue is empty.
func (*IndexedPriorityQueue) Peek ¶
func (i *IndexedPriorityQueue) Peek() (index int, value interface{}, err error)
Peek peeks the priority queue, it returns the heap top value with it's index. if queue is empty, error will be returned.
func (*IndexedPriorityQueue) Pop ¶
func (i *IndexedPriorityQueue) Pop() (index int, value interface{}, err error)
Pop returns the heap top value of the queue, and remove it from the queue in the meantime, error will be returned if queue is empty.
func (*IndexedPriorityQueue) Size ¶
func (i *IndexedPriorityQueue) Size() int
Size returns the number of values stored in the queue.