with Interfaces; use Interfaces;

package body CORBA_Repository_Root_UnionDef_Hash is

   P : constant array (0 .. 5) of Natural :=
     (2, 4, 8, 9, 13, 24);

   T1 : constant array (0 .. 5) of Unsigned_8 :=
     (28, 30, 64, 51, 5, 27);

   T2 : constant array (0 .. 5) of Unsigned_8 :=
     (32, 65, 71, 14, 13, 29);

   G : constant array (0 .. 82) of Unsigned_8 :=
     (18, 0, 25, 0, 20, 40, 0, 0, 23, 1, 26, 0, 0, 0, 0, 0, 8, 0, 29, 0, 0,
      0, 0, 0, 28, 0, 0, 7, 0, 0, 0, 0, 0, 36, 1, 0, 0, 13, 0, 9, 2, 10, 0,
      36, 0, 1, 19, 16, 34, 34, 0, 0, 0, 3, 37, 0, 27, 0, 22, 0, 6, 19, 0,
      0, 0, 40, 0, 0, 0, 8, 0, 1, 36, 36, 2, 29, 0, 0, 37, 13, 0, 19, 32);

   function Hash (S : String) return Natural is
      F : constant Natural := S'First - 1;
      L : constant Natural := S'Length;
      F1, F2 : Natural := 0;
      J : Natural;
   begin
      for K in P'Range loop
         exit when L < P (K);
         J  := Character'Pos (S (P (K) + F));
         F1 := (F1 + Natural (T1 (K)) * J) mod 83;
         F2 := (F2 + Natural (T2 (K)) * J) mod 83;
      end loop;
      return (Natural (G (F1)) + Natural (G (F2))) mod 41;
   end Hash;

end CORBA_Repository_Root_UnionDef_Hash;
