focus/README.md

55 lines
1.4 KiB
Markdown
Raw Normal View History

new file: .gitignore new file: LICENSE new file: README.md new file: compare/compare.go new file: for_test.go new file: heap/heap.go new file: heap/heap_test.go new file: interface.go new file: lastack/lastack.go new file: lastack/lastack_test.go new file: list/list.go new file: list/list_test.go new file: map/hashmap/hashmap.go new file: map/hashmap/hashmap_test.go new file: priority_list/iterator.go new file: priority_list/priority_list.go new file: priority_list/priority_list_test.go new file: priority_queue/iterator.go new file: priority_queue/priority_queue.go new file: priority_queue/priority_queue_test.go new file: priority_queue/vbt.go new file: priority_queue/vbt_test.go new file: priority_queuekey/iterator.go new file: priority_queuekey/priority_queuekey.go new file: priority_queuekey/priority_queuekey_test.go new file: priority_queuekey/vbt.go new file: priority_queuekey/vbt_test.go new file: set/hashset/hashset.go new file: set/hashset/hashset_test.go new file: set/treeset/treeset.go new file: set/treeset/treeset_test.go new file: sparse_array/array2/array2.go new file: sparse_array/array2/array2_test.go new file: sparse_array/array3/array3.go new file: sparse_array/array3/array3_test.go new file: sparse_array/arrayn/arrayn.go new file: sparse_array/arrayn/arrayn_test.go new file: stack/stack.go new file: stack/stack_test.go new file: tree/avl/avl.go new file: tree/avl/avl_test.go new file: tree/avl/iterator.go new file: tree/avldup/avldup.go new file: tree/avldup/avldup_test.go new file: tree/avldup/iterator.go new file: tree/avlkey/avlkey.go new file: tree/avlkey/avlkey_test.go new file: tree/avlkey/iterator.go new file: tree/avlkeydup/avlkeydup.go new file: tree/avlkeydup/avlkeydup_test.go new file: tree/avlkeydup/iterator.go new file: tree/vbt/iterator.go new file: tree/vbt/vbt.go new file: tree/vbt/vbt_test.go new file: tree/vbtkey/iterator.go new file: tree/vbtkey/vbtkey.go new file: tree/vbtkey/vbtkey_test.go
2019-05-08 02:42:51 +00:00
# structure
2020-03-20 08:57:21 +00:00
暂时没时间整理, 后期才整理完整.
2019-07-18 03:06:39 +00:00
## PriorityQueue
``` golang
2019-07-18 06:57:44 +00:00
package main
import (
"log"
"github.com/474420502/focus/compare"
pqueuekey "github.com/474420502/focus/priority_queuekey"
)
func main() {
pq := New(compare.Int)
2019-07-18 06:57:44 +00:00
pq.Push(1, 1)
pq.Push(4, 4)
pq.Push(5, 5)
pq.Push(6, 6)
pq.Push(2, 2) // pq.Values() = [6 5 4 2 1]
log.Println(pq.Values())
value, _ := pq.Pop() // value = 6
log.Println(value)
value, _ = pq.Get(1) // value = 1 pq.Values() = [5 4 2 1]
log.Println(value)
value, _ = pq.Get(0) // value = nil , Get equal to Seach Key
log.Println(value)
value, _ = pq.Index(0) // value = 5, compare.Int the order from big to small
log.Println(value)
values := pq.GetRange(2, 5) // values = [2 4 5]
log.Println(values)
values = pq.GetRange(5, 2) // values = [5 4 2]
log.Println(values)
values = pq.GetRange(100, 2) // values = [5 4 2]
log.Println(values)
values3 := pq.GetAround(5) // values3 = [<nil>, 5, 4]
log.Println(values3)
iter := pq.Iterator() // Next 大到小 从root节点起始
log.Println(pq.String())
2019-07-18 06:57:44 +00:00
// log.Println(iter.Value()) 直接使用会报错,
iter.ToHead()
iter.Next()
log.Println(iter.Value()) // 起始最大值. true 5
log.Println(iter.Prev(), iter.Value()) // false 5
2019-07-18 06:57:44 +00:00
2019-07-18 07:00:20 +00:00
// Prev 大到小
log.Println(iter.Next(), iter.Value()) // true 4
2019-07-18 06:57:44 +00:00
}
2019-07-18 03:06:39 +00:00
```