-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update readme and add an example
- Loading branch information
Showing
5 changed files
with
431 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
qradix "github.com/ihexxa/q-radix" | ||
) | ||
|
||
func main() { | ||
// create a new radix tree | ||
rTree := qradix.NewRTree() | ||
|
||
// insert value in any type with a string key | ||
_, err := rTree.Insert("key", "value") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// get the value by key | ||
val, err := rTree.Get("key") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// get all prefix matches of the key | ||
keyValues := rTree.GetAllPrefixMatches("key") | ||
if err != nil { | ||
panic(err) | ||
} | ||
for key, value := range keyValues { | ||
fmt.Println(key, value) | ||
} | ||
|
||
// get the longest prefix match of the key | ||
key, val, ok := rTree.GetBestMatch("key") | ||
fmt.Println(key, val, ok) | ||
|
||
// override the value of the key if it exists in the radix tree | ||
// and the old value will be returned if it exists | ||
oldValue, err := rTree.Insert("key", "newValue") | ||
ok = rTree.Remove("key") // remove the value from the radix tree | ||
fmt.Println(oldValue, err, ok) | ||
|
||
// get the size of the radix tree | ||
fmt.Println(rTree.Size()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
module github.com/ihexxa/q-radix | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect | ||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect | ||
github.com/golang/protobuf v1.4.3 // indirect | ||
github.com/google/uuid v1.1.2 // indirect | ||
github.com/kellydunn/go-art v0.0.1 // indirect | ||
github.com/spf13/cobra v1.1.1 // indirect | ||
github.com/stretchr/testify v1.6.1 // indirect | ||
) |
Oops, something went wrong.