Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace payload string to unsafe.Pointer #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Bienne
Copy link

@Bienne Bienne commented Nov 12, 2015

For example:
package main

import (
    "fmt"
    "github.com/thekvs/go-net-radix"
    "log"
    "unsafe"
)

type RateLimit struct {
    rate   int
    perSec int
}

func main() {
    rateLimits := make([]*RateLimit, 0, 0)

    rtree, err := netradix.NewNetRadixTree()
    if err != nil {
        panic(err)
    }

    rateLimit := &RateLimit{rate: 1000, perSec: 60}
    rateLimits = append(rateLimits, rateLimit)
    if err = rtree.Add("217.72.192.0/20", unsafe.Pointer(rateLimit)); err != nil {
        log.Fatal(err)
    }
    found, ptr, err := rtree.SearchBest("217.72.192.1")
    if err != nil {
        log.Fatal(err)
    }
    if found {
        rateLimit := (*RateLimit)(ptr)
        fmt.Printf("found: rate = %d, perSec = %d\n", rateLimit.rate, rateLimit.perSec)
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant