RangeMap

module
v0.0.0-...-2427052 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: Apache-2.0

README

Range map

Very useful when its needed to make a map from a key ranging from a set of values, for example:

from to value
0 9 "Ones"
10 99 "Tens"
100 999 "Hundreds"
1000 9999 "Thousands"

Code example:

package main

import "github.com/AndrejfSantos/RangeMap/rangemap"

func main()  {

    rangeMap := rangemap.RangeMap[string]{}
    rangeMap.Put(0, 9, "Ones")
    rangeMap.Put(10, 99, "Tens")
    rangeMap.Put(100, 999, "Hundreds")    
    rangeMap.Put(1000, 9999, "Thousands")

    value, found := rangeMap.Get(-1)  // returns nil , false
    value, found = rangeMap.Get(1)    // returns "Ones" , true
    value, found = rangeMap.Get(42)   // returns "Tens" , true
    value, found = rangeMap.Get(666)  // returns "Hundreds" , true
    value, found = rangeMap.Get(1337) // returns "Thousands" , true

}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL