Overview
Comment: | smaz-tools: new primitive to remove an entry from a dictionary |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
134a6f8380ec6a1c3bb21fb1837cdcba |
User & Date: | nat on 2016-10-23 21:23:51 |
Other Links: | manifest | tags |
Context
2016-10-24
| ||
19:31 | smaz-tools: new primitive to append a new string value to a dictionary check-in: 5e694df685 user: nat tags: trunk | |
2016-10-23
| ||
21:23 | smaz-tools: new primitive to remove an entry from a dictionary check-in: 134a6f8380 user: nat tags: trunk | |
2016-10-22
| ||
19:21 | tools/smaz: replace "word list" with clearer "[sample] text list" check-in: db2278efbb user: nat tags: trunk | |
Changes
Modified src/natools-smaz-tools.adb from [bad9cd1aa0] to [8bd112085b].
︙ | |||
363 364 365 366 367 368 369 370 371 372 373 374 375 376 | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | exit Read_Loop; end case; 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 is Dict_Last : constant Ada.Streams.Stream_Element |
︙ |
Modified src/natools-smaz-tools.ads from [d2634b59f6] to [62afa1f171].
︙ | |||
61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | + + + + + + + + + + + + + + + + | -- Output Ada code corresponding to the value of the dictionary. -- Note that Prefix is the actual base indentation, while Half_Indent -- 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. procedure Set_Dictionary_For_Map_Search (Dict : in Dictionary); function Map_Search (Value : String) return Natural; |
︙ |