1 Reply Latest reply: Jun 19, 2012 2:17 PM by Steve Kato RSS

sorted index example

Steve Kato

Hi -

Anyone out there have an example of using a sorted index in mrl?

  • 1. sorted index example
    Steve Kato

    Here's how I think it works:

     

    test1.baroc - data class definition

    MC_DATA_CLASS : TEST_CLASS ISA DATA

    DEFINES

    {

        slot1 : STRING;

        slot2 : STRING, key = yes;

        slot3 : STRING, key = yes;

        slot4 : STRING;

    }

    END

     

    test1_data.baroc - the data table

    TEST_CLASS;

        slot1a = 'slot1a test';

        slot2a = 'test 1a';

        slot3a = 'test1a';

        slot4a = 'test2a';

    END

     

    TEST_CLASS;

        slot1b = 'slot1b test';

        slot2b = 'test 1b';

        slot3b = 'test1b';

        slot4b = 'test2b';

    END

     

    TEST_CLASS;

        slot1c = 'slot1c test';

        slot3c = 'test1c';

        slot4c = 'test2c';

    END

     

    TEST_CLASS;

        slot1d = 'slot1d test';

        slot4d = 'test2d';

    END

     

    test1.mrl - the rule

    index A_idx : TEST_CLASS sorted

        [slot2,slot3]

    END

     

    refine test1 :

        SOME_CLASS ($SC)

        where [$SC == OPEN]

        using ALL {

            index A_idx[]($D)  # in this case the search iterates over slot2 first and if slot2

                                       # has duplicates it iterates over slot3; the whole idea behind the index

                                       # is so the engine doesn't have to search through every data instance

                                       # so I guess it'll search through the first two instances, then the third but skip

                                       # the fourth - I don't know how I would verify that though

                                      

                where [

                    $SC.slot1 == $D.slot1a

                ]

        }

        {

            $SC.slot3 = $D.slot3a;

        }

    END