Index: src/natools-smaz-tools.adb ================================================================== --- src/natools-smaz-tools.adb +++ src/natools-smaz-tools.adb @@ -365,10 +365,68 @@ Descriptor.Next (Event); end loop Read_Loop; end Read_List; + + function Remove_Element + (Dict : in Dictionary; + Index : in Ada.Streams.Stream_Element) + return Dictionary + is + Removed_Length : constant Positive := Dict_Entry (Dict, Index)'Length; + + function New_Offsets return Offset_Array; + function New_Values return String; + + function New_Offsets return Offset_Array is + Result : Offset_Array (0 .. Dict.Dict_Last - 1); + begin + for I in Result'Range loop + if I < Index then + Result (I) := Dict.Offsets (I); + else + Result (I) := Dict.Offsets (I + 1) - Removed_Length; + end if; + end loop; + + return Result; + end New_Offsets; + + function New_Values return String is + begin + if Index < Dict.Dict_Last then + return Dict.Values (1 .. Dict.Offsets (Index) - 1) + & Dict.Values (Dict.Offsets (Index + 1) .. Dict.Values'Last); + else + return Dict.Values (1 .. Dict.Offsets (Index) - 1); + end if; + end New_Values; + + New_Max_Word_Length : Positive := Dict.Max_Word_Length; + begin + if Removed_Length = Dict.Max_Word_Length then + New_Max_Word_Length := 1; + for I in Dict.Offsets'Range loop + if I /= Index + and then Dict_Entry (Dict, I)'Length > New_Max_Word_Length + then + New_Max_Word_Length := Dict_Entry (Dict, I)'Length; + end if; + end loop; + end if; + + return Dictionary' + (Dict_Last => Dict.Dict_Last - 1, + String_Size => Dict.String_Size - Removed_Length, + Variable_Length_Verbatim => Dict.Variable_Length_Verbatim, + Max_Word_Length => New_Max_Word_Length, + Offsets => New_Offsets, + Values => New_Values, + Hash => Dummy_Hash'Access); + end Remove_Element; + function To_Dictionary (List : in String_Lists.List; Variable_Length_Verbatim : in Boolean) return Dictionary Index: src/natools-smaz-tools.ads ================================================================== --- src/natools-smaz-tools.ads +++ src/natools-smaz-tools.ads @@ -63,10 +63,26 @@ -- is added beyond Prefix before values continued on another line. -- Frist_Prefix is used instead of Prefix on the first line. -- All the defaults value are what was used to generate the constant -- in Natools.Smaz.Original. + function Remove_Element + (Dict : in Dictionary; + Index : in Ada.Streams.Stream_Element) + return Dictionary + with Pre => Index <= Dict.Dict_Last, + Post => Dict.Dict_Last = Remove_Element'Result.Dict_Last + 1 + and then (Index = 0 + or else (for all I in 0 .. Index - 1 + => Dict_Entry (Dict, I) + = Dict_Entry (Remove_Element'Result, I))) + and then (Index = Dict.Dict_Last + or else (for all I in Index .. Dict.Dict_Last - 1 + => Dict_Entry (Dict, I + 1) + = Dict_Entry (Remove_Element'Result, I))); + -- Return a new dictionary equal to Dict without element for Index + List_For_Linear_Search : String_Lists.List; function Linear_Search (Value : String) return Natural; -- Function and data source for inefficient but dynamic function -- that can be used with Dictionary.Hash.