1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . P E R F E C T _ H A S H _ G E N E R A T O R S --
9 -- Copyright (C) 2002-2024, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with GNAT
.Heap_Sort_G
;
35 with System
.OS_Lib
; use System
.OS_Lib
;
37 package body System
.Perfect_Hash_Generators
is
39 -- We are using the algorithm of J. Czech as described in Zbigniew J.
40 -- Czech, George Havas, and Bohdan S. Majewski ``An Optimal Algorithm for
41 -- Generating Minimal Perfect Hash Functions'', Information Processing
42 -- Letters, 43(1992) pp.257-264, Oct.1992
44 -- This minimal perfect hash function generator is based on random graphs
45 -- and produces a hash function of the form:
47 -- h (w) = (g (f1 (w)) + g (f2 (w))) mod m
49 -- where f1 and f2 are functions that map strings into integers, and g is
50 -- a function that maps integers into [0, m-1]. h can be order preserving.
51 -- For instance, let W = {w_0, ..., w_i, ..., w_m-1}, h can be defined
52 -- such that h (w_i) = i.
54 -- This algorithm defines two possible constructions of f1 and f2. Method
55 -- b) stores the hash function in less memory space at the expense of
58 -- a) fk (w) = sum (for i in 1 .. length (w)) (Tk (i, w (i))) mod n
60 -- size (Tk) = max (for w in W) (length (w)) * size (used char set)
62 -- b) fk (w) = sum (for i in 1 .. length (w)) (Tk (i) * w (i)) mod n
64 -- size (Tk) = max (for w in W) (length (w)) but the table lookups are
65 -- replaced by multiplications.
67 -- where Tk values are randomly generated. n is defined later on but the
68 -- algorithm recommends to use a value a little bit greater than 2m. Note
69 -- that for large values of m, the main memory space requirements comes
70 -- from the memory space for storing function g (>= 2m entries).
72 -- Random graphs are frequently used to solve difficult problems that do
73 -- not have polynomial solutions. This algorithm is based on a weighted
74 -- undirected graph. It comprises two steps: mapping and assignment.
76 -- In the mapping step, a graph G = (V, E) is constructed, where = {0, 1,
77 -- ..., n-1} and E = {(for w in W) (f1 (w), f2 (w))}. In order for the
78 -- assignment step to be successful, G has to be acyclic. To have a high
79 -- probability of generating an acyclic graph, n >= 2m. If it is not
80 -- acyclic, Tk have to be regenerated.
82 -- In the assignment step, the algorithm builds function g. As G is
83 -- acyclic, there is a vertex v1 with only one neighbor v2. Let w_i be
84 -- the word such that v1 = f1 (w_i) and v2 = f2 (w_i). Let g (v1) = 0 by
85 -- construction and g (v2) = (i - g (v1)) mod n (or h (i) - g (v1) mod n).
86 -- If word w_j is such that v2 = f1 (w_j) and v3 = f2 (w_j), g (v3) = (j -
87 -- g (v2)) mod (or to be general, (h (j) - g (v2)) mod n). If w_i has no
88 -- neighbor, then another vertex is selected. The algorithm traverses G to
89 -- assign values to all the vertices. It cannot assign a value to an
90 -- already assigned vertex as G is acyclic.
92 subtype Word_Id
is Integer;
93 subtype Key_Id
is Integer;
94 subtype Vertex_Id
is Integer;
95 subtype Edge_Id
is Integer;
96 subtype Table_Id
is Integer;
98 No_Vertex
: constant Vertex_Id
:= -1;
99 No_Edge
: constant Edge_Id
:= -1;
100 No_Table
: constant Table_Id
:= -1;
102 type Word_Type
is new String_Access
;
103 procedure Free_Word
(W
: in out Word_Type
) renames Free
;
104 function New_Word
(S
: String) return Word_Type
;
106 procedure Resize_Word
(W
: in out Word_Type
; Len
: Natural);
107 -- Resize string W to have a length Len
109 type Key_Type
is record
112 -- A key corresponds to an edge in the algorithm graph
114 type Vertex_Type
is record
118 -- A vertex can be involved in several edges. First and Last are the bounds
119 -- of an array of edges stored in a global edge table.
121 type Edge_Type
is record
126 -- An edge is a peer of vertices. In the algorithm, a key is associated to
129 package WT
is new GNAT
.Table
(Word_Type
, Word_Id
, 0, 32, 32);
130 package IT
is new GNAT
.Table
(Integer, Integer, 0, 32, 32);
131 -- The two main tables. WT is used to store the words in their initial
132 -- version and in their reduced version (that is words reduced to their
133 -- significant characters). As an instance of GNAT.Table, WT does not
134 -- initialize string pointers to null. This initialization has to be done
135 -- manually when the table is allocated. IT is used to store several
136 -- tables of components containing only integers.
138 function Image
(Int
: Integer; W
: Natural := 0) return String;
139 function Image
(Str
: String; W
: Natural := 0) return String;
140 -- Return a string which includes string Str or integer Int preceded by
141 -- leading spaces if required by width W.
143 function Trim_Trailing_Nuls
(Str
: String) return String;
144 -- Return Str with trailing NUL characters removed
146 Output
: File_Descriptor
renames System
.OS_Lib
.Standout
;
149 EOL
: constant Character := ASCII
.LF
;
151 Max
: constant := 78;
153 Line
: String (1 .. Max
);
154 -- Use this line to provide buffered IO
156 procedure Add
(C
: Character);
157 procedure Add
(S
: String);
158 -- Add a character or a string in Line and update Last
161 (F
: File_Descriptor
;
169 -- Write string S into file F as a element of an array of one or two
170 -- dimensions. Fk (resp. Lk and Ck) indicates the first (resp last and
171 -- current) index in the k-th dimension. If F1 = L1 the array is considered
172 -- as a one dimension array. This dimension is described by F2 and L2. This
173 -- routine takes care of all the parenthesis, spaces and commas needed to
174 -- format correctly the array. Moreover, the array is well indented and is
175 -- wrapped to fit in a 80 col line. When the line is full, the routine
176 -- writes it into file F. When the array is completed, the routine adds
177 -- semi-colon and writes the line into file F.
179 procedure New_Line
(File
: File_Descriptor
);
180 -- Simulate Ada.Text_IO.New_Line with GNAT.OS_Lib
182 procedure Put
(File
: File_Descriptor
; Str
: String);
183 -- Simulate Ada.Text_IO.Put with GNAT.OS_Lib
185 procedure Put_Used_Char_Set
(File
: File_Descriptor
; Title
: String);
186 -- Output a title and a used character set
188 procedure Put_Int_Vector
189 (File
: File_Descriptor
;
193 -- Output a title and a vector
195 procedure Put_Int_Matrix
196 (File
: File_Descriptor
;
201 -- Output a title and a matrix. When the matrix has only one non-empty
202 -- dimension (Len_2 = 0), output a vector.
204 procedure Put_Edges
(File
: File_Descriptor
; Title
: String);
205 -- Output a title and an edge table
207 procedure Put_Initial_Keys
(File
: File_Descriptor
; Title
: String);
208 -- Output a title and a key table
210 procedure Put_Reduced_Keys
(File
: File_Descriptor
; Title
: String);
211 -- Output a title and a key table
213 procedure Put_Vertex_Table
(File
: File_Descriptor
; Title
: String);
214 -- Output a title and a vertex table
216 ----------------------------------
217 -- Character Position Selection --
218 ----------------------------------
220 -- We reduce the maximum key size by selecting representative positions
221 -- in these keys. We build a matrix with one word per line. We fill the
222 -- remaining space of a line with ASCII.NUL. The heuristic selects the
223 -- position that induces the minimum number of collisions. If there are
224 -- collisions, select another position on the reduced key set responsible
225 -- of the collisions. Apply the heuristic until there is no more collision.
227 procedure Apply_Position_Selection
;
228 -- Apply Position selection and build the reduced key table
230 procedure Parse_Position_Selection
(Argument
: String);
231 -- Parse Argument and compute the position set. Argument is list of
232 -- substrings separated by commas. Each substring represents a position
233 -- or a range of positions (like x-y).
235 procedure Select_Character_Set
;
236 -- Define an optimized used character set like Character'Pos in order not
237 -- to allocate tables of 256 entries.
239 procedure Select_Char_Position
;
240 -- Find a min char position set in order to reduce the max key length. The
241 -- heuristic selects the position that induces the minimum number of
242 -- collisions. If there are collisions, select another position on the
243 -- reduced key set responsible of the collisions. Apply the heuristic until
244 -- there is no collision.
246 -----------------------------
247 -- Random Graph Generation --
248 -----------------------------
250 procedure Random
(Seed
: in out Natural);
251 -- Simulate Ada.Discrete_Numerics.Random
253 procedure Generate_Mapping_Table
257 Seed
: in out Natural);
258 -- Random generation of the tables below. T is already allocated
260 procedure Generate_Mapping_Tables
262 Seed
: in out Natural);
263 -- Generate the mapping tables T1 and T2. They are used to define fk (w) =
264 -- sum (for i in 1 .. length (w)) (Tk (i, w (i))) mod n. Keys, NK and Chars
265 -- are used to compute the matrix size.
267 ---------------------------
268 -- Algorithm Computation --
269 ---------------------------
271 procedure Compute_Edges_And_Vertices
(Opt
: Optimization
);
272 -- Compute the edge and vertex tables. These are empty when a self loop is
273 -- detected (f1 (w) = f2 (w)). The edge table is sorted by X value and then
274 -- Y value. Keys is the key table and NK the number of keys. Chars is the
275 -- set of characters really used in Keys. NV is the number of vertices
276 -- recommended by the algorithm. T1 and T2 are the mapping tables needed to
277 -- compute f1 (w) and f2 (w).
279 function Acyclic
return Boolean;
280 -- Return True when the graph is acyclic. Vertices is the current vertex
281 -- table and Edges the current edge table.
283 procedure Assign_Values_To_Vertices
;
284 -- Execute the assignment step of the algorithm. Keys is the current key
285 -- table. Vertices and Edges represent the random graph. G is the result of
286 -- the assignment step such that:
287 -- h (w) = (g (f1 (w)) + g (f2 (w))) mod m
292 Opt
: Optimization
) return Natural;
293 -- For an optimization of CPU_Time return
294 -- fk (w) = sum (for i in 1 .. length (w)) (Tk (i, w (i))) mod n
295 -- For an optimization of Memory_Space return
296 -- fk (w) = sum (for i in 1 .. length (w)) (Tk (i) * w (i)) mod n
299 -------------------------------
300 -- Internal Table Management --
301 -------------------------------
303 function Allocate
(N
: Natural; S
: Natural := 1) return Table_Id
;
304 -- Allocate N * S ints from IT table
310 Keys
: Table_Id
:= No_Table
;
312 -- NK : Number of Keys
314 function Initial
(K
: Key_Id
) return Word_Id
;
315 pragma Inline
(Initial
);
317 function Reduced
(K
: Key_Id
) return Word_Id
;
318 pragma Inline
(Reduced
);
320 function Get_Key
(N
: Key_Id
) return Key_Type
;
321 procedure Set_Key
(N
: Key_Id
; Item
: Key_Type
);
322 -- Get or Set Nth element of Keys table
328 Char_Pos_Set
: Table_Id
:= No_Table
;
329 Char_Pos_Set_Len
: Natural;
330 -- Character Selected Position Set
332 function Get_Char_Pos
(P
: Natural) return Natural;
333 procedure Set_Char_Pos
(P
: Natural; Item
: Natural);
334 -- Get or Set the string position of the Pth selected character
340 Used_Char_Set
: Table_Id
:= No_Table
;
341 Used_Char_Set_Len
: Natural;
342 -- Used Character Set : Define a new character mapping. When all the
343 -- characters are not present in the keys, in order to reduce the size
344 -- of some tables, we redefine the character mapping.
346 function Get_Used_Char
(C
: Character) return Natural;
347 procedure Set_Used_Char
(C
: Character; Item
: Natural);
353 T1
: Table_Id
:= No_Table
;
354 T2
: Table_Id
:= No_Table
;
357 -- T1 : Values table to compute F1
358 -- T2 : Values table to compute F2
360 function Get_Table
(T
: Integer; X
, Y
: Natural) return Natural;
361 procedure Set_Table
(T
: Integer; X
, Y
: Natural; Item
: Natural);
367 G
: Table_Id
:= No_Table
;
369 -- Values table to compute G
372 -- Number of tries running the algorithm before raising an error
374 function Get_Graph
(N
: Natural) return Integer;
375 procedure Set_Graph
(N
: Natural; Item
: Integer);
376 -- Get or Set Nth element of graph
382 Edge_Size
: constant := 3;
383 Edges
: Table_Id
:= No_Table
;
385 -- Edges : Edge table of the random graph G
387 function Get_Edges
(F
: Natural) return Edge_Type
;
388 procedure Set_Edges
(F
: Natural; Item
: Edge_Type
);
394 Vertex_Size
: constant := 2;
396 Vertices
: Table_Id
:= No_Table
;
397 -- Vertex table of the random graph G
400 -- Number of Vertices
402 function Get_Vertices
(F
: Natural) return Vertex_Type
;
403 procedure Set_Vertices
(F
: Natural; Item
: Vertex_Type
);
404 -- Comments needed ???
407 -- Optimization mode (memory vs CPU)
409 Max_Key_Len
: Natural := 0;
410 Min_Key_Len
: Natural := 0;
411 -- Maximum and minimum of all the word length
416 function Type_Size
(L
: Natural) return Natural;
417 -- Given the last L of an unsigned integer type T, return its size
423 function Acyclic
return Boolean is
424 Marks
: array (0 .. NV
- 1) of Vertex_Id
:= (others => No_Vertex
);
426 function Traverse
(Edge
: Edge_Id
; Mark
: Vertex_Id
) return Boolean;
427 -- Propagate Mark from X to Y. X is already marked. Mark Y and propagate
428 -- it to the edges of Y except the one representing the same key. Return
429 -- False when Y is marked with Mark.
435 function Traverse
(Edge
: Edge_Id
; Mark
: Vertex_Id
) return Boolean is
436 E
: constant Edge_Type
:= Get_Edges
(Edge
);
437 K
: constant Key_Id
:= E
.Key
;
438 Y
: constant Vertex_Id
:= E
.Y
;
439 M
: constant Vertex_Id
:= Marks
(E
.Y
);
446 elsif M
= No_Vertex
then
448 V
:= Get_Vertices
(Y
);
450 for J
in V
.First
.. V
.Last
loop
452 -- Do not propagate to the edge representing the same key
454 if Get_Edges
(J
).Key
/= K
455 and then not Traverse
(J
, Mark
)
467 -- Start of processing for Acyclic
470 -- Edges valid range is
472 for J
in 1 .. Edges_Len
- 1 loop
474 Edge
:= Get_Edges
(J
);
476 -- Mark X of E when it has not been already done
478 if Marks
(Edge
.X
) = No_Vertex
then
479 Marks
(Edge
.X
) := Edge
.X
;
482 -- Traverse E when this has not already been done
484 if Marks
(Edge
.Y
) = No_Vertex
485 and then not Traverse
(J
, Edge
.X
)
498 procedure Add
(C
: Character) is
499 pragma Assert
(C
/= ASCII
.NUL
);
501 Line
(Last
+ 1) := C
;
509 procedure Add
(S
: String) is
510 Len
: constant Natural := S
'Length;
512 for J
in S
'Range loop
513 pragma Assert
(S
(J
) /= ASCII
.NUL
);
517 Line
(Last
+ 1 .. Last
+ Len
) := S
;
525 function Allocate
(N
: Natural; S
: Natural := 1) return Table_Id
is
526 L
: constant Integer := IT
.Last
;
528 IT
.Set_Last
(L
+ N
* S
);
530 -- Initialize, so debugging printouts don't trip over uninitialized
533 for J
in L
+ 1 .. IT
.Last
loop
540 ------------------------------
541 -- Apply_Position_Selection --
542 ------------------------------
544 procedure Apply_Position_Selection
is
546 for J
in 0 .. NK
- 1 loop
548 IW
: constant String := WT
.Table
(Initial
(J
)).all;
549 RW
: String (1 .. IW
'Length) := (others => ASCII
.NUL
);
550 N
: Natural := IW
'First - 1;
553 -- Select the characters of Word included in the position
556 for C
in 0 .. Char_Pos_Set_Len
- 1 loop
557 exit when IW
(Get_Char_Pos
(C
)) = ASCII
.NUL
;
559 RW
(N
) := IW
(Get_Char_Pos
(C
));
562 -- Build the new table with the reduced word. Be careful
563 -- to deallocate the old version to avoid memory leaks.
565 Free_Word
(WT
.Table
(Reduced
(J
)));
566 WT
.Table
(Reduced
(J
)) := New_Word
(RW
);
567 Set_Key
(J
, (Edge
=> No_Edge
));
570 end Apply_Position_Selection
;
572 -------------------------------
573 -- Assign_Values_To_Vertices --
574 -------------------------------
576 procedure Assign_Values_To_Vertices
is
579 procedure Assign
(X
: Vertex_Id
);
580 -- Execute assignment on X's neighbors except the vertex that we are
581 -- coming from which is already assigned.
587 procedure Assign
(X
: Vertex_Id
) is
589 V
: constant Vertex_Type
:= Get_Vertices
(X
);
592 for J
in V
.First
.. V
.Last
loop
595 if Get_Graph
(E
.Y
) = -1 then
596 pragma Assert
(NK
/= 0);
597 Set_Graph
(E
.Y
, (E
.Key
- Get_Graph
(X
)) mod NK
);
603 -- Start of processing for Assign_Values_To_Vertices
606 -- Value -1 denotes an uninitialized value as it is supposed to
607 -- be in the range 0 .. NK.
611 G
:= Allocate
(G_Len
, 1);
614 for J
in 0 .. G_Len
- 1 loop
618 for K
in 0 .. NK
- 1 loop
619 X
:= Get_Edges
(Get_Key
(K
).Edge
).X
;
621 if Get_Graph
(X
) = -1 then
627 for J
in 0 .. G_Len
- 1 loop
628 if Get_Graph
(J
) = -1 then
634 Put_Int_Vector
(Output
, "Assign Values To Vertices", G
, G_Len
);
636 end Assign_Values_To_Vertices
;
642 procedure Compute
(Position
: String) is
643 Success
: Boolean := False;
647 raise Program_Error
with "keywords set cannot be empty";
651 Put_Initial_Keys
(Output
, "Initial Key Table");
654 if Position
'Length /= 0 then
655 Parse_Position_Selection
(Position
);
657 Select_Char_Position
;
662 (Output
, "Char Position Set", Char_Pos_Set
, Char_Pos_Set_Len
);
665 Apply_Position_Selection
;
668 Put_Reduced_Keys
(Output
, "Reduced Keys Table");
671 Select_Character_Set
;
674 Put_Used_Char_Set
(Output
, "Character Position Table");
677 -- Perform Czech's algorithm
679 for J
in 1 .. NT
loop
680 Generate_Mapping_Tables
(Opt
, S
);
681 Compute_Edges_And_Vertices
(Opt
);
683 -- When graph is not empty (no self-loop from previous operation) and
686 if 0 < Edges_Len
and then Acyclic
then
693 raise Too_Many_Tries
;
696 Assign_Values_To_Vertices
;
699 --------------------------------
700 -- Compute_Edges_And_Vertices --
701 --------------------------------
703 procedure Compute_Edges_And_Vertices
(Opt
: Optimization
) is
708 Vertex
: Vertex_Type
;
709 Not_Acyclic
: Boolean := False;
711 procedure Move
(From
: Natural; To
: Natural);
712 function Lt
(L
, R
: Natural) return Boolean;
713 -- Subprograms needed for GNAT.Heap_Sort_G
719 function Lt
(L
, R
: Natural) return Boolean is
720 EL
: constant Edge_Type
:= Get_Edges
(L
);
721 ER
: constant Edge_Type
:= Get_Edges
(R
);
723 return EL
.X
< ER
.X
or else (EL
.X
= ER
.X
and then EL
.Y
< ER
.Y
);
730 procedure Move
(From
: Natural; To
: Natural) is
732 Set_Edges
(To
, Get_Edges
(From
));
735 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
737 -- Start of processing for Compute_Edges_And_Vertices
740 -- We store edges from 1 to 2 * NK and leave zero alone in order to use
743 Edges_Len
:= 2 * NK
+ 1;
745 if Edges
= No_Table
then
746 Edges
:= Allocate
(Edges_Len
, Edge_Size
);
749 if Vertices
= No_Table
then
750 Vertices
:= Allocate
(NV
, Vertex_Size
);
753 for J
in 0 .. NV
- 1 loop
754 Set_Vertices
(J
, (No_Vertex
, No_Vertex
- 1));
757 -- For each w, X = f1 (w) and Y = f2 (w)
759 for J
in 0 .. NK
- 1 loop
764 X
:= Sum
(WT
.Table
(Reduced
(J
)), T1
, Opt
);
765 Y
:= Sum
(WT
.Table
(Reduced
(J
)), T2
, Opt
);
767 -- Discard T1 and T2 as soon as we discover a self loop
774 -- We store (X, Y) and (Y, X) to ease assignment step
776 Set_Edges
(2 * J
+ 1, (X
, Y
, J
));
777 Set_Edges
(2 * J
+ 2, (Y
, X
, J
));
780 -- Return an empty graph when self loop detected
787 Put_Edges
(Output
, "Unsorted Edge Table");
788 Put_Int_Matrix
(Output
, "Function Table 1", T1
,
790 Put_Int_Matrix
(Output
, "Function Table 2", T2
,
794 -- Enforce consistency between edges and keys. Construct Vertices and
795 -- compute the list of neighbors of a vertex First .. Last as Edges
796 -- is sorted by X and then Y. To compute the neighbor list, sort the
799 Sorting
.Sort
(Edges_Len
- 1);
802 Put_Edges
(Output
, "Sorted Edge Table");
803 Put_Int_Matrix
(Output
, "Function Table 1", T1
,
805 Put_Int_Matrix
(Output
, "Function Table 2", T2
,
809 -- Edges valid range is 1 .. 2 * NK
811 for E
in 1 .. Edges_Len
- 1 loop
812 Edge
:= Get_Edges
(E
);
813 Key
:= Get_Key
(Edge
.Key
);
815 if Key
.Edge
= No_Edge
then
817 Set_Key
(Edge
.Key
, Key
);
820 Vertex
:= Get_Vertices
(Edge
.X
);
822 if Vertex
.First
= No_Edge
then
827 Set_Vertices
(Edge
.X
, Vertex
);
831 Put_Reduced_Keys
(Output
, "Key Table");
832 Put_Edges
(Output
, "Edge Table");
833 Put_Vertex_Table
(Output
, "Vertex Table");
836 end Compute_Edges_And_Vertices
;
844 Item_Size
: out Natural;
845 Length_1
: out Natural;
846 Length_2
: out Natural)
850 when Character_Position
=>
852 Length_1
:= Char_Pos_Set_Len
;
855 when Used_Character_Set
=>
860 when Function_Table_1
863 Item_Size
:= Type_Size
(NV
);
868 Item_Size
:= Type_Size
(NK
);
878 procedure Finalize
is
881 Put
(Output
, "Finalize");
885 -- Deallocate all the WT components (both initial and reduced ones) to
886 -- avoid memory leaks.
888 for W
in 0 .. WT
.Last
loop
890 -- Note: WT.Table (NK) is a temporary variable, do not free it since
891 -- this would cause a double free.
894 Free_Word
(WT
.Table
(W
));
901 -- Reset all variables for next usage
905 Char_Pos_Set
:= No_Table
;
906 Char_Pos_Set_Len
:= 0;
908 Used_Char_Set
:= No_Table
;
909 Used_Char_Set_Len
:= 0;
923 Vertices
:= No_Table
;
931 ----------------------------
932 -- Generate_Mapping_Table --
933 ----------------------------
935 procedure Generate_Mapping_Table
939 Seed
: in out Natural)
942 for J
in 0 .. L1
- 1 loop
943 for K
in 0 .. L2
- 1 loop
945 Set_Table
(Tab
, J
, K
, Seed
mod NV
);
948 end Generate_Mapping_Table
;
950 -----------------------------
951 -- Generate_Mapping_Tables --
952 -----------------------------
954 procedure Generate_Mapping_Tables
956 Seed
: in out Natural)
959 -- If T1 and T2 are already allocated no need to do it twice. Reuse them
960 -- as their size has not changed.
962 if T1
= No_Table
and then T2
= No_Table
then
964 Used_Char_Last
: Natural := 0;
968 if Opt
= CPU_Time
then
969 for P
in reverse Character'Range loop
970 Used_Char
:= Get_Used_Char
(P
);
971 if Used_Char
/= 0 then
972 Used_Char_Last
:= Used_Char
;
978 T1_Len
:= Char_Pos_Set_Len
;
979 T2_Len
:= Used_Char_Last
+ 1;
980 T1
:= Allocate
(T1_Len
* T2_Len
);
981 T2
:= Allocate
(T1_Len
* T2_Len
);
985 Generate_Mapping_Table
(T1
, T1_Len
, T2_Len
, Seed
);
986 Generate_Mapping_Table
(T2
, T1_Len
, T2_Len
, Seed
);
989 Put_Used_Char_Set
(Output
, "Used Character Set");
990 Put_Int_Matrix
(Output
, "Function Table 1", T1
,
992 Put_Int_Matrix
(Output
, "Function Table 2", T2
,
995 end Generate_Mapping_Tables
;
1001 function Get_Char_Pos
(P
: Natural) return Natural is
1002 N
: constant Natural := Char_Pos_Set
+ P
;
1004 return IT
.Table
(N
);
1011 function Get_Edges
(F
: Natural) return Edge_Type
is
1012 N
: constant Natural := Edges
+ (F
* Edge_Size
);
1015 E
.X
:= IT
.Table
(N
);
1016 E
.Y
:= IT
.Table
(N
+ 1);
1017 E
.Key
:= IT
.Table
(N
+ 2);
1025 function Get_Graph
(N
: Natural) return Integer is
1027 return IT
.Table
(G
+ N
);
1034 function Get_Key
(N
: Key_Id
) return Key_Type
is
1037 K
.Edge
:= IT
.Table
(Keys
+ N
);
1045 function Get_Table
(T
: Integer; X
, Y
: Natural) return Natural is
1046 N
: constant Natural := T
+ (Y
* T1_Len
) + X
;
1048 return IT
.Table
(N
);
1055 function Get_Used_Char
(C
: Character) return Natural is
1056 N
: constant Natural := Used_Char_Set
+ Character'Pos (C
);
1058 return IT
.Table
(N
);
1065 function Get_Vertices
(F
: Natural) return Vertex_Type
is
1066 N
: constant Natural := Vertices
+ (F
* Vertex_Size
);
1069 V
.First
:= IT
.Table
(N
);
1070 V
.Last
:= IT
.Table
(N
+ 1);
1078 function Image
(Int
: Integer; W
: Natural := 0) return String is
1079 B
: String (1 .. 32);
1082 procedure Img
(V
: Natural);
1083 -- Compute image of V into B, starting at B (L), incrementing L
1089 procedure Img
(V
: Natural) is
1096 B
(L
) := Character'Val ((V
mod 10) + Character'Pos ('0'));
1099 -- Start of processing for Image
1110 return Image
(B
(1 .. L
), W
);
1117 function Image
(Str
: String; W
: Natural := 0) return String is
1118 Len
: constant Natural := Str
'Length;
1119 Max
: Natural := Len
;
1127 Buf
: String (1 .. Max
) := (1 .. Max
=> ' ');
1130 for J
in 0 .. Len
- 1 loop
1131 Buf
(Max
- Len
+ 1 + J
) := Str
(Str
'First + J
);
1142 function Initial
(K
: Key_Id
) return Word_Id
is
1151 procedure Initialize
1154 Optim
: Optimization
;
1159 Put
(Output
, "Initialize");
1163 -- Deallocate the part of the table concerning the reduced words.
1164 -- Initial words are already present in the table. We may have reduced
1165 -- words already there because a previous computation failed. We are
1166 -- currently retrying and the reduced words have to be deallocated.
1168 for W
in Reduced
(0) .. WT
.Last
loop
1169 Free_Word
(WT
.Table
(W
));
1174 -- Initialize of computation variables
1178 Char_Pos_Set
:= No_Table
;
1179 Char_Pos_Set_Len
:= 0;
1181 Used_Char_Set
:= No_Table
;
1182 Used_Char_Set_Len
:= 0;
1197 raise Program_Error
with "K to V ratio cannot be lower than 2";
1200 Vertices
:= No_Table
;
1207 Keys
:= Allocate
(NK
);
1209 -- Resize initial words to have all of them at the same size
1210 -- (so the size of the largest one).
1212 for K
in 0 .. NK
- 1 loop
1213 Resize_Word
(WT
.Table
(Initial
(K
)), Max_Key_Len
);
1216 -- Allocated the table to store the reduced words. As WT is a
1217 -- GNAT.Table (using C memory management), pointers have to be
1218 -- explicitly initialized to null.
1220 WT
.Set_Last
(Reduced
(NK
- 1));
1222 -- Note: Reduced (0) = NK + 1
1224 WT
.Table
(NK
) := null;
1226 for W
in 0 .. NK
- 1 loop
1227 WT
.Table
(Reduced
(W
)) := null;
1235 procedure Insert
(Value
: String) is
1236 Len
: constant Natural := Value
'Length;
1240 Put
(Output
, "Inserting """ & Value
& """");
1244 for J
in Value
'Range loop
1245 pragma Assert
(Value
(J
) /= ASCII
.NUL
);
1250 WT
.Table
(NK
) := New_Word
(Value
);
1253 if Max_Key_Len
< Len
then
1257 if Min_Key_Len
= 0 or else Len
< Min_Key_Len
then
1266 procedure New_Line
(File
: File_Descriptor
) is
1268 if Write
(File
, EOL
'Address, 1) /= 1 then
1269 raise Program_Error
;
1277 function New_Word
(S
: String) return Word_Type
is
1279 return new String'(S);
1282 ------------------------------
1283 -- Parse_Position_Selection --
1284 ------------------------------
1286 procedure Parse_Position_Selection (Argument : String) is
1287 N : Natural := Argument'First;
1288 L : constant Natural := Argument'Last;
1289 M : constant Natural := Max_Key_Len;
1291 T : array (1 .. M) of Boolean := (others => False);
1293 function Parse_Index return Natural;
1294 -- Parse argument starting at index N to find an index
1300 function Parse_Index return Natural is
1301 C : Character := Argument (N);
1310 if C not in '0' .. '9' then
1311 raise Program_Error with "cannot read position argument";
1314 while C in '0' .. '9' loop
1315 V := V * 10 + (Character'Pos (C) - Character'Pos ('0'));
1324 -- Start of processing for Parse_Position_Selection
1327 -- Empty specification means all the positions
1330 Char_Pos_Set_Len := M;
1331 Char_Pos_Set := Allocate (Char_Pos_Set_Len);
1333 for C in 0 .. Char_Pos_Set_Len - 1 loop
1334 Set_Char_Pos (C, C + 1);
1340 First, Last : Natural;
1343 First := Parse_Index;
1348 if N <= L and then Argument (N) = '-' then
1350 Last := Parse_Index;
1353 -- Include the positions in the selection
1355 for J in First .. Last loop
1362 if Argument (N) /= ',' then
1363 raise Program_Error with "cannot read position argument";
1369 -- Compute position selection length
1372 for J in T'Range loop
1378 -- Fill position selection
1380 Char_Pos_Set_Len := N;
1381 Char_Pos_Set := Allocate (Char_Pos_Set_Len);
1384 for J in T'Range loop
1386 Set_Char_Pos (N, J);
1391 end Parse_Position_Selection;
1397 procedure Put (File : File_Descriptor; Str : String) is
1398 Len : constant Natural := Str'Length;
1400 for J in Str'Range loop
1401 pragma Assert (Str (J) /= ASCII.NUL);
1405 if Write (File, Str'Address, Len) /= Len then
1406 raise Program_Error;
1415 (F : File_Descriptor;
1424 Len : constant Natural := S'Length;
1427 -- Write current line, followed by LF
1435 Put (F, Line (1 .. Last));
1440 -- Start of processing for Put
1443 if C1 = F1 and then C2 = F2 then
1447 if Last + Len + 3 >= Max then
1455 if C1 = F1 and then C2 = F2 then
1507 procedure Put_Edges (File : File_Descriptor; Title : String) is
1509 F1 : constant Natural := 1;
1510 L1 : constant Natural := Edges_Len - 1;
1511 M : constant Natural := Max / 5;
1517 -- Edges valid range is 1 .. Edge_Len - 1
1519 for J in F1 .. L1 loop
1521 Put (File, Image (J, M), F1, L1, J, 1, 4, 1);
1522 Put (File, Image (E.X, M), F1, L1, J, 1, 4, 2);
1523 Put (File, Image (E.Y, M), F1, L1, J, 1, 4, 3);
1524 Put (File, Image (E.Key, M), F1, L1, J, 1, 4, 4);
1528 ----------------------
1529 -- Put_Initial_Keys --
1530 ----------------------
1532 procedure Put_Initial_Keys (File : File_Descriptor; Title : String) is
1533 F1 : constant Natural := 0;
1534 L1 : constant Natural := NK - 1;
1535 M : constant Natural := Max / 5;
1542 for J in F1 .. L1 loop
1544 Put (File, Image (J, M), F1, L1, J, 1, 3, 1);
1545 Put (File, Image (K.Edge, M), F1, L1, J, 1, 3, 2);
1546 Put (File, Trim_Trailing_Nuls (WT.Table (Initial (J)).all),
1547 F1, L1, J, 1, 3, 3);
1549 end Put_Initial_Keys;
1551 --------------------
1552 -- Put_Int_Matrix --
1553 --------------------
1555 procedure Put_Int_Matrix
1556 (File : File_Descriptor;
1562 F1 : constant Integer := 0;
1563 L1 : constant Integer := Len_1 - 1;
1564 F2 : constant Integer := 0;
1565 L2 : constant Integer := Len_2 - 1;
1573 for J in F1 .. L1 loop
1574 Ix := IT.Table (Table + J);
1575 Put (File, Image (Ix), 1, 0, 1, F1, L1, J);
1579 for J in F1 .. L1 loop
1580 for K in F2 .. L2 loop
1581 Ix := IT.Table (Table + J + K * Len_1);
1582 Put (File, Image (Ix), F1, L1, J, F2, L2, K);
1588 --------------------
1589 -- Put_Int_Vector --
1590 --------------------
1592 procedure Put_Int_Vector
1593 (File : File_Descriptor;
1598 F2 : constant Natural := 0;
1599 L2 : constant Natural := Length - 1;
1605 for J in F2 .. L2 loop
1606 Put (File, Image (IT.Table (Vector + J)), 1, 0, 1, F2, L2, J);
1610 ----------------------
1611 -- Put_Reduced_Keys --
1612 ----------------------
1614 procedure Put_Reduced_Keys (File : File_Descriptor; Title : String) is
1615 F1 : constant Natural := 0;
1616 L1 : constant Natural := NK - 1;
1617 M : constant Natural := Max / 5;
1624 for J in F1 .. L1 loop
1626 Put (File, Image (J, M), F1, L1, J, 1, 3, 1);
1627 Put (File, Image (K.Edge, M), F1, L1, J, 1, 3, 2);
1628 Put (File, Trim_Trailing_Nuls (WT.Table (Reduced (J)).all),
1629 F1, L1, J, 1, 3, 3);
1631 end Put_Reduced_Keys;
1633 -----------------------
1634 -- Put_Used_Char_Set --
1635 -----------------------
1637 procedure Put_Used_Char_Set (File : File_Descriptor; Title : String) is
1638 F : constant Natural := Character'Pos (Character'First);
1639 L : constant Natural := Character'Pos (Character'Last);
1645 for J in Character'Range loop
1647 (File, Image (Get_Used_Char (J)), 1, 0, 1, F, L, Character'Pos (J));
1649 end Put_Used_Char_Set;
1651 ----------------------
1652 -- Put_Vertex_Table --
1653 ----------------------
1655 procedure Put_Vertex_Table (File : File_Descriptor; Title : String) is
1656 F1 : constant Natural := 0;
1657 L1 : constant Natural := NV - 1;
1658 M : constant Natural := Max / 4;
1665 for J in F1 .. L1 loop
1666 V := Get_Vertices (J);
1667 Put (File, Image (J, M), F1, L1, J, 1, 3, 1);
1668 Put (File, Image (V.First, M), F1, L1, J, 1, 3, 2);
1669 Put (File, Image (V.Last, M), F1, L1, J, 1, 3, 3);
1671 end Put_Vertex_Table;
1677 procedure Random (Seed : in out Natural) is
1679 -- Park & Miller Standard Minimal using Schrage's algorithm to avoid
1680 -- overflow: Xn+1 = 16807 * Xn mod (2 ** 31 - 1)
1687 R := Seed mod 127773;
1689 X := 16807 * R - 2836 * Q;
1691 Seed := (if X < 0 then X + 2147483647 else X);
1698 function Reduced (K : Key_Id) return Word_Id is
1707 procedure Resize_Word (W : in out Word_Type; Len : Natural) is
1708 S1 : constant String := W.all;
1709 S2 : String (1 .. Len) := (others => ASCII.NUL);
1710 L : constant Natural := S1'Length;
1719 --------------------------
1720 -- Select_Char_Position --
1721 --------------------------
1723 procedure Select_Char_Position is
1725 type Vertex_Table_Type is array (Natural range <>) of Vertex_Type;
1727 procedure Build_Identical_Keys_Sets
1728 (Table : in out Vertex_Table_Type;
1729 Last : in out Natural;
1731 -- Build a list of keys subsets that are identical with the current
1732 -- position selection plus Pos. Once this routine is called, reduced
1733 -- words are sorted by subsets and each item (First, Last) in Sets
1734 -- defines the range of identical keys.
1735 -- Need comment saying exactly what Last is ???
1737 function Count_Different_Keys
1738 (Table : Vertex_Table_Type;
1740 Pos : Natural) return Natural;
1741 -- For each subset in Sets, count the number of different keys if we add
1742 -- Pos to the current position selection.
1744 Sel_Position : IT.Table_Type (1 .. Max_Key_Len);
1745 Last_Sel_Pos : Natural := 0;
1746 Max_Sel_Pos : Natural := 0;
1748 -------------------------------
1749 -- Build_Identical_Keys_Sets --
1750 -------------------------------
1752 procedure Build_Identical_Keys_Sets
1753 (Table : in out Vertex_Table_Type;
1754 Last : in out Natural;
1757 S : constant Vertex_Table_Type := Table (Table'First .. Last);
1758 C : constant Natural := Pos;
1759 -- Shortcuts (why are these not renames ???)
1763 -- First and last words of a subset
1766 -- GNAT.Heap_Sort assumes that the first array index is 1. Offset
1767 -- defines the translation to operate.
1769 function Lt (L, R : Natural) return Boolean;
1770 procedure Move (From : Natural; To : Natural);
1771 -- Subprograms needed by GNAT.Heap_Sort_G
1777 function Lt (L, R : Natural) return Boolean is
1778 C : constant Natural := Pos;
1785 Right := Offset + R;
1791 Right := Offset + R;
1794 return WT.Table (Left)(C) < WT.Table (Right)(C);
1801 procedure Move (From : Natural; To : Natural) is
1802 Target, Source : Natural;
1807 Target := Offset + To;
1809 Source := Offset + From;
1812 Source := Offset + From;
1813 Target := Offset + To;
1816 WT.Table (Target) := WT.Table (Source);
1817 WT.Table (Source) := null;
1820 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1822 -- Start of processing for Build_Identical_Key_Sets
1827 -- For each subset in S, extract the new subsets we have by adding C
1828 -- in the position selection.
1830 for J in S'Range loop
1831 pragma Annotate (CodePeer, Modified, S (J));
1833 if S (J).First = S (J).Last then
1837 Table (Last) := (F, L);
1840 Offset := Reduced (S (J).First) - 1;
1841 Sorting.Sort (S (J).Last - S (J).First + 1);
1845 for N in S (J).First .. S (J).Last loop
1847 -- For the last item, close the last subset
1849 if N = S (J).Last then
1851 Table (Last) := (F, N);
1853 -- Two contiguous words are identical when they have the
1854 -- same Cth character.
1856 elsif WT.Table (Reduced (N))(C) =
1857 WT.Table (Reduced (N + 1))(C)
1861 -- Find a new subset of identical keys. Store the current
1862 -- one and create a new subset.
1866 Table (Last) := (F, L);
1873 end Build_Identical_Keys_Sets;
1875 --------------------------
1876 -- Count_Different_Keys --
1877 --------------------------
1879 function Count_Different_Keys
1880 (Table : Vertex_Table_Type;
1882 Pos : Natural) return Natural
1884 N : array (Character) of Natural;
1889 -- For each subset, count the number of words that are still
1890 -- different when we include Pos in the position selection. Only
1891 -- focus on this position as the other positions already produce
1894 for S in 1 .. Last loop
1896 -- Count the occurrences of the different characters
1899 for K in Table (S).First .. Table (S).Last loop
1900 C := WT.Table (Reduced (K))(Pos);
1904 -- Update the number of different keys. Each character used
1905 -- denotes a different key.
1907 for J in N'Range loop
1915 end Count_Different_Keys;
1917 -- Start of processing for Select_Char_Position
1920 -- Initialize the reduced words set
1922 for K in 0 .. NK - 1 loop
1923 WT.Table (Reduced (K)) := New_Word (WT.Table (Initial (K)).all);
1927 Differences : Natural;
1928 Max_Differences : Natural := 0;
1929 Old_Differences : Natural;
1930 Max_Diff_Sel_Pos : Natural := 0; -- init to kill warning
1931 Max_Diff_Sel_Pos_Idx : Natural := 0; -- init to kill warning
1932 Same_Keys_Sets_Table : Vertex_Table_Type (1 .. NK);
1933 Same_Keys_Sets_Last : Natural := 1;
1936 for C in Sel_Position'Range loop
1937 Sel_Position (C) := C;
1940 Same_Keys_Sets_Table (1) := (0, NK - 1);
1943 -- Preserve maximum number of different keys and check later on
1944 -- that this value is strictly incrementing. Otherwise, it means
1945 -- that two keys are strictly identical.
1947 Old_Differences := Max_Differences;
1949 -- The first position should not exceed the minimum key length.
1950 -- Otherwise, we may end up with an empty word once reduced.
1953 (if Last_Sel_Pos = 0 then Min_Key_Len else Max_Key_Len);
1955 -- Find which position increases more the number of differences
1957 for J in Last_Sel_Pos + 1 .. Max_Sel_Pos loop
1958 Differences := Count_Different_Keys
1959 (Same_Keys_Sets_Table,
1960 Same_Keys_Sets_Last,
1965 "Selecting position" & Sel_Position (J)'Img &
1966 " results in" & Differences'Img &
1971 if Differences > Max_Differences then
1972 Max_Differences := Differences;
1973 Max_Diff_Sel_Pos := Sel_Position (J);
1974 Max_Diff_Sel_Pos_Idx := J;
1978 if Old_Differences = Max_Differences then
1979 raise Program_Error with "some keys are identical";
1982 -- Insert selected position and sort Sel_Position table
1984 Last_Sel_Pos := Last_Sel_Pos + 1;
1985 Sel_Position (Last_Sel_Pos + 1 .. Max_Diff_Sel_Pos_Idx) :=
1986 Sel_Position (Last_Sel_Pos .. Max_Diff_Sel_Pos_Idx - 1);
1987 Sel_Position (Last_Sel_Pos) := Max_Diff_Sel_Pos;
1989 for P in 1 .. Last_Sel_Pos - 1 loop
1990 if Max_Diff_Sel_Pos < Sel_Position (P) then
1992 (CodePeer, False_Positive,
1993 "test always false", "false positive?");
1995 Sel_Position (P + 1 .. Last_Sel_Pos) :=
1996 Sel_Position (P .. Last_Sel_Pos - 1);
1997 Sel_Position (P) := Max_Diff_Sel_Pos;
2002 exit when Max_Differences = NK;
2004 Build_Identical_Keys_Sets
2005 (Same_Keys_Sets_Table,
2006 Same_Keys_Sets_Last,
2011 "Selecting position" & Max_Diff_Sel_Pos'Img &
2012 " results in" & Max_Differences'Img &
2017 for J in 1 .. Same_Keys_Sets_Last loop
2019 Same_Keys_Sets_Table (J).First ..
2020 Same_Keys_Sets_Table (J).Last
2023 Trim_Trailing_Nuls (WT.Table (Reduced (K)).all));
2033 Char_Pos_Set_Len := Last_Sel_Pos;
2034 Char_Pos_Set := Allocate (Char_Pos_Set_Len);
2036 for C in 1 .. Last_Sel_Pos loop
2037 Set_Char_Pos (C - 1, Sel_Position (C));
2039 end Select_Char_Position;
2041 --------------------------
2042 -- Select_Character_Set --
2043 --------------------------
2045 procedure Select_Character_Set is
2046 Last : Natural := 0;
2047 Used : array (Character) of Boolean := (others => False);
2051 for J in 0 .. NK - 1 loop
2052 for K in 0 .. Char_Pos_Set_Len - 1 loop
2053 Char := WT.Table (Initial (J))(Get_Char_Pos (K));
2054 exit when Char = ASCII.NUL;
2055 Used (Char) := True;
2059 Used_Char_Set_Len := 256;
2060 Used_Char_Set := Allocate (Used_Char_Set_Len);
2062 for J in Used'Range loop
2064 Set_Used_Char (J, Last);
2067 Set_Used_Char (J, 0);
2070 end Select_Character_Set;
2076 procedure Set_Char_Pos (P : Natural; Item : Natural) is
2077 N : constant Natural := Char_Pos_Set + P;
2079 IT.Table (N) := Item;
2086 procedure Set_Edges (F : Natural; Item : Edge_Type) is
2087 N : constant Natural := Edges + (F * Edge_Size);
2089 IT.Table (N) := Item.X;
2090 IT.Table (N + 1) := Item.Y;
2091 IT.Table (N + 2) := Item.Key;
2098 procedure Set_Graph (N : Natural; Item : Integer) is
2100 IT.Table (G + N) := Item;
2107 procedure Set_Key (N : Key_Id; Item : Key_Type) is
2109 IT.Table (Keys + N) := Item.Edge;
2116 procedure Set_Table (T : Integer; X, Y : Natural; Item : Natural) is
2117 N : constant Natural := T + ((Y * T1_Len) + X);
2119 IT.Table (N) := Item;
2126 procedure Set_Used_Char (C : Character; Item : Natural) is
2127 N : constant Natural := Used_Char_Set + Character'Pos (C);
2129 IT.Table (N) := Item;
2136 procedure Set_Vertices (F : Natural; Item : Vertex_Type) is
2137 N : constant Natural := Vertices + (F * Vertex_Size);
2139 IT.Table (N) := Item.First;
2140 IT.Table (N + 1) := Item.Last;
2150 Opt : Optimization) return Natural
2158 for J in 0 .. T1_Len - 1 loop
2159 exit when Word (J + 1) = ASCII.NUL;
2160 R := Get_Table (Table, J, Get_Used_Char (Word (J + 1)));
2161 pragma Assert (NV /= 0);
2162 S := (S + R) mod NV;
2165 when Memory_Space =>
2166 for J in 0 .. T1_Len - 1 loop
2167 exit when Word (J + 1) = ASCII.NUL;
2168 R := Get_Table (Table, J, 0);
2169 pragma Assert (NV /= 0);
2170 S := (S + R * Character'Pos (Word (J + 1))) mod NV;
2177 ------------------------
2178 -- Trim_Trailing_Nuls --
2179 ------------------------
2181 function Trim_Trailing_Nuls (Str : String) return String is
2183 for J in reverse Str'Range loop
2184 if Str (J) /= ASCII.NUL then
2185 return Str (Str'First .. J);
2190 end Trim_Trailing_Nuls;
2196 function Type_Size (L : Natural) return Natural is
2200 elsif L <= 2 ** 16 then
2214 K : Natural := 0) return Natural
2218 when Character_Position =>
2219 return Get_Char_Pos (J);
2221 when Used_Character_Set =>
2222 return Get_Used_Char (Character'Val (J));
2224 when Function_Table_1 =>
2225 return Get_Table (T1, J, K);
2227 when Function_Table_2 =>
2228 return Get_Table (T2, J, K);
2231 return Get_Graph (J);
2235 end System.Perfect_Hash_Generators;