Differences From Artifact [8876c91a07]:
- File src/natools-smaz_generic.ads — part of check-in [7ae85f4e93] at 2016-12-13 22:09:00 on branch trunk — smaz_generic: remove the too-costly dynamic predicate (user: nat, size: 5788) [annotate] [blame] [check-ins using]
To Artifact [90fa9f96a9]:
- File
src/natools-smaz_generic.ads
— part of check-in
[ec19d3153c]
at
2016-12-14 20:01:08
on branch trunk
— smaz_generic: brind the predicate back as a separate function
Since Smaz dictionaries are meant to be global hard-coded constant objects, it makes sense to check the precondition only once, e.g. in a test suite, and not for each and every subprogram call. (user: nat, size: 6570) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | (Dict : in Dictionary; Code : in Dictionary_Code) return Positive is (1 + Code_Last (Dict.Offsets, Code, Dict.Values'Last) - Code_First (Dict.Offsets, Code, Dict.Values'First)) with Pre => Is_Valid_Code (Dict, Code); -- Return the length of the string for at the given Index in Dict function Compressed_Upper_Bound (Dict : in Dictionary; Input : in String) return Ada.Streams.Stream_Element_Count; -- Return the maximum number of bytes needed to encode Input | > > > > > > > > > > > > > | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | (Dict : in Dictionary; Code : in Dictionary_Code) return Positive is (1 + Code_Last (Dict.Offsets, Code, Dict.Values'Last) - Code_First (Dict.Offsets, Code, Dict.Values'First)) with Pre => Is_Valid_Code (Dict, Code); -- Return the length of the string for at the given Index in Dict function Is_Valid (Dictionary : in Smaz_Generic.Dictionary) return Boolean is ((for all Code in Dictionary.Offsets'Range => Dictionary.Offsets (Code) in Dictionary.Values'Range) and then (for all Code in Dictionary_Code'First .. Dictionary.Last_Code => Code_Last (Dictionary.Offsets, Code, Dictionary.Values'Last) + 1 - Code_First (Dictionary.Offsets, Code, Dictionary.Values'First) in 1 .. Dictionary.Max_Word_Length) and then (for all Code in Dictionary_Code'First .. Dictionary.Last_Code => Dictionary_Code'Val (Dictionary.Hash (Dict_Entry (Dictionary, Code))) = Code)); -- Check all the assumptions made on Dictionary objects. function Compressed_Upper_Bound (Dict : in Dictionary; Input : in String) return Ada.Streams.Stream_Element_Count; -- Return the maximum number of bytes needed to encode Input |
︙ | ︙ |