StringStringHashmap
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gianlucac
// code took and readapted from: © ramihoteit321

//@version=5

//@description A simple implementation of a key string to string value dictionary in pinescript
library('StringStringHashmap', false)

//@function Create empty string-string dictionary
//@returns the indeces and elements of the dict
export create_ss_dict() =>
    indices = array.new_string(0)
    elements = array.new_string(0)

    [indices, elements]

//@function Add new key-value pair in the dictionary
//@param key string 
//@param value string
//@param i string[] the indices of the dictionary
//@param e string[] the element of the dictionary
export add_key_value(string key, string value, string[] i, string[] e) =>
    // check if key exists
    if array.indexof(i, key) == -1
        array.push(i, key)
        array.push(e, value)

//@function Get the value of the given key
//@param key string
//@param i string[] the indices of the dictionary
//@param e string[] the element of the dictionary
//@returns return the value of the fiven key
export get_value(string key, string[] i, string[] e) =>
    array.get(e, array.indexof(i, key))

//@function Change the value of the given key
//@param key string
//@param value string
//@param i string[] the indices of the dictionary
//@param e string[] the element of the dictionary
export change_value(string key,  string new_value , string[] i, string[] e) =>
    array.set(e, array.indexof(i, key), new_value)
