Natools

Check-in [d41ee1b20d]
Login
Overview
Comment:tools/smaz: add support for not adding worst word to pending list
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d41ee1b20db5f4a09398768b00239153420300f9
User & Date: nat on 2017-05-24 21:29:21
Other Links: manifest | tags
Context
2017-05-25
21:11
tools/smaz: allow Optimization_Round to increase dictionary size check-in: 44c74c875f user: nat tags: trunk
2017-05-24
21:29
tools/smaz: add support for not adding worst word to pending list check-in: d41ee1b20d user: nat tags: trunk
2017-05-23
20:15
tools/smaz: allow Optimization_Round to reduce dictionary size check-in: c3f4498cb8 user: nat tags: trunk
Changes

Modified tools/smaz.adb from [3c3e05eba8] to [ac8c1a7478].

595
596
597
598
599
600
601

602
603
604
605
606
607
608
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609







+







         Original : constant Dictionary := Dict.Element;
         Worst_Index : constant Dictionary_Entry
           := Worst_Element
              (Original, Counts, Method, First, Last_Code (Original));
         Worst_Value : constant String
           := Dict_Entry (Original, Worst_Index);
         Worst_Count : constant String_Count := Counts (Worst_Index);
         Worst_Removed : Boolean := False;
         Base : constant Dictionary
           := Remove_Element (Original, Worst_Index);
         Old_Score : constant Ada.Streams.Stream_Element_Count := Score;
      begin
         Updated := False;

         for Position in Pending_Words.Iterate loop
616
617
618
619
620
621
622

623
624
625
626
627
628
629
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631







+







                 (Job_Count, New_Dict, Input_Texts, New_Score, New_Counts);

               if New_Score < Score then
                  Dict := Holders.To_Holder (New_Dict);
                  Score := New_Score;
                  Counts := New_Counts;
                  No_Longer_Pending := Position;
                  Worst_Removed := True;
                  Updated := True;
                  Log_Message := Ada.Strings.Unbounded.To_Unbounded_String
                    ("Removing"
                     & Worst_Count'Img & "x "
                     & Natools.String_Escapes.C_Escape_Hex (Worst_Value, True)
                     & ", adding"
                     & Counts (Last_Code (New_Dict))'Img & "x "
647
648
649
650
651
652
653

654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

674


675
676
677
678
679
680
681
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
685
686







+




















+
-
+
+







                 (Job_Count, Base, Input_Texts, New_Score, New_Counts);

               if New_Score <= Score then
                  Dict := Holders.To_Holder (Base);
                  Score := New_Score;
                  Counts := New_Counts;
                  No_Longer_Pending := String_Lists.No_Element;
                  Worst_Removed := True;
                  Updated := True;
                  Log_Message := Ada.Strings.Unbounded.To_Unbounded_String
                    ("Removing"
                     & Worst_Count'Img & "x "
                     & Natools.String_Escapes.C_Escape_Hex (Worst_Value, True)
                     & ", size"
                     & Score'Img
                     & " ("
                     & Ada.Streams.Stream_Element_Offset'Image
                        (Score - Old_Score)
                     & ')');
               end if;
            end;
         end if;

         if Updated then
            if String_Lists.Has_Element (No_Longer_Pending) then
               Pending_Words.Delete (No_Longer_Pending);
            end if;

            if Worst_Removed then
            Pending_Words.Append (Worst_Value);
               Pending_Words.Append (Worst_Value);
            end if;

            Ada.Text_IO.Put_Line
              (Ada.Text_IO.Current_Error,
               Ada.Strings.Unbounded.To_String (Log_Message));
         end if;
      end Optimization_Round;