PreviousUpNext

Red-Black Trees: Purity Test

Here is a little demonstration that these really are pure-functional trees which leave pre-existing copies of the tree unchanged after an operation:

    linux$ my
    eval:  include package   string_map;
    eval:  m0 = empty: Map( String );
    eval:  m1 = m0 $ ("Key1", "Value1");
    eval:  m2 = m1 $ ("Key2", "Value2");
    eval:  m3 = m2 $ ("Key3", "Value3");
    eval:  my (m4,_) = drop (m3, "Key2");

    eval:  keyvals_list m0;

    []

    eval:  keyvals_list m1;

    [("Key1", "Value1")]

    eval:  keyvals_list m2;

    [("Key1", "Value1"), ("Key2", "Value2")]

    eval:  keyvals_list m3;

    [("Key1", "Value1"), ("Key2", "Value2"), ("Key3", "Value3")]

    eval:  keyvals_list m4;

    [("Key1", "Value1"), ("Key3", "Value3")]

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext