key_value

package
v0.0.0-...-8ceac79 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

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 key is a string, and value could be anything. It defines additional functions that returns 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 internal it uses map for optimization.

Index

Constants

View Source
const ListLength = 1_000_000

ListLength 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 Empty

func Empty() KeyValue

Empty KeyValue is created

func New

func New(keyValue map[string]interface{}) KeyValue

New KeyValue from golang's map.

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 key value

func (KeyValue) Bytes

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

Bytes serializes k into the series of bytes

func (KeyValue) Exist

func (k KeyValue) Exist(name string) error

func (KeyValue) GetBigNumber

func (k KeyValue) GetBigNumber(name string) (*big.Int, error)

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

func (KeyValue) GetBoolean

func (k KeyValue) GetBoolean(name string) (bool, error)

GetBoolean extracts the value as boolean

func (KeyValue) GetFloat64

func (k KeyValue) GetFloat64(name string) (float64, error)

GetFloat64 extracts the float number

func (KeyValue) GetKeyValue

func (k KeyValue) GetKeyValue(name string) (KeyValue, error)

GetKeyValue returns the parameter as a KeyValue

func (KeyValue) GetKeyValueList

func (k KeyValue) GetKeyValueList(name string) ([]KeyValue, error)

GetKeyValueList returns the parameter as a slice of map:

[]key_value.KeyValue

func (KeyValue) GetString

func (k KeyValue) GetString(name string) (string, error)

GetString returns the parameter as a string

func (KeyValue) GetStringList

func (k KeyValue) GetStringList(name string) ([]string, error)

GetStringList returns the list of strings

func (KeyValue) GetUint64

func (k KeyValue) GetUint64(name string) (uint64, error)

GetUint64 returns the parameter as an uint64

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) Set

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

Set the parameter in KeyValue

func (KeyValue) String

func (k KeyValue) String() (string, error)

Returns the serialized key-value as a string

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 LIST_LENGTH amount 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) 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. The value should be passed by pointer

func (*List) IsEmpty

func (q *List) IsEmpty() bool

func (*List) IsFull

func (q *List) IsFull() bool

func (*List) Len

func (q *List) Len() int

func (*List) List

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

Jump to

Keyboard shortcuts

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