key_value

package
v0.0.0-...-0cc5829 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MPL-2.0 Imports: 7 Imported by: 26

Documentation

Overview

Package key_value defines the custom map and its additional functions.

The package defines two different data types:

  • KeyValue is the map where the kv is a string, and the value could be anything. It defines additional functions that return the value converted to the desired type.
  • List is the list of elements but based on the map. For the user, the list acts as the array. However, internally it uses a map for optimization.

Index

Constants

View Source
const DefaultCap uint = 1_000_000

DefaultCap max amount of data that this list could keep

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValue

type KeyValue map[string]interface{}

KeyValue is the golang's map with the functions. Important to know that, no value could be `nil`.

func New

func New() KeyValue

New empty KeyValue is created

func NewFromInterface

func NewFromInterface(i interface{}) (KeyValue, error)

NewFromInterface converts the data structure "i" to KeyValue In order to do that, it serializes data structure using json

The data structures should define the json variable names

func NewFromString

func NewFromString(s string) (KeyValue, error)

NewFromString converts the s string with a json decoder into the kv value

func (KeyValue) BigIntValue

func (k KeyValue) BigIntValue(key string) (*big.Int, error)

BigIntValue extracts the value as the parsed large number. Use this if the number size is more than 64 bits.

func (KeyValue) BoolValue

func (k KeyValue) BoolValue(key string) (bool, error)

BoolValue extracts the value as boolean

func (KeyValue) Bytes

func (k KeyValue) Bytes() ([]byte, error)

Bytes serialize k into the series of bytes

func (KeyValue) Exist

func (k KeyValue) Exist(key string) (exists bool)

func (KeyValue) Float64Value

func (k KeyValue) Float64Value(key string) (float64, error)

Float64Value extracts the float number

func (KeyValue) Interface

func (k KeyValue) Interface(i interface{}) error

Interface representation of this KeyValue

func (KeyValue) Map

func (k KeyValue) Map() map[string]interface{}

Map converts the k to golang's map

func (KeyValue) MapString

func (k KeyValue) MapString() map[string]string

MapString returns the map with the string values only

func (KeyValue) NestedListValue

func (k KeyValue) NestedListValue(key string) ([]KeyValue, error)

NestedListValue returns the parameter as a slice of map:

[]key_value.KeyValue

func (KeyValue) NestedValue

func (k KeyValue) NestedValue(key string) (KeyValue, error)

NestedValue returns the parameter as a KeyValue

func (KeyValue) Set

func (k KeyValue) Set(key string, value interface{}) KeyValue

Set the parameter in KeyValue

func (KeyValue) String

func (k KeyValue) String() string

Returns the serialized kv-value as a string

func (KeyValue) StringValue

func (k KeyValue) StringValue(key string) (string, error)

StringValue returns the parameter as a string

func (KeyValue) StringsValue

func (k KeyValue) StringsValue(key string) ([]string, error)

StringsValue returns the list of strings

func (KeyValue) Uint64Value

func (k KeyValue) Uint64Value(key string) (uint64, error)

Uint64Value returns the parameter as an uint64

type List

type List struct {
	// contains filtered or unexported fields
}

func NewList

func NewList() *List

NewList returns a new list of the elements that could contain maximum DefaultCap of elements.

The queue has a function that returns the first element by taking it out from the list.

The added elements attached after the last element.

func (*List) Add

func (q *List) Add(key interface{}, value interface{}) error

Add a new element to the queue. If the element type is not the same as the expected type, then It will silently drop it. Silently drop if the queue is full

func (*List) Cap

func (q *List) Cap() uint

Cap returns the capacity of the list

func (*List) Exist

func (q *List) Exist(key interface{}) bool

func (*List) Get

func (q *List) Get(key interface{}) (interface{}, error)

Get the element in the list to the value. Pointer should pass the value

func (*List) GetFirst

func (q *List) GetFirst() (interface{}, interface{}, error)

GetFirst returns the first added element. Returns the kv, value and error if it can not find it.

func (*List) IsEmpty

func (q *List) IsEmpty() bool

func (*List) IsFull

func (q *List) IsFull() bool

func (*List) Len

func (q *List) Len() uint

func (*List) List

func (q *List) List() map[interface{}]interface{}

func (*List) SetCap

func (q *List) SetCap(newCap uint) error

SetCap updates the capacity of the list. If the list has more elements than newCap, it throws an error.

func (*List) Take

func (q *List) Take(key interface{}) (interface{}, error)

Take is a Get, but removes the returned element from the list

func (*List) TakeFirst

func (q *List) TakeFirst() (interface{}, interface{}, error)

TakeFirst is a GetFirst, but removes the element from the list

Jump to

Keyboard shortcuts

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