|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 Tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: B T
Length: 1250 (0x4e2)
Types: TextFile
Names: »B«
└─⟦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⟧
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;
-- TESTS THE BINARY SEARCH PACKAGE AT THE EXTREME LIMITS
-- OF ITS INDEX TYPE.