The Wavelet Matrix implementation for Go..
package main
import (
"fmt"
"github.com/hideo55/go-waveletmatrix"
)
func main() {
src := []uint64{1, 3, 1, 4, 2, 1, 10}
wm, err := waveletmatrix.NewWM(src)
if err != nil {
// Failed to build wavelet-matrix
}
val, _ := wm.Lookup(3)
fmt.Println(val) // 4 ... src[3]
rank, _ := wm.Rank(2, 6)
fmt.Println(rank) // 1 ... The number of 2 in src[0, 6)
ranklt := wm.RankLessThan(3, 6)
fmt.Println(ranklt) /// 4 ... The frequency of characters c' < c in src[0, 6)
rankmt := wm.RankMoreThan(3, 6)
fmt.Println(rankmt) /// 1 ... The frequency of characters c' > c in the src[0, 6)
pos, _ := wm.Select(1, 3) // = 5 ... The third 1 appeared in src[5]
fmt.Println(pos)
}
Go 1.4 or later
MIT License