r9e

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

RamStorage (r9e)

CodeQL Analysis Gosec Unit Test Release GitHub go.mod Go version license codecov release Go Reference

RamStorage (r9e) is a Thread-Safe Golang library used for memory storage with convenient methods to store and retrieve data.

This is focused on usability and simplicity rather than performance, but it doesn't mean that it's not fast. Discover it for yourself

Overview

Taking advantage of the Golang Generics and internal golang data structures, RamStorage (r9e) provides a simple way to store and retrieve data.

The goal is to provide an easy way to use a library to store and retrieve data from memory using an API and data structures simples and.

This package doesn't have any dependencies, so it's easy to use and maintain, only golang standard library is required.

Available Containers
Documentation

Official documentation is available on pkg.go.dev -> slashdevops/r9e

Installing

Latest release:

go get -u github.com/slashdevops/r9e@latest

Specific release:

go get -u github.com/slashdevops/r9e@vx.y.z

Adding it to your project:

import "github.com/slashdevops/r9e"

Example

package main

import (
  "fmt"

  "github.com/slashdevops/r9e"
)

func main() {
  type MathematicalConstants struct {
    Name  string
    Value float64
  }

  // With Capacity allocated
  // kv := r9e.NewMapKeyValue[string, MathematicalConstants](r9e.WithCapacity(5))
  kv := r9e.NewMapKeyValue[string, MathematicalConstants]()

  kv.Set("pi", MathematicalConstants{"Archimedes' constant", 3.141592})
  kv.Set("e", MathematicalConstants{"Euler number, Napier's constant", 2.718281})
  kv.Set("γ", MathematicalConstants{"Euler number, Napier's constant", 0.577215})
  kv.Set("Φ", MathematicalConstants{"Golden ratio constant", 1.618033})
  kv.Set("ρ", MathematicalConstants{"Plastic number ρ (or silver constant)", 2.414213})

  kvFilteredValues := kv.FilterValue(func(value MathematicalConstants) bool {
    return value.Value > 2.0
  })

  fmt.Println("Mathematical Constants:")
  kvFilteredValues.ForEach(func(key string, value MathematicalConstants) {
    fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
  })

  fmt.Printf("\n")
  fmt.Printf("The most famous mathematical constant:\n")
  fmt.Printf("Name: %v, Value: %v\n", kv.Get("pi").Name, kv.Get("pi").Value)

  lst := kv.SortValues(func(value1, value2 MathematicalConstants) bool {
    return value1.Value > value2.Value
  })

  fmt.Printf("\n")
  fmt.Printf("The most famous mathematical constant sorted by value:\n")
  for i, value := range lst {
    fmt.Printf("i: %v, Name: %v, Value: %v\n", i, value.Name, value.Value)
  }

  kvHigh, kvLow := kv.Partition(func(key string, value MathematicalConstants) bool {
    return value.Value > 2.5
  })

  fmt.Printf("\n")
  fmt.Printf("Mathematical constants which value is greater than 2.5:\n")
  kvHigh.ForEach(func(key string, value MathematicalConstants) {
    fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
  })

  fmt.Printf("\n")
  fmt.Printf("Mathematical constants which value is less than 2.5:\n")
  kvLow.ForEach(func(key string, value MathematicalConstants) {
    fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
  })
}

Output:

Mathematical Constants:
Key: ρ, Name: Plastic number ρ (or silver constant), Value: 2.414213
Key: e, Name: Euler number, Napier's constant, Value: 2.718281
Key: pi, Name: Archimedes' constant, Value: 3.141592

The most famous mathematical constant:
Name: Archimedes' constant, Value: 3.141592

The most famous mathematical constants sorted by value:
i: 0, Name: Archimedes' constant, Value: 3.141592
i: 1, Name: Euler number, Napier's constant, Value: 2.718281
i: 2, Name: Plastic number ρ (or silver constant), Value: 2.414213
i: 3, Name: Golden ratio constant, Value: 1.618033
i: 4, Name: Euler number, Napier's constant, Value: 0.577215

Mathematical constants which value is greater than 2.5:
Key: pi, Name: Archimedes' constant, Value: 3.141592
Key: e, Name: Euler number, Napier's constant, Value: 2.718281

Mathematical constants which value is less than 2.5:
Key: Φ, Name: Golden ratio constant, Value: 1.618033
Key: ρ, Name: Plastic number ρ (or silver constant), Value: 2.414213
Key: γ, Name: Euler number, Napier's constant, Value: 0.577215

How Fast?

Discover it for yourself:

git clone git@github.com:slashdevops/r9e.git
cd r9e/
make bench

License

RamStorage (r9e) is released under the Apache License Version 2.0:

Documentation

Overview

Package r9e provides a collection of memory store containers.

Available Containers

* [MapKeyValue[K comparable, T any]](https://pkg.go.dev/github.com/slashdevops/r9e#MapKeyValue) using sync.RWMutex * [SMapKeyValue[K comparable, T any]](https://pkg.go.dev/github.com/slashdevops/r9e#SMapKeyValue) using sync.Map

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapKeyValue

type MapKeyValue[K comparable, T any] struct {
	// contains filtered or unexported fields
}

MapKeyValue is a generic key-value store container that is thread-safe. This use a golang native map data structure as underlying data structure and a mutex to protect the data.

Example (Basic)
package main

import (
	"fmt"

	"github.com/slashdevops/r9e"
)

func main() {
	type MathematicalConstants struct {
		Name  string
		Value float64
	}

	// With Capacity allocated
	// kv := r9e.NewMapKeyValue[string, MathematicalConstants](r9e.WithCapacity(5))
	kv := r9e.NewMapKeyValue[string, MathematicalConstants]()

	kv.Set("pi", MathematicalConstants{"Archimedes' constant", 3.141592})
	kv.Set("e", MathematicalConstants{"Euler number, Napier's constant", 2.718281})
	kv.Set("γ", MathematicalConstants{"Euler number, Napier's constant", 0.577215})
	kv.Set("Φ", MathematicalConstants{"Golden ratio constant", 1.618033})
	kv.Set("ρ", MathematicalConstants{"Plastic number ρ (or silver constant)", 2.414213})

	kvFilteredValues := kv.FilterValue(func(value MathematicalConstants) bool {
		return value.Value > 2.0
	})

	fmt.Println("Mathematical Constants:")
	kvFilteredValues.ForEach(func(key string, value MathematicalConstants) {
		fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
	})

	fmt.Printf("\n")
	fmt.Printf("The most famous mathematical constant:\n")
	fmt.Printf("Name: %v, Value: %v\n", kv.Get("pi").Name, kv.Get("pi").Value)

	lst := kv.SortValues(func(value1, value2 MathematicalConstants) bool {
		return value1.Value > value2.Value
	})

	fmt.Printf("\n")
	fmt.Printf("The most famous mathematical constant sorted by value:\n")
	for i, value := range lst {
		fmt.Printf("i: %v, Name: %v, Value: %v\n", i, value.Name, value.Value)
	}

	kvHigh, kvLow := kv.Partition(func(key string, value MathematicalConstants) bool {
		return value.Value > 2.5
	})

	fmt.Printf("\n")
	fmt.Printf("Mathematical constants which value is greater than 2.5:\n")
	kvHigh.ForEach(func(key string, value MathematicalConstants) {
		fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
	})

	fmt.Printf("\n")
	fmt.Printf("Mathematical constants which value is less than 2.5:\n")
	kvLow.ForEach(func(key string, value MathematicalConstants) {
		fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
	})
}
Output:

func NewMapKeyValue

func NewMapKeyValue[K comparable, T any](options ...MapKeyValueOptions) *MapKeyValue[K, T]

NewMapKeyValue returns a new MapKeyValue container.

Example (Int)

Using int data types

kv := NewMapKeyValue[int, int]()

kv.Set(1, 8096)
kv.Set(25, 4096)

fmt.Printf("key 1: %v, value 1: %v\nkey 2: %v, value 2: %v", 1, kv.Get(1), 25, kv.Get(25))
Output:

key 1: 1, value 1: 8096
key 2: 25, value 2: 4096
Example (Struct)

Using string as key and struct as value data types.

type testStruct struct {
	Name  string
	value float64
}

MathConstants := NewMapKeyValue[string, testStruct]()

MathConstants.Set("Archimedes", testStruct{"This is Archimedes' Constant (Pi)", 3.1415})
MathConstants.Set("Euler", testStruct{"This is Euler's Number (e)", 2.7182})
MathConstants.Set("Golden Ratio", testStruct{"This is The Golden Ratio", 1.6180})

fmt.Printf("name: %v, value: %v\n", MathConstants.Get("Archimedes").Name, MathConstants.Get("Archimedes").value)
Output:

name: This is Archimedes' Constant (Pi), value: 3.1415

func (*MapKeyValue[K, T]) Clear

func (r *MapKeyValue[K, T]) Clear()

Clear deletes all key-value pairs stored in the container.

func (*MapKeyValue[K, T]) Clone

func (r *MapKeyValue[K, T]) Clone() *MapKeyValue[K, T]

Clone returns a new MapKeyValue with a copy of the underlying data.

func (*MapKeyValue[K, T]) CloneAndClear

func (r *MapKeyValue[K, T]) CloneAndClear() *MapKeyValue[K, T]

CloneAndClear returns a new MapKeyValue with a copy of the underlying data and clears the container.

func (*MapKeyValue[K, T]) ContainsKey

func (r *MapKeyValue[K, T]) ContainsKey(key K) bool

ContainsKey returns true if the key is in the container.

func (*MapKeyValue[K, T]) ContainsValue

func (r *MapKeyValue[K, T]) ContainsValue(value T) bool

ContainsValue returns true if the value is in the container.

func (*MapKeyValue[K, T]) DeepEqual

func (r *MapKeyValue[K, T]) DeepEqual(kv *MapKeyValue[K, T]) bool

DeepEqual returns true if the given kv is deep equal to the MapKeyValue container

func (*MapKeyValue[K, T]) Delete

func (r *MapKeyValue[K, T]) Delete(key K)

Delete deletes the value associated with the key.

func (*MapKeyValue[K, T]) Filter

func (r *MapKeyValue[K, T]) Filter(fn func(key K, value T) bool) *MapKeyValue[K, T]

Filter returns a new MapKeyValue after applying the given function fn to each key-value pair.

func (*MapKeyValue[K, T]) FilterKey

func (r *MapKeyValue[K, T]) FilterKey(fn func(key K) bool) *MapKeyValue[K, T]

FilterKey returns a new MapKeyValue after applying the given function fn to each key.

func (*MapKeyValue[K, T]) FilterValue

func (r *MapKeyValue[K, T]) FilterValue(fn func(value T) bool) *MapKeyValue[K, T]

FilterValue returns a new MapKeyValue after applying the given function fn to each value.

func (*MapKeyValue[K, T]) ForEach

func (r *MapKeyValue[K, T]) ForEach(fn func(key K, value T))

ForEach calls the given function for each key-value pair in the container.

func (*MapKeyValue[K, T]) ForEachKey

func (r *MapKeyValue[K, T]) ForEachKey(fn func(key K))

ForEachKey calls the given function for each key in the container.

func (*MapKeyValue[K, T]) ForEachValue

func (r *MapKeyValue[K, T]) ForEachValue(fn func(value T))

ForEachValue calls the given function for each value in the container.

func (*MapKeyValue[K, T]) Get

func (r *MapKeyValue[K, T]) Get(key K) T

Get returns the value associated with the key. If the key does not exist, return zero value of the type.

func (*MapKeyValue[K, T]) GetAnDelete

func (r *MapKeyValue[K, T]) GetAnDelete(key K) (T, bool)

GetAnDelete returns the value associated with the key and delete it if the key exist if the key doesn't exist return the given key value false

func (*MapKeyValue[K, T]) GetAndCheck added in v0.0.2

func (r *MapKeyValue[K, T]) GetAndCheck(key K) (T, bool)

GetAndCheck returns the value associated with the key if this exist also a boolean value if this exist of not.

func (*MapKeyValue[K, T]) IsEmpty

func (r *MapKeyValue[K, T]) IsEmpty() bool

IsEmpty returns true if the container is empty.

func (*MapKeyValue[K, T]) IsFull

func (r *MapKeyValue[K, T]) IsFull() bool

IsFull returns true if the container has elements.

func (*MapKeyValue[K, T]) Key

func (r *MapKeyValue[K, T]) Key(key K) K

Get returns the key value associated with the key.

func (*MapKeyValue[K, T]) Keys

func (r *MapKeyValue[K, T]) Keys() []K

Keys returns all keys stored in the container.

func (*MapKeyValue[K, T]) Map

func (r *MapKeyValue[K, T]) Map(fn func(key K, value T) (newKey K, newValue T)) *MapKeyValue[K, T]

Map returns a new MapKeyValue after applying the given function fn to each key-value pair.

func (*MapKeyValue[K, T]) MapKey

func (r *MapKeyValue[K, T]) MapKey(fn func(key K) K) *MapKeyValue[K, T]

MapKey returns a new MapKeyValue after applying the given function fn to each key.

func (*MapKeyValue[K, T]) MapValue

func (r *MapKeyValue[K, T]) MapValue(fn func(value T) T) *MapKeyValue[K, T]

MapValue returns a new MapKeyValue after applying the given function fn to each value.

func (*MapKeyValue[K, T]) Partition

func (r *MapKeyValue[K, T]) Partition(fn func(key K, value T) bool) (match, others *MapKeyValue[K, T])

Partition returns two new MapKeyValue. One with all the elements that satisfy the predicate and another with the rest. The predicate is applied to each element.

func (*MapKeyValue[K, T]) PartitionKey

func (r *MapKeyValue[K, T]) PartitionKey(fn func(key K) bool) (match, others *MapKeyValue[K, T])

PartitionKey returns two new MapKeyValue. One with all the elements that satisfy the predicate and another with the rest. The predicate is applied to each key.

func (*MapKeyValue[K, T]) PartitionValue

func (r *MapKeyValue[K, T]) PartitionValue(fn func(value T) bool) (match, others *MapKeyValue[K, T])

PartitionValue returns two new MapKeyValue. One with all the elements that satisfy the predicate and another with the rest. The predicate is applied to each value.

func (*MapKeyValue[K, T]) Set

func (r *MapKeyValue[K, T]) Set(key K, value T)

Set sets the value associated with the key.

func (*MapKeyValue[K, T]) Size

func (r *MapKeyValue[K, T]) Size() int

Size returns the number of key-value pairs stored in the container.

func (*MapKeyValue[K, T]) SortKeys

func (r *MapKeyValue[K, T]) SortKeys(sortFn func(key1, key2 K) bool) []*K

SortKeys returns a []*K (keys) after sorting the keys using the given sortFn function.

func (*MapKeyValue[K, T]) SortValues

func (r *MapKeyValue[K, T]) SortValues(sortFn func(value1, value2 T) bool) []*T

SortValues returns a []*T (values) after sorting the values using given function sortFn.

func (*MapKeyValue[K, T]) Values

func (r *MapKeyValue[K, T]) Values() []T

Values returns all values stored in the container.

type MapKeyValueOptions

type MapKeyValueOptions func(*mapKeyValueOptions)

MapKeyValueOptions are the options for MapKeyValue container.

func WithCapacity

func WithCapacity(size int) MapKeyValueOptions

WithCapacity sets the initial capacity allocation of the MapKeyValue container.

type SMapKeyValue added in v0.0.2

type SMapKeyValue[K comparable, T any] struct {
	// contains filtered or unexported fields
}

SMapKeyValue is a generic key-value store container that is thread-safe. This use a golang native sync.Map data structure as underlying data structure.

Example (Basic)
package main

import (
	"fmt"

	"github.com/slashdevops/r9e"
)

func main() {
	type MathematicalConstants struct {
		Name  string
		Value float64
	}

	kv := r9e.NewSMapKeyValue[string, MathematicalConstants]()

	kv.Set("pi", MathematicalConstants{"Archimedes' constant", 3.141592})
	kv.Set("e", MathematicalConstants{"Euler number, Napier's constant", 2.718281})
	kv.Set("γ", MathematicalConstants{"Euler number, Napier's constant", 0.577215})
	kv.Set("Φ", MathematicalConstants{"Golden ratio constant", 1.618033})
	kv.Set("ρ", MathematicalConstants{"Plastic number ρ (or silver constant)", 2.414213})

	kvFilteredValues := kv.FilterValue(func(value MathematicalConstants) bool {
		return value.Value > 2.0
	})

	fmt.Println("Mathematical Constants:")
	kvFilteredValues.ForEach(func(key string, value MathematicalConstants) {
		fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
	})

	fmt.Printf("\n")
	fmt.Printf("The most famous mathematical constant:\n")
	fmt.Printf("Name: %v, Value: %v\n", kv.Get("pi").Name, kv.Get("pi").Value)

	lst := kv.SortValues(func(value1, value2 MathematicalConstants) bool {
		return value1.Value > value2.Value
	})

	fmt.Printf("\n")
	fmt.Printf("The most famous mathematical constant sorted by value:\n")
	for i, value := range lst {
		fmt.Printf("i: %v, Name: %v, Value: %v\n", i, value.Name, value.Value)
	}

	kvHigh, kvLow := kv.Partition(func(key string, value MathematicalConstants) bool {
		return value.Value > 2.5
	})

	fmt.Printf("\n")
	fmt.Printf("Mathematical constants which value is greater than 2.5:\n")
	kvHigh.ForEach(func(key string, value MathematicalConstants) {
		fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
	})

	fmt.Printf("\n")
	fmt.Printf("Mathematical constants which value is less than 2.5:\n")
	kvLow.ForEach(func(key string, value MathematicalConstants) {
		fmt.Printf("Key: %v, Name: %v, Value: %v\n", key, value.Name, value.Value)
	})
}
Output:

func NewSMapKeyValue added in v0.0.2

func NewSMapKeyValue[K comparable, T any]() *SMapKeyValue[K, T]

NewSMapKeyValue returns a new SMapKeyValue container.

Example (Int)

Using int data types

kv := NewSMapKeyValue[int, int]()

kv.Set(1, 8096)
kv.Set(25, 4096)

fmt.Printf("key 1: %v, value 1: %v\nkey 2: %v, value 2: %v", 1, kv.Get(1), 25, kv.Get(25))
Output:

key 1: 1, value 1: 8096
key 2: 25, value 2: 4096
Example (Struct)

Using string as key and struct as value data types.

type STestStruct struct {
	Name  string
	value float64
}

MathConstants := NewSMapKeyValue[string, STestStruct]()

MathConstants.Set("Archimedes", STestStruct{"This is Archimedes' Constant (Pi)", 3.1415})
MathConstants.Set("Euler", STestStruct{"This is Euler's Number (e)", 2.7182})
MathConstants.Set("Golden Ratio", STestStruct{"This is The Golden Ratio", 1.6180})

fmt.Printf("name: %v, value: %v\n", MathConstants.Get("Archimedes").Name, MathConstants.Get("Archimedes").value)
Output:

name: This is Archimedes' Constant (Pi), value: 3.1415

func (*SMapKeyValue[K, T]) Clear added in v0.0.2

func (r *SMapKeyValue[K, T]) Clear()

Clear deletes all key-value pairs stored in the container.

func (*SMapKeyValue[K, T]) Clone added in v0.0.2

func (r *SMapKeyValue[K, T]) Clone() *SMapKeyValue[K, T]

Clone returns a new SMapKeyValue with a copy of the underlying data.

func (*SMapKeyValue[K, T]) CloneAndClear added in v0.0.2

func (r *SMapKeyValue[K, T]) CloneAndClear() *SMapKeyValue[K, T]

CloneAndClear returns a new SMapKeyValue with a copy of the underlying data and clears the container.

func (*SMapKeyValue[K, T]) ContainsKey added in v0.0.2

func (r *SMapKeyValue[K, T]) ContainsKey(key K) bool

ContainsKey returns true if the key is in the container.

func (*SMapKeyValue[K, T]) ContainsValue added in v0.0.2

func (r *SMapKeyValue[K, T]) ContainsValue(value T) bool

ContainsValue returns true if the value is in the container.

func (*SMapKeyValue[K, T]) DeepEqual added in v0.0.2

func (r *SMapKeyValue[K, T]) DeepEqual(kv *SMapKeyValue[K, T]) bool

DeepEqual returns true if the given kv is deep equal to the SMapKeyValue container

func (*SMapKeyValue[K, T]) Delete added in v0.0.2

func (r *SMapKeyValue[K, T]) Delete(key K)

Delete deletes the value associated with the key.

func (*SMapKeyValue[K, T]) Filter added in v0.0.2

func (r *SMapKeyValue[K, T]) Filter(fn func(key K, value T) bool) *SMapKeyValue[K, T]

Filter returns a new SMapKeyValue after applying the given function fn to each key-value pair.

func (*SMapKeyValue[K, T]) FilterKey added in v0.0.2

func (r *SMapKeyValue[K, T]) FilterKey(fn func(key K) bool) *SMapKeyValue[K, T]

FilterKey returns a new SMapKeyValue after applying the given function fn to each key.

func (*SMapKeyValue[K, T]) FilterValue added in v0.0.2

func (r *SMapKeyValue[K, T]) FilterValue(fn func(value T) bool) *SMapKeyValue[K, T]

FilterValue returns a new SMapKeyValue after applying the given function fn to each value.

func (*SMapKeyValue[K, T]) ForEach added in v0.0.2

func (r *SMapKeyValue[K, T]) ForEach(fn func(key K, value T))

ForEach calls the given function for each key-value pair in the container.

func (*SMapKeyValue[K, T]) ForEachKey added in v0.0.2

func (r *SMapKeyValue[K, T]) ForEachKey(fn func(key K))

ForEachKey calls the given function for each key in the container.

func (*SMapKeyValue[K, T]) ForEachValue added in v0.0.2

func (r *SMapKeyValue[K, T]) ForEachValue(fn func(value T))

ForEachValue calls the given function for each value in the container.

func (*SMapKeyValue[K, T]) Get added in v0.0.2

func (r *SMapKeyValue[K, T]) Get(key K) T

Get returns the value associated with the key. If the key does not exist, return zero value of the type.

func (*SMapKeyValue[K, T]) GetAnDelete added in v0.0.2

func (r *SMapKeyValue[K, T]) GetAnDelete(key K) (T, bool)

GetAnDelete returns the value associated with the key and delete it if the key exist if the key doesn't exist return the given key value false

func (*SMapKeyValue[K, T]) GetAndCheck added in v0.0.2

func (r *SMapKeyValue[K, T]) GetAndCheck(key K) (T, bool)

GetAndCheck returns the value associated with the key if this exist also a boolean value if this exist of not.

func (*SMapKeyValue[K, T]) IsEmpty added in v0.0.2

func (r *SMapKeyValue[K, T]) IsEmpty() bool

IsEmpty returns true if the container is empty.

func (*SMapKeyValue[K, T]) IsFull added in v0.0.2

func (r *SMapKeyValue[K, T]) IsFull() bool

IsFull returns true if the container has elements.

func (*SMapKeyValue[K, T]) Key added in v0.0.2

func (r *SMapKeyValue[K, T]) Key(key K) K

Get returns the key value associated with the key.

func (*SMapKeyValue[K, T]) Keys added in v0.0.2

func (r *SMapKeyValue[K, T]) Keys() []K

Keys returns all keys stored in the container.

func (*SMapKeyValue[K, T]) Map added in v0.0.2

func (r *SMapKeyValue[K, T]) Map(fn func(key K, value T) (newKey K, newValue T)) *SMapKeyValue[K, T]

Map returns a new SMapKeyValue after applying the given function fn to each key-value pair.

func (*SMapKeyValue[K, T]) MapKey added in v0.0.2

func (r *SMapKeyValue[K, T]) MapKey(fn func(key K) K) *SMapKeyValue[K, T]

MapKey returns a new SMapKeyValue after applying the given function fn to each key.

func (*SMapKeyValue[K, T]) MapValue added in v0.0.2

func (r *SMapKeyValue[K, T]) MapValue(fn func(value T) T) *SMapKeyValue[K, T]

MapValue returns a new SMapKeyValue after applying the given function fn to each value.

func (*SMapKeyValue[K, T]) Partition added in v0.0.2

func (r *SMapKeyValue[K, T]) Partition(fn func(key K, value T) bool) (match, others *SMapKeyValue[K, T])

Partition returns two new SMapKeyValue. One with all the elements that satisfy the predicate and another with the rest. The predicate is applied to each element.

func (*SMapKeyValue[K, T]) PartitionKey added in v0.0.2

func (r *SMapKeyValue[K, T]) PartitionKey(fn func(key K) bool) (match, others *SMapKeyValue[K, T])

PartitionKey returns two new SMapKeyValue. One with all the elements that satisfy the predicate and another with the rest. The predicate is applied to each key.

func (*SMapKeyValue[K, T]) PartitionValue added in v0.0.2

func (r *SMapKeyValue[K, T]) PartitionValue(fn func(value T) bool) (match, others *SMapKeyValue[K, T])

PartitionValue returns two new SMapKeyValue. One with all the elements that satisfy the predicate and another with the rest. The predicate is applied to each value.

func (*SMapKeyValue[K, T]) Set added in v0.0.2

func (r *SMapKeyValue[K, T]) Set(key K, value T)

Set sets the value associated with the key.

func (*SMapKeyValue[K, T]) Size added in v0.0.2

func (r *SMapKeyValue[K, T]) Size() int

Size returns the number of key-value pairs stored in the container.

func (*SMapKeyValue[K, T]) SortKeys added in v0.0.2

func (r *SMapKeyValue[K, T]) SortKeys(sortFn func(key1, key2 K) bool) []*K

SortKeys returns a []*K (keys) after sorting the keys using the given sortFn function.

func (*SMapKeyValue[K, T]) SortValues added in v0.0.2

func (r *SMapKeyValue[K, T]) SortValues(sortFn func(value1, value2 T) bool) []*T

SortValues returns a []*T (values) after sorting the values using given function sortFn.

func (*SMapKeyValue[K, T]) Values added in v0.0.2

func (r *SMapKeyValue[K, T]) Values() []T

Values returns all values stored in the container.

Jump to

Keyboard shortcuts

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy