


If we want to use Int rather than String keys we need to switch to a different tree variant, but things otherwise work just the same. Here we use the int_red_black_map tree variant. Since that is a long name, we define the short synonym map for it within the script:
#!/usr/bin/mythryl
package map = int_red_black_map;
m = (map::empty: map::Map( String ));
m = map::set (m, 111, "Value1");
m = map::set (m, 222, "Value2");
m = map::set (m, 333, "Value3");
printf "%d -> %s\n" 111 (the (map::get (m, 111)) );
printf "%d -> %s\n" 222 (the (map::get (m, 222)) );
printf "%d -> %s\n" 333 (the (map::get (m, 333)) );
Here is the execution:
linux$ ./my-script
111 -> Value1
222 -> Value2
333 -> Value3
Same script rewritten to use Int values:
#!/usr/bin/mythryl
package map = int_red_black_map;
m = (map::empty: map::Map( Int ));
m = map::set (m, 111, 1111);
m = map::set (m, 222, 2222);
m = map::set (m, 333, 3333);
printf "%d -> %d\n" 111 (the (map::get (m, 111)) );
printf "%d -> %d\n" 222 (the (map::get (m, 222)) );
printf "%d -> %d\n" 333 (the (map::get (m, 333)) );
The run:
linux$ ./my-script
111 -> 1111
222 -> 2222
333 -> 3333
And now with float values:
#!/usr/bin/mythryl
package map = int_red_black_map;
m = (map::empty: map::Map( Float ));
m = map::set (m, 111, 0.111);
m = map::set (m, 222, 0.222);
m = map::set (m, 333, 0.333);
printf "%d -> %f\n" 111 (the (map::get (m, 111)) );
printf "%d -> %f\n" 222 (the (map::get (m, 222)) );
printf "%d -> %f\n" 333 (the (map::get (m, 333)) );
The run:
linux$ ./my-script
111 -> 0.111000
222 -> 0.222000
333 -> 0.333000


