
algo
is a Golang library featuring a variety of efficient and well-optimized algorithms designed for diverse problem-solving needs.
The purpose of this package is to implement specific algorithms in a simplified manner based on formulaic documentation available on Wikipedia or other sources. These algorithms
been validated in terms of functionality and testing.
π Available Algorithms
π Installation >= go 1.19
go get -u github.com/Ja7ad/algo
β
Usage Example
Hereβs how you can use the Random Weighted Selection algorithm:
package main
import (
"fmt"
"log"
"github.com/Ja7ad/algo/rws"
)
func main() {
// Define items with weights
weightedItems := map[int]string{
3: "Apple",
1: "Banana",
6: "Cherry",
}
// Create a selector
selector, err := rws.NewWeightedSelector(weightedItems)
if err != nil {
log.Fatal(err)
}
// Pick a random item
selectedItem, _ := selector.Pick()
fmt.Println("Selected:", selectedItem)
}
For more details, check the Random Weighted Selection documentation.
π Contribution
We welcome contributions! Feel free to submit pull requests, open issues, or suggest new algorithms.
π License
This project is licensed under the MIT License.