golang 数据结构.
Go to file
2020-03-23 10:58:15 +08:00
compare add []byte []rune compare 2020-03-04 11:24:36 +08:00
list 更换package结构 2020-03-21 08:43:29 +08:00
map 更换package结构 2020-03-21 08:43:29 +08:00
priority_queue 把一些运算优化为位运算. 2020-03-23 10:56:53 +08:00
priority_queuekey 把一些运算优化为位运算. 2020-03-23 10:56:53 +08:00
set 更换package结构 2020-03-21 08:43:29 +08:00
sparse_array benchmark 转移到其他仓库 2019-05-08 17:33:58 +08:00
stack 更换package结构 2020-03-21 08:43:29 +08:00
tree Merge branch 'feature/lsv' of https://github.com/474420502/focus into feature/lsv 2020-03-23 10:58:15 +08:00
utils add RemoveNode IndexNode method 2019-12-23 00:43:25 +08:00
.gitignore new file: .gitignore 2019-05-08 10:42:51 +08:00
for_test.go TODO: assertImplementation, add interface InsertIf 组合等 2019-07-25 02:30:55 +08:00
go.mod 更换package结构 2020-03-21 08:43:29 +08:00
go.sum 更换package结构 2020-03-21 08:43:29 +08:00
interface.go TODO: assertImplementation, add interface InsertIf 组合等 2019-07-25 02:30:55 +08:00
LICENSE new file: .gitignore 2019-05-08 10:42:51 +08:00
README.md save some code; 2020-03-20 16:57:21 +08:00
TODO finish TODO 2020-03-23 00:48:59 +08:00

structure

暂时没时间整理, 后期才整理完整.

PriorityQueue

package main

import (
    "log"

    "github.com/474420502/focus/compare"
    pqueuekey "github.com/474420502/focus/priority_queuekey"
)

func main() {
    pq := New(compare.Int)
    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())
    // log.Println(iter.Value()) 直接使用会报错,
    iter.ToHead()
    iter.Next()
    log.Println(iter.Value())              // 起始最大值. true 5
    log.Println(iter.Prev(), iter.Value()) // false 5

    // Prev 大到小
    log.Println(iter.Next(), iter.Value()) // true 4

}