Differences From Artifact [2d303fae46]:
- File
src/natools-static_hash_maps.adb
— part of check-in
[582f564b61]
at
2014-05-18 20:20:13
on branch trunk
— static_hash_maps: new code generation package to build static hash maps
A static hash map means here a hash maps completely known before compile time. It uses GNAT.Perfect_Hash_Generator to turn string keys into indexes for an array of elements. (user: nat, size: 16980) [annotate] [blame] [check-ins using]
To Artifact [8a60f68029]:
- File src/natools-static_hash_maps.adb — part of check-in [ddc10181a8] at 2014-05-24 13:03:03 on branch trunk — static_hash_maps: retry perfect hash generation when it fails (user: nat, size: 17645) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
134 135 136 137 138 139 140 | Ada.Text_IO.Put_Line (File, " end if;"); Ada.Text_IO.Put_Line (File, " end " & To_String (Map.Function_Name) & ';'); end Write_Map_Body; procedure Write_Map_Hash_Package (Map : in Map_Description) is | | > > > > | | > > > > > > > > > > > > > > > > > > > > > | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | Ada.Text_IO.Put_Line (File, " end if;"); Ada.Text_IO.Put_Line (File, " end " & To_String (Map.Function_Name) & ';'); end Write_Map_Body; procedure Write_Map_Hash_Package (Map : in Map_Description) is Seed : Natural := 2; NK : constant Float := Float (Map.Nodes.Length); NV : Natural := Natural (Map.Nodes.Length) * 2 + 1; Cursor : Node_Lists.Cursor := Map.Nodes.First; begin while Node_Lists.Has_Element (Cursor) loop GNAT.Perfect_Hash_Generators.Insert (To_String (Node_Lists.Element (Cursor).Key)); Node_Lists.Next (Cursor); end loop; loop begin GNAT.Perfect_Hash_Generators.Initialize (Seed, Float (NV) / NK); GNAT.Perfect_Hash_Generators.Compute; exit; exception when GNAT.Perfect_Hash_Generators.Too_Many_Tries => null; end; Seed := Seed * NV; begin GNAT.Perfect_Hash_Generators.Initialize (Seed, Float (NV) / NK); GNAT.Perfect_Hash_Generators.Compute; exit; exception when GNAT.Perfect_Hash_Generators.Too_Many_Tries => null; end; NV := NV + 1; Seed := NV; end loop; GNAT.Perfect_Hash_Generators.Produce (To_String (Map.Hash_Package_Name)); GNAT.Perfect_Hash_Generators.Finalize; exception when others => GNAT.Perfect_Hash_Generators.Finalize; raise; end Write_Map_Hash_Package; |
︙ | ︙ |