Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
mmadfox committed Dec 29, 2021
1 parent a7b493d commit ddc8591
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/sample/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"

h3geodist "github.com/mmadfox/go-h3geo-dist"
"github.com/uber/h3-go/v3"
)

func main() {
h3dist, err := h3geodist.New(h3geodist.Level5,
h3geodist.WithVNodes(8),
)
if err != nil {
panic(err)
}

_ = h3dist.Add("127.0.0.1")
_ = h3dist.Add("127.0.0.2")

cells, err := h3.HexRange(h3.FromString("854176affffffff"), 8)
if err != nil {
panic(err)
}

stats := make(map[string]int)
for _, cell := range cells {
level := h3.Resolution(cell)
dcell, ok := h3dist.Lookup(cell)
if ok {
fmt.Printf("cell=%v, level=%d, host=%s\n", dcell.H3ID, level, dcell.Host)
stats[dcell.Host]++
}
}

fmt.Println("Stats:")
for host, counter := range stats {
fmt.Printf("- host=%s, counter=%d\n", host, counter)
}
}

0 comments on commit ddc8591

Please sign in to comment.