PreviousUpNext

Red-Black Trees: Finding First Key or Value

We might want to get the first key or key-value pair from a tree, perhaps to use it as a poor man’s priority queue:

    linux$ my

    eval:  include package   string_map;

    eval:  m = empty: Map( String );

    eval:  m $= ("Key1", "Value1");
    eval:  m $= ("Key2", "Value2");
    eval:  m $= ("Key3", "Value3");

    eval:  first_keyval_else_null m;
    THE ("Key1", "Value1")

    eval:  my (m,_) = drop(m, "Key1");

    eval:  first_keyval_else_null m;
    THE ("Key2", "Value2")

    eval:  my (m,_) = drop(m, "Key2");

    eval:  first_keyval_else_null m;
    THE ("Key3", "Value3")

    eval:  my (m,_) = drop(m, "Key3");

    eval:  first_keyval_else_null m;
    NULL

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext