Natools

Check-in [26569a2ae1]
Login
Overview
Comment:smat_tests: add 256 digraphs to the base-4096 dictionaries
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 26569a2ae15ea779a4bdad06e682bc9a7fec35ce
User & Date: nat on 2017-02-09 22:57:38
Other Links: manifest | tags
Context
2017-02-10
20:58
smaz_tests: update base-4096 expected streams for the new dictionaries check-in: 541596303a user: nat tags: trunk
2017-02-09
22:57
smat_tests: add 256 digraphs to the base-4096 dictionaries check-in: 26569a2ae1 user: nat tags: trunk
2017-02-08
22:23
smaz_tests: remove unneeded exception caused by byte-4096 hash function check-in: b2360c3935 user: nat tags: trunk
Changes

Modified tests/natools-smaz_tests.adb from [b4a1d57d65] to [36eaf7fc1d].

128
129
130
131
132
133
134



135
136
137
138
139
140
141
      function Upper (N : Letter_Rank) return Character
        is (Character'Val (Character'Pos ('A') - 1 + N));

      subtype Digit_Rank is Natural range 0 .. 9;
      function Image (N : Digit_Rank) return Character
        is (Character'Val (Character'Pos ('0') + N));




      Current_Index : Smaz_Implementations.Base_4096.Base_4096_Digit := 0;
      Current_Offset : Positive := 1;

      use type Smaz_Implementations.Base_4096.Base_4096_Digit;

      procedure Push_Value
        (Dict : in out Natools.Smaz_4096.Dictionary;







>
>
>







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
      function Upper (N : Letter_Rank) return Character
        is (Character'Val (Character'Pos ('A') - 1 + N));

      subtype Digit_Rank is Natural range 0 .. 9;
      function Image (N : Digit_Rank) return Character
        is (Character'Val (Character'Pos ('0') + N));

      subtype Alphanum is Character with Static_Predicate
        => Alphanum in '0' .. '9' | 'A' .. 'Z' | 'a' .. 'z';

      Current_Index : Smaz_Implementations.Base_4096.Base_4096_Digit := 0;
      Current_Offset : Positive := 1;

      use type Smaz_Implementations.Base_4096.Base_4096_Digit;

      procedure Push_Value
        (Dict : in out Natools.Smaz_4096.Dictionary;
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

























168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
           := Value;

         Current_Index := Current_Index + 1;
         Current_Offset := Current_Offset + Value'Length;
      end Push_Value;
   begin
      return Dict : Natools.Smaz_4096.Dictionary
        := (Last_Code => 3803,
            Values_Last => 8608,
            Variable_Length_Verbatim => Variable_Length_Verbatim,
            Max_Word_Length => 3,
            Offsets => <>,
            Values => <>,
            Hash => Dictionary_4096_Hash'Access)
      do

























         --  0 .. 99: two-digit numbers
         for U in Digit_Rank loop
            for V in Digit_Rank loop
               Push_Value (Dict, (1 => Image (U), 2 => Image (V)));
            end loop;
         end loop;

         --  100 .. 1099: three-digit numbers
         for U in Digit_Rank loop
            for V in Digit_Rank loop
               for W in Digit_Rank loop
                  Push_Value
                    (Dict, (1 => Image (U), 2 => Image (V), 3 => Image (W)));
               end loop;
            end loop;
         end loop;

         --  1100 .. 1775: two lower-case letters
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Lower (M), 2 => Lower (N)));
            end loop;
         end loop;

         --  1776 .. 2451: lower-case then upper-case letter
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Lower (M), 2 => Upper (N)));
            end loop;
         end loop;

         --  2452 .. 3127: upper-case then lower-case letter
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Upper (M), 2 => Lower (N)));
            end loop;
         end loop;

         --  3128 .. 3803: two upper-case letters
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Upper (M), 2 => Upper (N)));
            end loop;
         end loop;

         pragma Assert (Current_Index = Dict.Last_Code + 1);







|
|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|






|









|






|






|






|







156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
           := Value;

         Current_Index := Current_Index + 1;
         Current_Offset := Current_Offset + Value'Length;
      end Push_Value;
   begin
      return Dict : Natools.Smaz_4096.Dictionary
        := (Last_Code => 4059,
            Values_Last => 9120,
            Variable_Length_Verbatim => Variable_Length_Verbatim,
            Max_Word_Length => 3,
            Offsets => <>,
            Values => <>,
            Hash => Dictionary_4096_Hash'Access)
      do
         --  0 .. 61: space + letter
         for L in Alphanum loop
            Push_Value (Dict, (1 => ' ', 2 => L));
         end loop;

         --  62 .. 123: letter + space
         for L in Alphanum loop
            Push_Value (Dict, (1 => L, 2 => ' '));
         end loop;

         --  124 .. 185: letter + comma
         for L in Alphanum loop
            Push_Value (Dict, (1 => L, 2 => ','));
         end loop;

         --  186 .. 247: letter + period
         for L in Alphanum loop
            Push_Value (Dict, (1 => L, 2 => '.'));
         end loop;

         --  248 .. 255: double punctuation
         for L in Character range ' ' .. ''' loop
            Push_Value (Dict, (1 => L, 2 => L));
         end loop;

         --  256 .. 355: two-digit numbers
         for U in Digit_Rank loop
            for V in Digit_Rank loop
               Push_Value (Dict, (1 => Image (U), 2 => Image (V)));
            end loop;
         end loop;

         --  356 .. 1355: three-digit numbers
         for U in Digit_Rank loop
            for V in Digit_Rank loop
               for W in Digit_Rank loop
                  Push_Value
                    (Dict, (1 => Image (U), 2 => Image (V), 3 => Image (W)));
               end loop;
            end loop;
         end loop;

         --  1356 .. 2031: two lower-case letters
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Lower (M), 2 => Lower (N)));
            end loop;
         end loop;

         --  2032 .. 2707: lower-case then upper-case letter
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Lower (M), 2 => Upper (N)));
            end loop;
         end loop;

         --  2708 .. 3383: upper-case then lower-case letter
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Upper (M), 2 => Lower (N)));
            end loop;
         end loop;

         --  3384 .. 4059: two upper-case letters
         for M in Letter_Rank loop
            for N in Letter_Rank loop
               Push_Value (Dict, (1 => Upper (M), 2 => Upper (N)));
            end loop;
         end loop;

         pragma Assert (Current_Index = Dict.Last_Code + 1);
226
227
228
229
230
231
232


























233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
   begin
      case S'Length is
         when 2 =>
            declare
               U : constant Character := S (S'First);
               V : constant Character := S (S'Last);
            begin


























               if U in '0' .. '9' and then V in '0' .. '9' then
                  return 0 + Rank (U) * 10 + Rank (V);
               elsif U in 'a' .. 'z' and then V in 'a' .. 'z' then
                  return 1100 + Rank (U) * 26 + Rank (V);
               elsif U in 'a' .. 'z' and then V in 'A' .. 'Z' then
                  return 1776 + Rank (U) * 26 + Rank (V);
               elsif U in 'A' .. 'Z' and then V in 'a' .. 'z' then
                  return 2452 + Rank (U) * 26 + Rank (V);
               elsif U in 'A' .. 'Z' and then V in 'A' .. 'Z' then
                  return 3128 + Rank (U) * 26 + Rank (V);
               else
                  return 4095;
               end if;
            end;

         when 3 =>
            declare
               U : constant Character := S (S'First);
               V : constant Character := S (S'First + 1);
               W : constant Character := S (S'First + 2);
            begin
               if U in '0' .. '9'
                 and then V in '0' .. '9'
                 and then W in '0' .. '9'
               then
                  return 100 + Rank (U) * 100 + Rank (V) * 10 + Rank (W);
               else
                  return 4095;
               end if;
            end;
         when others =>
            return 4095;
      end case;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|

|

|

|

|















|







254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
   begin
      case S'Length is
         when 2 =>
            declare
               U : constant Character := S (S'First);
               V : constant Character := S (S'Last);
            begin
               if U = ' ' and then V in '0' .. '9' then
                  return Rank (V);
               elsif U = ' ' and then V in 'A' .. 'Z' then
                  return 10 + Rank (V);
               elsif U = ' ' and then V in 'a' .. 'z' then
                  return 36 + Rank (V);
               elsif U in '0' .. '9' and then V in ' ' | ',' | '.' then
                  return Rank (U)
                    + (case V is when ' ' =>  62,
                                 when ',' => 124,
                                 when '.' => 186,
                                 when others => raise Program_Error);
               elsif U in 'A' .. 'Z' and then V in ' ' | ',' | '.' then
                  return Rank (U) + 10
                    + (case V is when ' ' =>  62,
                                 when ',' => 124,
                                 when '.' => 186,
                                 when others => raise Program_Error);
               elsif U in 'a' .. 'z' and then V in ' ' | ',' | '.' then
                  return Rank (U) + 36
                    + (case V is when ' ' =>  62,
                                 when ',' => 124,
                                 when '.' => 186,
                                 when others => raise Program_Error);
               elsif U in ' ' .. ''' and then U = V then
                  return 248 + Character'Pos (U) - Character'Pos (' ');
               elsif U in '0' .. '9' and then V in '0' .. '9' then
                  return 256 + Rank (U) * 10 + Rank (V);
               elsif U in 'a' .. 'z' and then V in 'a' .. 'z' then
                  return 1356 + Rank (U) * 26 + Rank (V);
               elsif U in 'a' .. 'z' and then V in 'A' .. 'Z' then
                  return 2032 + Rank (U) * 26 + Rank (V);
               elsif U in 'A' .. 'Z' and then V in 'a' .. 'z' then
                  return 2708 + Rank (U) * 26 + Rank (V);
               elsif U in 'A' .. 'Z' and then V in 'A' .. 'Z' then
                  return 3384 + Rank (U) * 26 + Rank (V);
               else
                  return 4095;
               end if;
            end;

         when 3 =>
            declare
               U : constant Character := S (S'First);
               V : constant Character := S (S'First + 1);
               W : constant Character := S (S'First + 2);
            begin
               if U in '0' .. '9'
                 and then V in '0' .. '9'
                 and then W in '0' .. '9'
               then
                  return 356 + Rank (U) * 100 + Rank (V) * 10 + Rank (W);
               else
                  return 4095;
               end if;
            end;
         when others =>
            return 4095;
      end case;