rangemap

package module
v0.0.0-...-6e51546 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 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"

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

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RangeMap

type RangeMap[T any] struct {
	// contains filtered or unexported fields
}

RangeMap - A Map that is very useful when its needed to make a map from a key ranging from a set of values

func (*RangeMap[T]) Get

func (m *RangeMap[T]) Get(key int) (value *T, ok bool)

Get - returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*RangeMap[T]) Put

func (m *RangeMap[T]) Put(from int, to int, value T)

Put - stores the value for a key that will be within the range of from and to

Jump to

Keyboard shortcuts

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