Created
February 10, 2023 01:42
-
-
Save kaigouthro/36fa53132000fbd6178bfc92e1a650ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=5 | |
library("keyed_primatives") | |
export type float_item | |
string key = '' | |
float val = 0. | |
export type float_dict | |
float_item[] content | |
export type int_item | |
string key = '' | |
int val = 0 | |
export type int_dict | |
int_item[] content | |
export type string_item | |
string key = '' | |
string val = '' | |
export type string_dict | |
string_item[] content | |
export type bool_item | |
string key = '' | |
bool val = na | |
export type bool_dict | |
bool_item[] content | |
export new ( string key , float val ) => float_item.new (key,val) | |
export method rekey ( float_item this , string key ) => this.key := key | |
export method reval ( float_item this , float val ) => this.val := val | |
export method count ( float_dict dict ) => array.size (dict.content) | |
export method item ( float_dict dict , int index ) => (index >= 0 and index < array.size(dict.content)) ? array.get(dict.content , index ) : na | |
export method set(float_dict d, string key, float val)=> | |
int index = -1 | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
d.item(i).val := val | |
break | |
index := i | |
if index < 0 | |
array.push(d.content, float_item.new(key,val)) | |
export method get(float_dict d, string key)=> | |
float out = na | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
out := d.item(i).val | |
out | |
export method get_keys(float_dict d)=> | |
string[] keys = array.new_string() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(keys, d.item(i).key) | |
keys | |
export method get_values(float_dict d)=> | |
float[] values = array.new_float() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(values, d.item(i).val) | |
values | |
export method get_items(float_dict d)=> | |
float_item[] content = array.new<float_item>() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(content, d.item(i)) | |
content | |
export int_item( string key, int val) => int_item.new(key,val) | |
export method rekey( int_item this, string key) => this.key := key | |
export method reval( int_item this, int val) => this.val := val | |
export method count(int_dict dict) => array.size(dict.content) | |
export method item(int_dict dict, int index) => (index >= 0 and index < array.size(dict.content)) ? array.get(dict.content , index ) : na | |
export method set(int_dict d, string key, int val)=> | |
int index = -1 | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
d.item(i).val := val | |
break | |
index := i | |
if index < 0 | |
array.push(d.content, int_item.new(key,val)) | |
export method get(int_dict d, string key)=> | |
int out = na | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
out := d.item(i).val | |
out | |
export method get_keys(int_dict d)=> | |
string[] keys = array.new_string() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(keys, d.item(i).key) | |
keys | |
export method get_values(int_dict d)=> | |
int[] values = array.new_int() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(values, d.item(i).val) | |
values | |
export method get_items(int_dict d)=> | |
int_item[] content = array.new<int_item>() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(content, d.item(i)) | |
content | |
export string_item( string key, string val) => string_item.new(key,val) | |
export method rekey( string_item this, string key) => this.key := key | |
export method reval( string_item this, string val) => this.val := val | |
export method count(string_dict dict) => array.size(dict.content) | |
export method item(string_dict dict, int index) => (index >= 0 and index < array.size(dict.content)) ? array.get(dict.content , index ) : na | |
export method get_keys(string_dict d)=> | |
string[] keys = array.new_string() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(keys, d.item(i).key) | |
keys | |
export method get_values(string_dict d)=> | |
string[] values = array.new_string() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(values, d.item(i).val) | |
values | |
export method get_items(string_dict d)=> | |
string_item[] content = array.new<string_item>() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(content, d.item(i)) | |
content | |
export method set(string_dict d, string key, string val)=> | |
int index = -1 | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
d.item(i).val := val | |
break | |
index := i | |
if index < 0 | |
array.push(d.content, string_item.new(key,val)) | |
export method get(string_dict d, string key)=> | |
string out = na | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
out := d.item(i).val | |
out | |
export bool_item( string key, bool val) => bool_item.new(key,val) | |
export method rekey( bool_item this, string key) => this.key := key | |
export method reval( bool_item this, bool val) => this.val := val | |
export method count(bool_dict dict) => array.size(dict.content) | |
export method item(bool_dict dict, int index) => (index >= 0 and index < array.size(dict.content)) ? array.get(dict.content , index ) : na | |
export method get_keys(bool_dict d)=> | |
string[] keys = array.new_string() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(keys, d.item(i).key) | |
keys | |
export method get_values(bool_dict d)=> | |
bool[] values = array.new_bool() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(values, d.item(i).val) | |
values | |
export method get_items(bool_dict d)=> | |
bool_item[] content = array.new<bool_item>() | |
for i = 0 to array.size(d.content) - 1 | |
array.push(content, d.item(i)) | |
content | |
export method set(bool_dict d, string key, bool val)=> | |
int index = -1 | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
d.item(i).val := val | |
break | |
index := i | |
if index < 0 | |
array.push(d.content, bool_item.new(key,val)) | |
export method get(bool_dict d, string key)=> | |
bool out = na | |
for i = 0 to array.size(d.content) - 1 | |
if d.item(i).key == key | |
out := d.item(i).val | |
out | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment