DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: B T

⟦f3a021cb8⟧ TextFile

    Length: 1265 (0x4f1)
    Types: TextFile
    Names: »B«

Derivation

└─⟦180fe333a⟧ Bits:30000405 8mm tape, Rational 1000, SW CATALOG, 10_20_0
└─⟦180fe333a⟧ Bits:30000537 8mm tape, Rational 1000, SW Catalog 10_20_0
    └─⟦5cb1d1d7f⟧ »DATA« 
        └─⟦3b1ee7bd8⟧ 
            └─⟦this⟧ 

TextFile

package body Searching is

    function Index_Of (Key : in Item; Within : in Table) return Index is

        Low : Index := Within'First;
        Mid : Index;
        Hi : Index := Within'Last;

    begin

        loop

            if Low > Hi then
                raise Not_Found;
            end if;

            -- Calculate the mean Index value, using an expression
            -- which can never overflow:
            Mid := Index'Val
                      (Index'Pos (Low) / 2 + Index'Pos (Hi) / 2 +
                       (Index'Pos (Low) rem 2 + Index'Pos (Hi) rem 2) / 2);

            if Within (Mid) = Key then

                return Mid;

            elsif Within (Mid) > Key then

                -- This can raise Constraint_Error, but in that case
                -- the search has failed:
                Hi := Index'Pred (Mid);

            else

                -- This can raise Constraint_Error, but in that case
                -- the search has failed:
                Low := Index'Succ (Mid);

            end if;

        end loop;

    exception

        when Constraint_Error =>
            raise Not_Found;

    end Index_Of;

end Searching;


-- This procedure tests the binary search package at the extreme limits
-- of its index type.