Overview
Comment: | tools/smaz: genericize Parallel_Evaluate_Dictionary |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
79a36ec95798ba0f668463f2740ea175 |
User & Date: | nat on 2016-12-02 21:12:32 |
Other Links: | manifest | tags |
Context
2016-12-03
| ||
22:29 | tools/smaz: genericize Evaluate_Dictionary check-in: bc86bc41ee user: nat tags: trunk | |
2016-12-02
| ||
21:12 | tools/smaz: genericize Parallel_Evaluate_Dictionary check-in: 79a36ec957 user: nat tags: trunk | |
2016-12-01
| ||
20:10 | tools/smaz: refactor dictionary processing in a dedicated procedure check-in: ef7006737f user: nat tags: trunk | |
Changes
Modified tools/smaz.adb from [d614874f0e] to [876acf9894].
︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | + | ------------------------------------------------------------------------------ -- Command Line Interface for primitives in Natools.Smaz.Tools. -- ------------------------------------------------------------------------------ with Ada.Characters.Latin_1; with Ada.Command_Line; with Ada.Containers.Indefinite_Doubly_Linked_Lists; with Ada.Containers.Indefinite_Holders; with Ada.Streams; with Ada.Strings.Fixed; with Ada.Strings.Unbounded; with Ada.Text_IO.Text_Streams; with Natools.Getopt_Long; with Natools.Parallelism; |
︙ | |||
154 155 156 157 158 159 160 | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | - - - - - - - - - | Input_Texts : in Natools.Smaz_Tools.String_Lists.List; Job_Count : in Natural; Method : in Methods.Enum) return Natools.Smaz_256.Dictionary; -- Optimize the dictionary on Input_Texts, starting with Base and -- adding substrings from Pending_Words. |
︙ | |||
190 191 192 193 194 195 196 197 198 199 200 201 202 203 | 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 242 243 244 245 246 247 248 249 250 251 252 253 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 320 321 322 323 324 325 326 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | function To_Dictionary (Handler : in Callback'Class; Input : in Natools.Smaz_Tools.String_Lists.List) return Natools.Smaz_256.Dictionary; -- Convert the input into a dictionary given the option in Handler generic type Dictionary (<>) is private; type Dictionary_Entry is (<>); type String_Count is range <>; type Dictionary_Counts is array (Dictionary_Entry) of String_Count; with package String_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists (String); with procedure Evaluate_Dictionary_Partial (Dict : in Dictionary; Corpus_Entry : in String; Compressed_Size : in out Ada.Streams.Stream_Element_Count; Counts : in out Dictionary_Counts); package Dictionary_Subprograms is procedure Parallel_Evaluate_Dictionary (Job_Count : in Positive; Dict : in Dictionary; Corpus : in String_Lists.List; Compressed_Size : out Ada.Streams.Stream_Element_Count; Counts : out Dictionary_Counts); -- Return the same results as Natools.Smaz.Tools.Evaluate_Dictionary, -- but hopefully more quickly, using Job_Count tasks. end Dictionary_Subprograms; package body Dictionary_Subprograms is procedure Parallel_Evaluate_Dictionary (Job_Count : in Positive; Dict : in Dictionary; Corpus : in String_Lists.List; Compressed_Size : out Ada.Streams.Stream_Element_Count; Counts : out Dictionary_Counts) is type Result_Values is record Compressed_Size : Ada.Streams.Stream_Element_Count; Counts : Dictionary_Counts; end record; procedure Initialize (Result : in out Result_Values); procedure Get_Next_Job (Global : in out String_Lists.Cursor; Job : out String_Lists.Cursor; Terminated : out Boolean); procedure Do_Job (Result : in out Result_Values; Job : in String_Lists.Cursor); procedure Gather_Result (Global : in out String_Lists.Cursor; Partial : in Result_Values); procedure Initialize (Result : in out Result_Values) is begin Result := (Compressed_Size => 0, Counts => (others => 0)); end Initialize; procedure Get_Next_Job (Global : in out String_Lists.Cursor; Job : out String_Lists.Cursor; Terminated : out Boolean) is begin Job := Global; Terminated := not String_Lists.Has_Element (Global); if not Terminated then String_Lists.Next (Global); end if; end Get_Next_Job; procedure Do_Job (Result : in out Result_Values; Job : in String_Lists.Cursor) is begin Evaluate_Dictionary_Partial (Dict, String_Lists.Element (Job), Result.Compressed_Size, Result.Counts); end Do_Job; procedure Gather_Result (Global : in out String_Lists.Cursor; Partial : in Result_Values) is pragma Unreferenced (Global); use type Ada.Streams.Stream_Element_Count; use type Natools.Smaz_Tools.String_Count; begin Compressed_Size := Compressed_Size + Partial.Compressed_Size; for I in Counts'Range loop Counts (I) := Counts (I) + Partial.Counts (I); end loop; end Gather_Result; procedure Parallel_Run is new Natools.Parallelism.Per_Task_Accumulator_Run (String_Lists.Cursor, Result_Values, String_Lists.Cursor); Cursor : String_Lists.Cursor := String_Lists.First (Corpus); begin Compressed_Size := 0; Counts := (others => 0); Parallel_Run (Cursor, Job_Count); end Parallel_Evaluate_Dictionary; end Dictionary_Subprograms; package Dict_256 is new Dictionary_Subprograms (Dictionary => Natools.Smaz_256.Dictionary, Dictionary_Entry => Ada.Streams.Stream_Element, String_Count => Natools.Smaz_Tools.String_Count, Dictionary_Counts => Tools_256.Dictionary_Counts, String_Lists => Natools.Smaz_Tools.String_Lists, Evaluate_Dictionary_Partial => Tools_256.Evaluate_Dictionary_Partial); overriding procedure Option (Handler : in out Callback; Id : in Options.Id; Argument : in String) is begin case Id is |
︙ | |||
315 316 317 318 319 320 321 | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | - + | (Natools.Smaz_256.Dict_Entry (Actual_Dict, I), True) & " ->" & Natural'Image (Natools.Smaz_Tools.Trie_Search (Natools.Smaz_256.Dict_Entry (Actual_Dict, I)))); end if; end loop; if Job_Count > 0 then |
︙ | |||
460 461 462 463 464 465 466 | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Method, Running); end loop; return Holder.Element; end Optimize_Dictionary; |
︙ | |||
757 758 759 760 761 762 763 | 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | + - + - | Sx_Output : Natools.S_Expressions.Printers.Canonical (Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Current_Output)); Ada_Dictionary : constant String := Ada.Strings.Unbounded.To_String (Handler.Ada_Dictionary); Hash_Package : constant String := Ada.Strings.Unbounded.To_String (Handler.Hash_Package); begin Natools.Smaz_Tools.Set_Dictionary_For_Trie_Search (Word_List); |
︙ |