with Interfaces; use Interfaces;

package body Natools.Static_Maps.S_Expressions.Templates.Dates.Zones is

   P : constant array (0 .. 3) of Natural :=
     (1, 2, 3, 4);

   T1 : constant array (0 .. 3) of Unsigned_16 :=
     (174, 296, 87, 202);

   T2 : constant array (0 .. 3) of Unsigned_16 :=
     (5, 119, 245, 172);

   G : constant array (0 .. 332) of Unsigned_8 :=
     (0, 85, 0, 0, 71, 0, 0, 104, 0, 149, 0, 0, 145, 0, 100, 51, 134, 3, 0,
      0, 136, 22, 0, 43, 0, 133, 0, 0, 0, 0, 0, 0, 18, 106, 87, 110, 0, 48,
      0, 0, 63, 0, 52, 0, 0, 83, 42, 0, 0, 66, 0, 0, 0, 0, 0, 72, 0, 83, 0,
      36, 33, 157, 0, 41, 0, 156, 0, 0, 116, 11, 4, 0, 129, 125, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 4, 61, 0, 0, 80, 7, 35, 0, 0, 0, 0, 0, 30, 5,
      140, 81, 111, 74, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 153, 0, 0, 45, 16, 2,
      108, 149, 109, 0, 0, 1, 0, 0, 158, 0, 164, 0, 139, 40, 0, 0, 0, 0, 0,
      116, 0, 0, 64, 129, 39, 159, 0, 0, 75, 5, 0, 0, 0, 55, 0, 106, 24,
      154, 0, 67, 86, 0, 9, 0, 65, 0, 50, 0, 0, 94, 47, 0, 0, 86, 6, 0, 61,
      0, 0, 75, 0, 38, 73, 30, 16, 120, 0, 0, 0, 16, 0, 0, 80, 0, 140, 44,
      146, 0, 0, 0, 0, 0, 27, 0, 0, 0, 90, 83, 32, 28, 0, 0, 104, 0, 83, 0,
      0, 0, 109, 16, 0, 112, 0, 0, 0, 66, 37, 0, 25, 70, 59, 70, 0, 24, 0,
      131, 0, 0, 0, 0, 45, 0, 0, 4, 0, 41, 97, 0, 0, 0, 17, 21, 0, 0, 0, 69,
      160, 5, 0, 0, 46, 64, 0, 68, 0, 5, 142, 8, 0, 0, 7, 79, 103, 77, 0, 0,
      138, 0, 163, 0, 43, 74, 0, 0, 134, 13, 54, 114, 51, 44, 0, 131, 32,
      13, 15, 148, 35, 94, 0, 31, 0, 0, 0, 144, 0, 84, 39, 0, 0, 125, 58, 0,
      0, 4, 12, 0, 0, 60, 11, 64, 0, 0, 0, 34, 14, 158, 145, 0, 23, 0, 143,
      163, 0, 96);

   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 333;
         F2 := (F2 + Natural (T2 (K)) * J) mod 333;
      end loop;
      return (Natural (G (F1)) + Natural (G (F2))) mod 166;
   end Hash;

end Natools.Static_Maps.S_Expressions.Templates.Dates.Zones;
