https://github.com/cookiengineer/golpm
:rocket: LPM Tries and Hash Set Maps for Go
https://github.com/cookiengineer/golpm
data-structures-and-algorithms go golang longest-prefix-match lpm-hashmap lpm-trie
Last synced: 2 months ago
JSON representation
:rocket: LPM Tries and Hash Set Maps for Go
- Host: GitHub
- URL: https://github.com/cookiengineer/golpm
- Owner: cookiengineer
- License: agpl-3.0
- Created: 2024-02-17T09:52:25.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-17T12:40:38.000Z (over 1 year ago)
- Last Synced: 2025-03-28T12:11:35.328Z (2 months ago)
- Topics: data-structures-and-algorithms, go, golang, longest-prefix-match, lpm-hashmap, lpm-trie
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go LPM Trie and Go LPM Hash Map Library
This is a standalone library that implements the `longest prefix match` algorithm
for use with `Subnets`, `CIDRs` and `IPs`. It supports both `IPv4` and `IPv6`
prefix notations.## Usage
The [examples](/examples) folder contains usage examples.
As pointed out in my [Web Log article about LPM Tries](https://cookie.engineer/weblog/articles/you-dont-need-lpm-tries.html)
it is heavily recommended to use the `HashMap` wherever possible, as it's the
most efficient way to represent a `longest prefix match` respecting data
structure.```go
import "github.com/cookiengineer/lpm"
import "fmt"hashmap := lpm.NewHashMap()
hashmap.Insert("192.168.0.0/24")
hashmap.Insert("192.169.128.0/17")
hashmap.Insert("192.169.0.0/16")
hashmap.Insert("192.169.0.0/24")fmt.Println("parent of 192.168.0.123 is:", hashmap.Search("192.168.0.123/32"))
fmt.Println("parent of 192.169.0.123 is:", hashmap.Search("192.169.0.123/32"))fmt.Println("")
fmt.Println("hashmap:")
hashmap.Print()
```## License
AGPL3