netgen-mesher 6.2.2506.post35.dev0__cp314-cp314-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. netgen/NgOCC.py +7 -0
  2. netgen/__init__.py +114 -0
  3. netgen/__init__.pyi +22 -0
  4. netgen/__main__.py +53 -0
  5. netgen/cmake/NetgenConfig.cmake +79 -0
  6. netgen/cmake/netgen-targets-release.cmake +69 -0
  7. netgen/cmake/netgen-targets.cmake +146 -0
  8. netgen/config/__init__.py +1 -0
  9. netgen/config/__init__.pyi +52 -0
  10. netgen/config/__main__.py +4 -0
  11. netgen/config/config.py +68 -0
  12. netgen/config/config.pyi +54 -0
  13. netgen/csg.py +25 -0
  14. netgen/geom2d.py +178 -0
  15. netgen/gui.py +82 -0
  16. netgen/include/core/archive.hpp +1256 -0
  17. netgen/include/core/array.hpp +1760 -0
  18. netgen/include/core/autodiff.hpp +1131 -0
  19. netgen/include/core/autodiffdiff.hpp +733 -0
  20. netgen/include/core/bitarray.hpp +240 -0
  21. netgen/include/core/concurrentqueue.h +3619 -0
  22. netgen/include/core/exception.hpp +145 -0
  23. netgen/include/core/flags.hpp +199 -0
  24. netgen/include/core/hashtable.hpp +1281 -0
  25. netgen/include/core/localheap.hpp +318 -0
  26. netgen/include/core/logging.hpp +117 -0
  27. netgen/include/core/memtracer.hpp +221 -0
  28. netgen/include/core/mpi4py_pycapi.h +245 -0
  29. netgen/include/core/mpi_wrapper.hpp +643 -0
  30. netgen/include/core/ng_mpi.hpp +94 -0
  31. netgen/include/core/ng_mpi_generated_declarations.hpp +155 -0
  32. netgen/include/core/ng_mpi_native.hpp +25 -0
  33. netgen/include/core/ngcore.hpp +32 -0
  34. netgen/include/core/ngcore_api.hpp +152 -0
  35. netgen/include/core/ngstream.hpp +115 -0
  36. netgen/include/core/paje_trace.hpp +279 -0
  37. netgen/include/core/profiler.hpp +382 -0
  38. netgen/include/core/python_ngcore.hpp +457 -0
  39. netgen/include/core/ranges.hpp +109 -0
  40. netgen/include/core/register_archive.hpp +100 -0
  41. netgen/include/core/signal.hpp +82 -0
  42. netgen/include/core/simd.hpp +160 -0
  43. netgen/include/core/simd_arm64.hpp +407 -0
  44. netgen/include/core/simd_avx.hpp +394 -0
  45. netgen/include/core/simd_avx512.hpp +285 -0
  46. netgen/include/core/simd_generic.hpp +1053 -0
  47. netgen/include/core/simd_math.hpp +178 -0
  48. netgen/include/core/simd_sse.hpp +289 -0
  49. netgen/include/core/statushandler.hpp +37 -0
  50. netgen/include/core/symboltable.hpp +153 -0
  51. netgen/include/core/table.hpp +810 -0
  52. netgen/include/core/taskmanager.hpp +1161 -0
  53. netgen/include/core/type_traits.hpp +65 -0
  54. netgen/include/core/utils.hpp +385 -0
  55. netgen/include/core/version.hpp +102 -0
  56. netgen/include/core/xbool.hpp +47 -0
  57. netgen/include/csg/algprim.hpp +563 -0
  58. netgen/include/csg/brick.hpp +150 -0
  59. netgen/include/csg/csg.hpp +43 -0
  60. netgen/include/csg/csgeom.hpp +389 -0
  61. netgen/include/csg/csgparser.hpp +101 -0
  62. netgen/include/csg/curve2d.hpp +67 -0
  63. netgen/include/csg/edgeflw.hpp +112 -0
  64. netgen/include/csg/explicitcurve2d.hpp +113 -0
  65. netgen/include/csg/extrusion.hpp +185 -0
  66. netgen/include/csg/gencyl.hpp +70 -0
  67. netgen/include/csg/geoml.hpp +16 -0
  68. netgen/include/csg/identify.hpp +213 -0
  69. netgen/include/csg/manifold.hpp +29 -0
  70. netgen/include/csg/meshsurf.hpp +46 -0
  71. netgen/include/csg/polyhedra.hpp +121 -0
  72. netgen/include/csg/revolution.hpp +180 -0
  73. netgen/include/csg/singularref.hpp +84 -0
  74. netgen/include/csg/solid.hpp +295 -0
  75. netgen/include/csg/specpoin.hpp +194 -0
  76. netgen/include/csg/spline3d.hpp +99 -0
  77. netgen/include/csg/splinesurface.hpp +85 -0
  78. netgen/include/csg/surface.hpp +394 -0
  79. netgen/include/csg/triapprox.hpp +63 -0
  80. netgen/include/csg/vscsg.hpp +34 -0
  81. netgen/include/general/autodiff.hpp +356 -0
  82. netgen/include/general/autoptr.hpp +39 -0
  83. netgen/include/general/gzstream.h +121 -0
  84. netgen/include/general/hashtabl.hpp +1692 -0
  85. netgen/include/general/myadt.hpp +48 -0
  86. netgen/include/general/mystring.hpp +226 -0
  87. netgen/include/general/netgenout.hpp +205 -0
  88. netgen/include/general/ngarray.hpp +797 -0
  89. netgen/include/general/ngbitarray.hpp +149 -0
  90. netgen/include/general/ngpython.hpp +74 -0
  91. netgen/include/general/optmem.hpp +44 -0
  92. netgen/include/general/parthreads.hpp +138 -0
  93. netgen/include/general/seti.hpp +50 -0
  94. netgen/include/general/sort.hpp +47 -0
  95. netgen/include/general/spbita2d.hpp +59 -0
  96. netgen/include/general/stack.hpp +114 -0
  97. netgen/include/general/table.hpp +280 -0
  98. netgen/include/general/template.hpp +509 -0
  99. netgen/include/geom2d/csg2d.hpp +750 -0
  100. netgen/include/geom2d/geometry2d.hpp +280 -0
  101. netgen/include/geom2d/spline2d.hpp +234 -0
  102. netgen/include/geom2d/vsgeom2d.hpp +28 -0
  103. netgen/include/gprim/adtree.hpp +1392 -0
  104. netgen/include/gprim/geom2d.hpp +858 -0
  105. netgen/include/gprim/geom3d.hpp +749 -0
  106. netgen/include/gprim/geomfuncs.hpp +212 -0
  107. netgen/include/gprim/geomobjects.hpp +544 -0
  108. netgen/include/gprim/geomops.hpp +404 -0
  109. netgen/include/gprim/geomtest3d.hpp +101 -0
  110. netgen/include/gprim/gprim.hpp +33 -0
  111. netgen/include/gprim/spline.hpp +778 -0
  112. netgen/include/gprim/splinegeometry.hpp +73 -0
  113. netgen/include/gprim/transform3d.hpp +216 -0
  114. netgen/include/include/acisgeom.hpp +3 -0
  115. netgen/include/include/csg.hpp +1 -0
  116. netgen/include/include/geometry2d.hpp +1 -0
  117. netgen/include/include/gprim.hpp +1 -0
  118. netgen/include/include/incopengl.hpp +62 -0
  119. netgen/include/include/inctcl.hpp +13 -0
  120. netgen/include/include/incvis.hpp +6 -0
  121. netgen/include/include/linalg.hpp +1 -0
  122. netgen/include/include/meshing.hpp +1 -0
  123. netgen/include/include/myadt.hpp +1 -0
  124. netgen/include/include/mydefs.hpp +70 -0
  125. netgen/include/include/mystdlib.h +59 -0
  126. netgen/include/include/netgen_config.hpp +27 -0
  127. netgen/include/include/netgen_version.hpp +9 -0
  128. netgen/include/include/nginterface_v2_impl.hpp +395 -0
  129. netgen/include/include/ngsimd.hpp +1 -0
  130. netgen/include/include/occgeom.hpp +1 -0
  131. netgen/include/include/opti.hpp +1 -0
  132. netgen/include/include/parallel.hpp +1 -0
  133. netgen/include/include/stlgeom.hpp +1 -0
  134. netgen/include/include/visual.hpp +1 -0
  135. netgen/include/interface/rw_medit.hpp +11 -0
  136. netgen/include/interface/writeuser.hpp +80 -0
  137. netgen/include/linalg/densemat.hpp +414 -0
  138. netgen/include/linalg/linalg.hpp +29 -0
  139. netgen/include/linalg/opti.hpp +142 -0
  140. netgen/include/linalg/polynomial.hpp +47 -0
  141. netgen/include/linalg/vector.hpp +217 -0
  142. netgen/include/meshing/adfront2.hpp +274 -0
  143. netgen/include/meshing/adfront3.hpp +332 -0
  144. netgen/include/meshing/basegeom.hpp +370 -0
  145. netgen/include/meshing/bcfunctions.hpp +53 -0
  146. netgen/include/meshing/bisect.hpp +72 -0
  147. netgen/include/meshing/boundarylayer.hpp +113 -0
  148. netgen/include/meshing/classifyhpel.hpp +1984 -0
  149. netgen/include/meshing/clusters.hpp +46 -0
  150. netgen/include/meshing/curvedelems.hpp +274 -0
  151. netgen/include/meshing/delaunay2d.hpp +73 -0
  152. netgen/include/meshing/fieldlines.hpp +103 -0
  153. netgen/include/meshing/findip.hpp +198 -0
  154. netgen/include/meshing/findip2.hpp +103 -0
  155. netgen/include/meshing/geomsearch.hpp +69 -0
  156. netgen/include/meshing/global.hpp +54 -0
  157. netgen/include/meshing/hpref_hex.hpp +330 -0
  158. netgen/include/meshing/hpref_prism.hpp +3405 -0
  159. netgen/include/meshing/hpref_pyramid.hpp +154 -0
  160. netgen/include/meshing/hpref_quad.hpp +2082 -0
  161. netgen/include/meshing/hpref_segm.hpp +122 -0
  162. netgen/include/meshing/hpref_tet.hpp +4230 -0
  163. netgen/include/meshing/hpref_trig.hpp +848 -0
  164. netgen/include/meshing/hprefinement.hpp +366 -0
  165. netgen/include/meshing/improve2.hpp +178 -0
  166. netgen/include/meshing/improve3.hpp +151 -0
  167. netgen/include/meshing/localh.hpp +223 -0
  168. netgen/include/meshing/meshclass.hpp +1076 -0
  169. netgen/include/meshing/meshfunc.hpp +47 -0
  170. netgen/include/meshing/meshing.hpp +63 -0
  171. netgen/include/meshing/meshing2.hpp +163 -0
  172. netgen/include/meshing/meshing3.hpp +123 -0
  173. netgen/include/meshing/meshtool.hpp +90 -0
  174. netgen/include/meshing/meshtype.hpp +1930 -0
  175. netgen/include/meshing/msghandler.hpp +62 -0
  176. netgen/include/meshing/paralleltop.hpp +172 -0
  177. netgen/include/meshing/python_mesh.hpp +206 -0
  178. netgen/include/meshing/ruler2.hpp +172 -0
  179. netgen/include/meshing/ruler3.hpp +211 -0
  180. netgen/include/meshing/soldata.hpp +141 -0
  181. netgen/include/meshing/specials.hpp +17 -0
  182. netgen/include/meshing/surfacegeom.hpp +73 -0
  183. netgen/include/meshing/topology.hpp +1003 -0
  184. netgen/include/meshing/validate.hpp +21 -0
  185. netgen/include/meshing/visual_interface.hpp +71 -0
  186. netgen/include/mydefs.hpp +70 -0
  187. netgen/include/nginterface.h +474 -0
  188. netgen/include/nginterface_v2.hpp +406 -0
  189. netgen/include/nglib.h +697 -0
  190. netgen/include/nglib_occ.h +50 -0
  191. netgen/include/occ/occ_edge.hpp +47 -0
  192. netgen/include/occ/occ_face.hpp +52 -0
  193. netgen/include/occ/occ_solid.hpp +23 -0
  194. netgen/include/occ/occ_utils.hpp +376 -0
  195. netgen/include/occ/occ_vertex.hpp +30 -0
  196. netgen/include/occ/occgeom.hpp +659 -0
  197. netgen/include/occ/occmeshsurf.hpp +168 -0
  198. netgen/include/occ/vsocc.hpp +33 -0
  199. netgen/include/pybind11/LICENSE +29 -0
  200. netgen/include/pybind11/attr.h +722 -0
  201. netgen/include/pybind11/buffer_info.h +208 -0
  202. netgen/include/pybind11/cast.h +2361 -0
  203. netgen/include/pybind11/chrono.h +228 -0
  204. netgen/include/pybind11/common.h +2 -0
  205. netgen/include/pybind11/complex.h +74 -0
  206. netgen/include/pybind11/conduit/README.txt +15 -0
  207. netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
  208. netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
  209. netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
  210. netgen/include/pybind11/critical_section.h +56 -0
  211. netgen/include/pybind11/detail/class.h +823 -0
  212. netgen/include/pybind11/detail/common.h +1348 -0
  213. netgen/include/pybind11/detail/cpp_conduit.h +75 -0
  214. netgen/include/pybind11/detail/descr.h +226 -0
  215. netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
  216. netgen/include/pybind11/detail/exception_translation.h +71 -0
  217. netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
  218. netgen/include/pybind11/detail/init.h +538 -0
  219. netgen/include/pybind11/detail/internals.h +799 -0
  220. netgen/include/pybind11/detail/native_enum_data.h +209 -0
  221. netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
  222. netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
  223. netgen/include/pybind11/detail/type_caster_base.h +1591 -0
  224. netgen/include/pybind11/detail/typeid.h +65 -0
  225. netgen/include/pybind11/detail/using_smart_holder.h +22 -0
  226. netgen/include/pybind11/detail/value_and_holder.h +90 -0
  227. netgen/include/pybind11/eigen/common.h +9 -0
  228. netgen/include/pybind11/eigen/matrix.h +723 -0
  229. netgen/include/pybind11/eigen/tensor.h +521 -0
  230. netgen/include/pybind11/eigen.h +12 -0
  231. netgen/include/pybind11/embed.h +320 -0
  232. netgen/include/pybind11/eval.h +161 -0
  233. netgen/include/pybind11/functional.h +147 -0
  234. netgen/include/pybind11/gil.h +199 -0
  235. netgen/include/pybind11/gil_safe_call_once.h +102 -0
  236. netgen/include/pybind11/gil_simple.h +37 -0
  237. netgen/include/pybind11/iostream.h +265 -0
  238. netgen/include/pybind11/native_enum.h +67 -0
  239. netgen/include/pybind11/numpy.h +2312 -0
  240. netgen/include/pybind11/operators.h +202 -0
  241. netgen/include/pybind11/options.h +92 -0
  242. netgen/include/pybind11/pybind11.h +3645 -0
  243. netgen/include/pybind11/pytypes.h +2680 -0
  244. netgen/include/pybind11/stl/filesystem.h +114 -0
  245. netgen/include/pybind11/stl.h +666 -0
  246. netgen/include/pybind11/stl_bind.h +858 -0
  247. netgen/include/pybind11/subinterpreter.h +299 -0
  248. netgen/include/pybind11/trampoline_self_life_support.h +65 -0
  249. netgen/include/pybind11/type_caster_pyobject_ptr.h +61 -0
  250. netgen/include/pybind11/typing.h +298 -0
  251. netgen/include/pybind11/warnings.h +75 -0
  252. netgen/include/stlgeom/meshstlsurface.hpp +67 -0
  253. netgen/include/stlgeom/stlgeom.hpp +491 -0
  254. netgen/include/stlgeom/stlline.hpp +193 -0
  255. netgen/include/stlgeom/stltool.hpp +331 -0
  256. netgen/include/stlgeom/stltopology.hpp +419 -0
  257. netgen/include/stlgeom/vsstl.hpp +58 -0
  258. netgen/include/visualization/meshdoc.hpp +42 -0
  259. netgen/include/visualization/mvdraw.hpp +325 -0
  260. netgen/include/visualization/vispar.hpp +128 -0
  261. netgen/include/visualization/visual.hpp +28 -0
  262. netgen/include/visualization/visual_api.hpp +10 -0
  263. netgen/include/visualization/vssolution.hpp +399 -0
  264. netgen/lib/libnggui.lib +0 -0
  265. netgen/lib/ngcore.lib +0 -0
  266. netgen/lib/nglib.lib +0 -0
  267. netgen/lib/togl.lib +0 -0
  268. netgen/libnggui.dll +0 -0
  269. netgen/libngguipy.lib +0 -0
  270. netgen/libngguipy.pyd +0 -0
  271. netgen/libngpy/_NgOCC.pyi +1545 -0
  272. netgen/libngpy/__init__.pyi +7 -0
  273. netgen/libngpy/_csg.pyi +259 -0
  274. netgen/libngpy/_geom2d.pyi +323 -0
  275. netgen/libngpy/_meshing.pyi +1111 -0
  276. netgen/libngpy/_stl.pyi +131 -0
  277. netgen/libngpy.lib +0 -0
  278. netgen/libngpy.pyd +0 -0
  279. netgen/meshing.py +65 -0
  280. netgen/ngcore.dll +0 -0
  281. netgen/nglib.dll +0 -0
  282. netgen/occ.py +52 -0
  283. netgen/read_gmsh.py +259 -0
  284. netgen/read_meshio.py +22 -0
  285. netgen/stl.py +2 -0
  286. netgen/togl.dll +0 -0
  287. netgen/version.py +2 -0
  288. netgen/webgui.py +529 -0
  289. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boundarycondition.geo +16 -0
  290. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boxcyl.geo +32 -0
  291. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/circle_on_cube.geo +27 -0
  292. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cone.geo +13 -0
  293. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cube.geo +16 -0
  294. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandring.geo +55 -0
  295. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandspheres.geo +21 -0
  296. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemcyl.geo +18 -0
  297. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemsphere.geo +19 -0
  298. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylinder.geo +12 -0
  299. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylsphere.geo +12 -0
  300. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/doc/ng4.pdf +0 -0
  301. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipsoid.geo +8 -0
  302. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipticcyl.geo +10 -0
  303. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/extrusion.geo +99 -0
  304. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/fichera.geo +24 -0
  305. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/frame.step +11683 -0
  306. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/hinge.stl +8486 -0
  307. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/lshape3d.geo +26 -0
  308. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes.geo +26 -0
  309. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes2.geo +26 -0
  310. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/matrix.geo +27 -0
  311. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ortho.geo +11 -0
  312. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/part1.stl +2662 -0
  313. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/period.geo +33 -0
  314. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/exportNeutral.py +26 -0
  315. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/mesh.py +19 -0
  316. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/shaft.geo +65 -0
  317. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/revolution.geo +18 -0
  318. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/screw.step +1694 -0
  319. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sculpture.geo +13 -0
  320. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shaft.geo +65 -0
  321. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shell.geo +10 -0
  322. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphere.geo +8 -0
  323. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphereincube.geo +17 -0
  324. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/square.in2d +35 -0
  325. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarecircle.in2d +48 -0
  326. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarehole.in2d +47 -0
  327. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/torus.geo +8 -0
  328. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/trafo.geo +57 -0
  329. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twobricks.geo +15 -0
  330. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocubes.geo +18 -0
  331. netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocyl.geo +16 -0
  332. netgen_mesher-6.2.2506.post35.dev0.dist-info/METADATA +15 -0
  333. netgen_mesher-6.2.2506.post35.dev0.dist-info/RECORD +340 -0
  334. netgen_mesher-6.2.2506.post35.dev0.dist-info/WHEEL +5 -0
  335. netgen_mesher-6.2.2506.post35.dev0.dist-info/entry_points.txt +2 -0
  336. netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/AUTHORS +1 -0
  337. netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/LICENSE +504 -0
  338. netgen_mesher-6.2.2506.post35.dev0.dist-info/top_level.txt +2 -0
  339. pyngcore/__init__.py +1 -0
  340. pyngcore/pyngcore.cp314-win_amd64.pyd +0 -0
@@ -0,0 +1,1692 @@
1
+ #ifndef FILE_HASHTABL
2
+ #define FILE_HASHTABL
3
+
4
+ /**************************************************************************/
5
+ /* File: hashtabl.hh */
6
+ /* Author: Joachim Schoeberl */
7
+ /* Date: 01. Jun. 95 */
8
+ /**************************************************************************/
9
+
10
+ #include "table.hpp"
11
+
12
+ namespace netgen
13
+ {
14
+
15
+ /**
16
+ Abstract data type HASHTABLE.
17
+ Hash is done by one INDEX
18
+ */
19
+ class BASE_INDEX_HASHTABLE
20
+ {
21
+ protected:
22
+ /// keys are stored in this table
23
+ TABLE<INDEX,1> hash;
24
+
25
+ public:
26
+ ///
27
+ BASE_INDEX_HASHTABLE (int size)
28
+ : hash (size) { };
29
+
30
+ protected:
31
+ ///
32
+ int HashValue (const INDEX & ind) const
33
+ {
34
+ return ind % hash.Size() + 1;
35
+ }
36
+
37
+ ///
38
+ int Position (int bnr, const INDEX & ind) const;
39
+ };
40
+
41
+ ///
42
+ template <class T>
43
+ class INDEX_HASHTABLE : private BASE_INDEX_HASHTABLE
44
+ {
45
+ ///
46
+ TABLE<T,1> cont;
47
+
48
+ public:
49
+ ///
50
+ inline INDEX_HASHTABLE (int size);
51
+ ///
52
+ inline void Set (const INDEX & hash, const T & acont);
53
+ ///
54
+ inline const T & Get (const INDEX & ahash) const;
55
+ ///
56
+ inline bool Used (const INDEX & ahash) const;
57
+ ///
58
+ inline int GetNBags () const;
59
+ ///
60
+ inline int GetBagSize (int bnr) const;
61
+ ///
62
+ inline void GetData (int bnr, int colnr, INDEX & ahash, T & acont) const;
63
+
64
+ ///
65
+ inline void PrintMemInfo (ostream & ost) const;
66
+ };
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+ ///
78
+ class BASE_INDEX_2_HASHTABLE
79
+ {
80
+ protected:
81
+ ///
82
+ TABLE<INDEX_2> hash;
83
+
84
+ public:
85
+ ///
86
+ BASE_INDEX_2_HASHTABLE () { ; }
87
+
88
+ BASE_INDEX_2_HASHTABLE (int size)
89
+ : hash (size) { };
90
+
91
+ ///
92
+ void PrintStat (ostream & ost) const;
93
+ void BaseSetSize(int s) {hash.SetSize(s);}
94
+ //protected:
95
+ ///
96
+ int HashValue (const INDEX_2 & ind) const
97
+ {
98
+ return (ind.I1() + ind.I2()) % hash.Size() + 1;
99
+ }
100
+ ///
101
+ int Position (int bnr, const INDEX_2 & ind) const
102
+ {
103
+ for (int i = 1; i <= hash.EntrySize (bnr); i++)
104
+ if (hash.Get(bnr, i) == ind)
105
+ return i;
106
+ return 0;
107
+ }
108
+ };
109
+
110
+
111
+ ///
112
+ template <class T>
113
+ class INDEX_2_HASHTABLE : public BASE_INDEX_2_HASHTABLE
114
+ {
115
+ ///
116
+ TABLE<T> cont;
117
+
118
+ public:
119
+ ///
120
+ INDEX_2_HASHTABLE () { ; }
121
+
122
+ INDEX_2_HASHTABLE (int size)
123
+ : BASE_INDEX_2_HASHTABLE (size), cont(size)
124
+ { ; }
125
+
126
+ ///
127
+ void SetSize(int s)
128
+ {
129
+ cont.SetSize(s);
130
+ BaseSetSize(s);
131
+ }
132
+
133
+ ///
134
+ void Set (const INDEX_2 & ahash, const T & acont)
135
+ {
136
+ int bnr = HashValue (ahash);
137
+ int pos = Position (bnr, ahash);
138
+ if (pos)
139
+ cont.Set (bnr, pos, acont);
140
+ else
141
+ {
142
+ hash.Add1 (bnr, ahash);
143
+ cont.Add1 (bnr, acont);
144
+ }
145
+ }
146
+
147
+ ///
148
+ const T & Get (const INDEX_2 & ahash) const
149
+ {
150
+ int bnr = HashValue (ahash);
151
+ int pos = Position (bnr, ahash);
152
+ return cont.Get (bnr, pos);
153
+ }
154
+
155
+ T & Get (const INDEX_2 & ahash)
156
+ {
157
+ int bnr = HashValue (ahash);
158
+ int pos = Position (bnr, ahash);
159
+ return cont.Get (bnr, pos);
160
+ }
161
+
162
+ ///
163
+ bool Used (const INDEX_2 & ahash) const
164
+ {
165
+ return Position (HashValue (ahash), ahash) > 0;
166
+ }
167
+ ///
168
+ int GetNBags () const
169
+ {
170
+ return cont.Size();
171
+ }
172
+
173
+ ///
174
+ int GetBagSize (int bnr) const
175
+ {
176
+ return cont.EntrySize (bnr);
177
+ }
178
+
179
+ ///
180
+ void GetData (int bnr, int colnr,
181
+ INDEX_2 & ahash, T & acont) const
182
+ {
183
+ ahash = hash.Get(bnr, colnr);
184
+ acont = cont.Get(bnr, colnr);
185
+ }
186
+
187
+ ///
188
+ void SetData (int bnr, int colnr,
189
+ const INDEX_2 & ahash, const T & acont)
190
+ {
191
+ hash.Set(bnr, colnr, ahash);
192
+ cont.Set(bnr, colnr, acont);
193
+ }
194
+
195
+ ///
196
+ void PrintMemInfo (ostream & ost) const
197
+ {
198
+ ost << "Hash: " << endl;
199
+ hash.PrintMemInfo (ost);
200
+ ost << "Cont: " << endl;
201
+ cont.PrintMemInfo (ost);
202
+ }
203
+
204
+
205
+ void DeleteData ()
206
+ {
207
+ int n = hash.Size();
208
+ hash.SetSize (n);
209
+ cont.SetSize (n);
210
+ }
211
+
212
+
213
+ class Iterator
214
+ {
215
+ const INDEX_2_HASHTABLE & ht;
216
+ int bagnr, pos;
217
+ public:
218
+ Iterator (const INDEX_2_HASHTABLE & aht,
219
+ int abagnr, int apos)
220
+ : ht(aht), bagnr(abagnr), pos(apos)
221
+ { ; }
222
+
223
+ int BagNr() const { return bagnr; }
224
+ int Pos() const { return pos; }
225
+
226
+ Iterator operator++ (int)
227
+ {
228
+ Iterator it(ht, bagnr, pos);
229
+ ++(*this);
230
+ return it;
231
+ }
232
+ Iterator& operator++()
233
+ {
234
+ pos++;
235
+ while (bagnr < ht.GetNBags() &&
236
+ pos == ht.GetBagSize(bagnr+1))
237
+ {
238
+ pos = 0;
239
+ bagnr++;
240
+ }
241
+ return *this;
242
+ }
243
+
244
+ std::pair<INDEX_2, T> operator*()
245
+ {
246
+ return std::make_pair(ht.hash[bagnr][pos], ht.cont[bagnr][pos]);
247
+ }
248
+
249
+ bool operator != (int i) const
250
+ {
251
+ return bagnr != i;
252
+ }
253
+
254
+ };
255
+
256
+ Iterator Begin () const
257
+ {
258
+ Iterator it(*this, 0, -1);
259
+ it++;
260
+ return it;
261
+ }
262
+
263
+ int End() const
264
+ {
265
+ return GetNBags();
266
+ }
267
+
268
+ Iterator begin () const
269
+ {
270
+ Iterator it(*this, 0, -1);
271
+ it++;
272
+ return it;
273
+ }
274
+
275
+ int end() const
276
+ {
277
+ return GetNBags();
278
+ }
279
+
280
+ void GetData (const Iterator & it,
281
+ INDEX_2 & ahash, T & acont) const
282
+ {
283
+ ahash = hash[it.BagNr()][it.Pos()];
284
+ acont = cont[it.BagNr()][it.Pos()];
285
+ }
286
+
287
+ const INDEX_2 & GetHash (const Iterator & it) const
288
+ { return hash[it.BagNr()][it.Pos()]; }
289
+
290
+ const T & GetData (const Iterator & it) const
291
+ { return cont[it.BagNr()][it.Pos()]; }
292
+
293
+ void DoArchive (Archive & ar)
294
+ {
295
+ ar & hash & cont;
296
+ }
297
+
298
+ };
299
+
300
+ template <typename T>
301
+ inline ostream & operator<< (ostream & ost, const INDEX_2_HASHTABLE<T> & ht)
302
+ {
303
+ for (typename INDEX_2_HASHTABLE<T>::Iterator it = ht.Begin();
304
+ it != ht.End(); it++)
305
+ {
306
+ ost << ht.GetHash(it) << ": " << ht.GetData(it) << endl;
307
+ }
308
+
309
+ return ost;
310
+ }
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+ ///
319
+ class BASE_INDEX_3_HASHTABLE
320
+ {
321
+ protected:
322
+ ///
323
+ TABLE<INDEX_3> hash;
324
+
325
+ public:
326
+ ///
327
+ BASE_INDEX_3_HASHTABLE () { ; }
328
+ BASE_INDEX_3_HASHTABLE (int size)
329
+ : hash (size) { };
330
+
331
+ protected:
332
+ ///
333
+ int HashValue (const INDEX_3 & ind) const
334
+ {
335
+ return (ind.I1() + ind.I2() + ind.I3()) % hash.Size() + 1;
336
+ }
337
+
338
+ ///
339
+ int Position (int bnr, const INDEX_3 & ind) const
340
+ {
341
+ const INDEX_3 * pi = &hash.Get(bnr, 1);
342
+ int n = hash.EntrySize(bnr);
343
+ for (int i = 1; i <= n; ++i, ++pi)
344
+ {
345
+ if (*pi == ind)
346
+ return i;
347
+ }
348
+
349
+ return 0;
350
+ }
351
+
352
+
353
+ };
354
+
355
+
356
+ ///
357
+ template <class T>
358
+ class INDEX_3_HASHTABLE : private BASE_INDEX_3_HASHTABLE
359
+ {
360
+ ///
361
+ TABLE<T> cont;
362
+
363
+ public:
364
+ ///
365
+ inline INDEX_3_HASHTABLE () { ; }
366
+ inline INDEX_3_HASHTABLE (int size);
367
+ ///
368
+ inline void Set (const INDEX_3 & ahash, const T & acont);
369
+ ///
370
+ inline const T & Get (const INDEX_3 & ahash) const;
371
+ ///
372
+ inline bool Used (const INDEX_3 & ahash) const;
373
+ ///
374
+ inline int GetNBags () const;
375
+ ///
376
+ inline int GetBagSize (int bnr) const;
377
+ ///
378
+ inline void SetData (int bnr, int colnr, const INDEX_3 & ahash, const T & acont);
379
+ ///
380
+ inline void GetData (int bnr, int colnr, INDEX_3 & ahash, T & acont) const;
381
+ /// returns position, if not existing, will create (create == return 1)
382
+ inline int PositionCreate (const INDEX_3 & ahash, int & bnr, int & colnr);
383
+ ///
384
+ inline void SetSize (int size);
385
+
386
+ ///
387
+ inline void PrepareSet (const INDEX_3 & ahash);
388
+ ///
389
+ inline void AllocateElements ();
390
+
391
+ ///
392
+ inline void PrintMemInfo (ostream & ost) const;
393
+ ///
394
+ inline void DeleteData ();
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+ class Iterator
405
+ {
406
+ const INDEX_3_HASHTABLE & ht;
407
+ int bagnr, pos;
408
+ public:
409
+ Iterator (const INDEX_3_HASHTABLE & aht,
410
+ int abagnr, int apos)
411
+ : ht(aht), bagnr(abagnr), pos(apos)
412
+ { ; }
413
+
414
+ int BagNr() const { return bagnr; }
415
+ int Pos() const { return pos; }
416
+
417
+ Iterator operator++ (int)
418
+ {
419
+ Iterator it(ht, bagnr, pos);
420
+ ++(*this);
421
+ return it;
422
+ }
423
+ Iterator& operator++()
424
+ {
425
+ pos++;
426
+ while (bagnr < ht.GetNBags() &&
427
+ pos == ht.GetBagSize(bagnr+1))
428
+ {
429
+ pos = 0;
430
+ bagnr++;
431
+ }
432
+ return *this;
433
+ }
434
+
435
+ std::pair<INDEX_3, T> operator*()
436
+ {
437
+ return std::make_pair(ht.hash[bagnr][pos], ht.cont[bagnr][pos]);
438
+ }
439
+
440
+ bool operator != (int i) const
441
+ {
442
+ return bagnr != i;
443
+ }
444
+
445
+ };
446
+
447
+ Iterator Begin () const
448
+ {
449
+ Iterator it(*this, 0, -1);
450
+ it++;
451
+ return it;
452
+ }
453
+
454
+ int End() const
455
+ {
456
+ return GetNBags();
457
+ }
458
+
459
+ Iterator begin () const
460
+ {
461
+ Iterator it(*this, 0, -1);
462
+ it++;
463
+ return it;
464
+ }
465
+
466
+ int end() const
467
+ {
468
+ return GetNBags();
469
+ }
470
+
471
+ void GetData (const Iterator & it,
472
+ INDEX_3 & ahash, T & acont) const
473
+ {
474
+ ahash = hash[it.BagNr()][it.Pos()];
475
+ acont = cont[it.BagNr()][it.Pos()];
476
+ }
477
+
478
+ const INDEX_3 & GetHash (const Iterator & it) const
479
+ { return hash[it.BagNr()][it.Pos()]; }
480
+
481
+ const T & GetData (const Iterator & it) const
482
+ { return cont[it.BagNr()][it.Pos()]; }
483
+
484
+
485
+ void DoArchive (Archive & ar)
486
+ {
487
+ ar & hash & cont;
488
+ }
489
+
490
+
491
+ };
492
+
493
+
494
+ template <typename T>
495
+ inline ostream & operator<< (ostream & ost, const INDEX_3_HASHTABLE<T> & ht)
496
+ {
497
+ for (typename INDEX_3_HASHTABLE<T>::Iterator it = ht.Begin();
498
+ it != ht.End(); it++)
499
+ {
500
+ ost << ht.GetHash(it) << ": " << ht.GetData(it) << endl;
501
+ }
502
+
503
+ return ost;
504
+ }
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+ /// Closed Hashing HT
530
+
531
+ class BASE_INDEX_CLOSED_HASHTABLE
532
+ {
533
+ protected:
534
+ ///
535
+ // MoveableArray<INDEX> hash;
536
+ NgArray<INDEX> hash;
537
+ ///
538
+ int invalid;
539
+ public:
540
+ ///
541
+ BASE_INDEX_CLOSED_HASHTABLE (int size);
542
+
543
+ int Size() const { return hash.Size(); }
544
+ int UsedPos (int pos) const { return ! (hash.Get(pos) == invalid); }
545
+ int UsedElements () const;
546
+
547
+ ///
548
+ int HashValue (const INDEX & ind) const
549
+ {
550
+ return (3*ind) % hash.Size() + 1;
551
+ }
552
+
553
+
554
+ int Position (const INDEX & ind) const
555
+ {
556
+ int i = HashValue(ind);
557
+ while (1)
558
+ {
559
+ if (hash.Get(i) == ind) return i;
560
+ if (hash.Get(i) == invalid) return 0;
561
+ i++;
562
+ if (i > hash.Size()) i = 1;
563
+ }
564
+ }
565
+
566
+ int CalcPositionCosts (const INDEX & ind) const
567
+ {
568
+ int i = HashValue(ind);
569
+ int costs = 1;
570
+ while (1)
571
+ {
572
+ if (hash.Get(i) == ind) return costs;
573
+ if (hash.Get(i) == invalid) return costs;
574
+ i++;
575
+ if (i > hash.Size()) i = 1;
576
+ costs++;
577
+ }
578
+ }
579
+
580
+
581
+
582
+ // returns 1, if new position is created
583
+ int PositionCreate (const INDEX & ind, int & apos)
584
+ {
585
+ int i = HashValue (ind);
586
+ if (hash.Get(i) == ind)
587
+ {
588
+ apos = i;
589
+ return 0;
590
+ }
591
+ if (hash.Get(i) == invalid)
592
+ {
593
+ hash.Elem(i) = ind;
594
+ apos = i;
595
+ return 1;
596
+ }
597
+ return PositionCreate2 (ind, apos);
598
+ }
599
+
600
+ protected:
601
+ int Position2 (const INDEX & ind) const;
602
+ int PositionCreate2 (const INDEX & ind, int & apos);
603
+ void BaseSetSize (int asize);
604
+ };
605
+
606
+
607
+ template <class T>
608
+ class INDEX_CLOSED_HASHTABLE : public BASE_INDEX_CLOSED_HASHTABLE
609
+ {
610
+ ///
611
+ // MoveableArray<T> cont;
612
+ NgArray<T> cont;
613
+
614
+ public:
615
+ ///
616
+ INDEX_CLOSED_HASHTABLE (int size)
617
+ : BASE_INDEX_CLOSED_HASHTABLE(size), cont(size)
618
+ {
619
+ ; // cont.SetName ("ind-hashtable, contents");
620
+ }
621
+
622
+
623
+ void Set (const INDEX & ahash, const T & acont)
624
+ {
625
+ int pos;
626
+ PositionCreate (ahash, pos);
627
+ hash.Elem(pos) = ahash;
628
+ cont.Elem(pos) = acont;
629
+ }
630
+
631
+ const T & Get (const INDEX & ahash) const
632
+ {
633
+ int pos = Position (ahash);
634
+ return cont.Get(pos);
635
+ }
636
+
637
+ ///
638
+ bool Used (const INDEX & ahash) const
639
+ {
640
+ int pos = Position (ahash);
641
+ return (pos != 0);
642
+ }
643
+
644
+
645
+ ///
646
+ inline void SetData (int pos, const INDEX & ahash, const T & acont)
647
+ {
648
+ hash.Elem(pos) = ahash;
649
+ cont.Elem(pos) = acont;
650
+ }
651
+
652
+ ///
653
+ void GetData (int pos, INDEX & ahash, T & acont) const
654
+ {
655
+ ahash = hash.Get(pos);
656
+ acont = cont.Get(pos);
657
+ }
658
+
659
+ ///
660
+ inline void SetData (int pos, const T & acont)
661
+ {
662
+ cont.Elem(pos) = acont;
663
+ }
664
+
665
+ ///
666
+ void GetData (int pos, T & acont) const
667
+ {
668
+ acont = cont.Get(pos);
669
+ }
670
+
671
+ ///
672
+ const T & GetData (int pos) { return cont.Get(pos); }
673
+ ///
674
+ inline void SetSize (int size)
675
+ {
676
+ BaseSetSize(size);
677
+ cont.SetSize(size);
678
+ }
679
+
680
+ ///
681
+ inline void DeleteData ()
682
+ { SetSize (cont.Size()); }
683
+
684
+ void SetName (const char * aname)
685
+ {
686
+ // cont.SetName(aname);
687
+ // hash.SetName(aname);
688
+ }
689
+ };
690
+
691
+
692
+
693
+
694
+
695
+ inline size_t RoundUp2 (size_t i)
696
+ {
697
+ size_t res = 1;
698
+ while (res < i) res *= 2; // hope it will never be too large
699
+ return res;
700
+ }
701
+
702
+ /// Closed Hashing HT
703
+
704
+ class BASE_INDEX_2_CLOSED_HASHTABLE
705
+ {
706
+ protected:
707
+ ///
708
+ // MoveableArray<INDEX_2> hash;
709
+ NgArray<INDEX_2> hash;
710
+ ///
711
+ int invalid;
712
+ size_t mask;
713
+ public:
714
+ ///
715
+ DLL_HEADER BASE_INDEX_2_CLOSED_HASHTABLE (size_t size);
716
+
717
+ int Size() const { return hash.Size(); }
718
+ bool UsedPos0 (int pos) const { return ! (hash[pos].I1() == invalid); }
719
+ int UsedElements () const;
720
+
721
+ ///
722
+ int HashValue (const INDEX_2 & ind) const
723
+ {
724
+ // return (ind.I1() + 71 * ind.I2()) % hash.Size() + 1;
725
+ return (ind.I1() + 71 * ind.I2()) & mask;
726
+ }
727
+
728
+
729
+ int Position0 (const INDEX_2 & ind) const
730
+ {
731
+ int i = HashValue(ind);
732
+ while (1)
733
+ {
734
+ if (hash[i] == ind) return i;
735
+ if (hash[i].I1() == invalid) return -1;
736
+ i = (i+1) & mask;
737
+ /*
738
+ i++;
739
+ if (i > hash.Size()) i = 1;
740
+ */
741
+ }
742
+ }
743
+
744
+ // returns 1, if new position is created
745
+ bool PositionCreate0 (const INDEX_2 & ind, int & apos)
746
+ {
747
+ int i = HashValue (ind);
748
+ if (hash[i] == ind)
749
+ {
750
+ apos = i;
751
+ return false;
752
+ }
753
+ if (hash[i].I1() == invalid)
754
+ {
755
+ hash[i] = ind;
756
+ apos = i;
757
+ return true;
758
+ }
759
+ return PositionCreate2 (ind, apos);
760
+ }
761
+
762
+ protected:
763
+ ///
764
+
765
+ DLL_HEADER int Position2 (const INDEX_2 & ind) const;
766
+ DLL_HEADER bool PositionCreate2 (const INDEX_2 & ind, int & apos);
767
+ DLL_HEADER void BaseSetSize (int asize);
768
+ };
769
+
770
+
771
+ template <class T>
772
+ class INDEX_2_CLOSED_HASHTABLE : public BASE_INDEX_2_CLOSED_HASHTABLE
773
+ {
774
+ NgArray<T> cont;
775
+ public:
776
+ INDEX_2_CLOSED_HASHTABLE (size_t size)
777
+ : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size))
778
+ { ; }
779
+
780
+ void Set (const INDEX_2 & ahash, const T & acont)
781
+ {
782
+ int pos;
783
+ PositionCreate0 (ahash, pos);
784
+ hash[pos] = ahash;
785
+ cont[pos] = acont;
786
+ }
787
+
788
+ const T & Get (const INDEX_2 & ahash) const
789
+ {
790
+ int pos = Position0 (ahash);
791
+ return cont[pos];
792
+ }
793
+
794
+ inline bool Used (const INDEX_2 & ahash) const
795
+ {
796
+ int pos = Position0 (ahash);
797
+ return (pos != -1);
798
+ }
799
+
800
+ inline optional<T> GetIfUsed (const INDEX_2 & ahash) const
801
+ {
802
+ int pos = Position0 (ahash);
803
+ if (pos != -1)
804
+ return cont[pos];
805
+ else
806
+ return nullopt;
807
+ }
808
+
809
+ inline void SetData0 (int pos, const INDEX_2 & ahash, const T & acont)
810
+ {
811
+ hash[pos] = ahash;
812
+ cont[pos] = acont;
813
+ }
814
+
815
+ ///
816
+ inline void GetData0 (int pos, INDEX_2 & ahash, T & acont) const
817
+ {
818
+ ahash = hash[pos];
819
+ acont = cont[pos];
820
+ }
821
+
822
+ inline void SetData0 (int pos, const T & acont)
823
+ {
824
+ cont[pos] = acont;
825
+ }
826
+
827
+ inline void GetData0 (int pos, T & acont) const
828
+ {
829
+ acont = cont[pos];
830
+ }
831
+
832
+ ///
833
+ const T & GetData0 (int pos) { return cont[pos]; }
834
+ ///
835
+ inline void SetSize (size_t size)
836
+ {
837
+ BaseSetSize(size);
838
+ cont.SetSize(RoundUp2(size));
839
+ }
840
+
841
+
842
+ ///
843
+ inline void PrintMemInfo (ostream & ost) const;
844
+ ///
845
+ inline void DeleteData ()
846
+ { SetSize (cont.Size()); }
847
+
848
+ void SetName (const char * aname)
849
+ {
850
+ ;
851
+ // cont.SetName(aname);
852
+ // hash.SetName(aname);
853
+ }
854
+ };
855
+
856
+
857
+
858
+ template <typename T>
859
+ inline ostream & operator<< (ostream & ost, const INDEX_2_CLOSED_HASHTABLE<T> & ht)
860
+ {
861
+ for (int i = 0; i < ht.Size(); i++)
862
+ if (ht.UsedPos(i))
863
+ {
864
+ // INDEX_2 hash;
865
+ // T data;
866
+ // ht.GetData0 (i, hash, data);
867
+ auto [hash,data] = ht.GetBoth(i);
868
+ ost << "hash = " << hash << ", data = " << data << endl;
869
+ }
870
+ return ost;
871
+ }
872
+
873
+
874
+
875
+
876
+ class BASE_INDEX_3_CLOSED_HASHTABLE
877
+ {
878
+ protected:
879
+ NgArray<INDEX_3> hash;
880
+ int invalid;
881
+ size_t mask;
882
+
883
+ protected:
884
+ BASE_INDEX_3_CLOSED_HASHTABLE (size_t size);
885
+ /*
886
+ : hash(RoundUp2(size))
887
+ {
888
+ // cout << "orig size = " << size
889
+ // << ", roundup size = " << hash.Size();
890
+ size = hash.Size();
891
+ mask = size-1;
892
+ // cout << "mask = " << mask << endl;
893
+ invalid = -1;
894
+ for (size_t i = 0; i < size; i++)
895
+ hash[i].I1() = invalid;
896
+ }
897
+ */
898
+
899
+ public:
900
+ int Size() const
901
+ {
902
+ return hash.Size();
903
+ }
904
+
905
+ bool UsedPos (int pos) const
906
+ {
907
+ return ! (hash[pos].I1() == invalid);
908
+ }
909
+
910
+ int UsedElements () const
911
+ {
912
+ int n = hash.Size();
913
+ int cnt = 0;
914
+ for (int i = 0; i < n; i++)
915
+ if (hash[i].I1() != invalid)
916
+ cnt++;
917
+ return cnt;
918
+ }
919
+
920
+ int HashValue (const INDEX_3 & ind) const
921
+ {
922
+ // return (ind.I1() + 15 * ind.I2() + 41 * ind.I3()) % hash.Size();
923
+ return (ind.I1() + 15 * ind.I2() + 41 * ind.I3()) & mask;
924
+ }
925
+
926
+ int Position (const INDEX_3 & ind) const
927
+ {
928
+ int i = HashValue(ind);
929
+ while (1)
930
+ {
931
+ if (hash[i] == ind) return i;
932
+ if (hash[i].I1() == invalid) return -1;
933
+ // i = (i+1) % hash.Size();
934
+ i = (i+1) & mask;
935
+ }
936
+ }
937
+
938
+ int Costs (const INDEX_3 & ind) const
939
+ {
940
+ int i = HashValue(ind);
941
+ int c = 1;
942
+ while (1)
943
+ {
944
+ if (hash[i] == ind) return c;
945
+ if (hash[i].I1() == invalid) return c;
946
+ // i = (i+1) % hash.Size();
947
+ i = (i+1) & mask;
948
+ c++;
949
+ }
950
+ }
951
+
952
+
953
+
954
+ // returns true, if new position is created
955
+ bool PositionCreate (const INDEX_3 & ind, int & apos)
956
+ {
957
+ int i = HashValue (ind);
958
+ if (hash[i] == ind)
959
+ {
960
+ apos = i;
961
+ return false;
962
+ }
963
+ if (hash[i].I1() == invalid)
964
+ {
965
+ hash[i] = ind;
966
+ apos = i;
967
+ return true;
968
+ }
969
+ return PositionCreate2 (ind, apos);
970
+ }
971
+
972
+ void DeleteData()
973
+ {
974
+ size_t size = hash.Size();
975
+ for (size_t i = 0; i < size; i++)
976
+ hash[i].I1() = invalid;
977
+ }
978
+
979
+ protected:
980
+ bool PositionCreate2 (const INDEX_3 & ind, int & apos);
981
+ void BaseSetSize (int asize);
982
+ };
983
+
984
+
985
+
986
+ template <class T>
987
+ class INDEX_3_CLOSED_HASHTABLE : public BASE_INDEX_3_CLOSED_HASHTABLE
988
+ {
989
+ // MoveableArray<T,0> cont;
990
+ NgArray<T,0> cont;
991
+
992
+ public:
993
+ INDEX_3_CLOSED_HASHTABLE (int size)
994
+ : BASE_INDEX_3_CLOSED_HASHTABLE(size), cont(RoundUp2(size))
995
+ {
996
+ ; //cont.SetName ("i3-hashtable, contents");
997
+ }
998
+
999
+ void Set (const INDEX_3 & ahash, const T & acont)
1000
+ {
1001
+ int pos;
1002
+ PositionCreate (ahash, pos);
1003
+ hash[pos] = ahash;
1004
+ cont[pos] = acont;
1005
+ }
1006
+
1007
+ const T & Get (const INDEX_3 & ahash) const
1008
+ {
1009
+ return cont[Position (ahash)];
1010
+ }
1011
+
1012
+ bool Used (const INDEX_3 & ahash) const
1013
+ {
1014
+ return (Position (ahash) != -1);
1015
+ }
1016
+
1017
+ void SetData (int pos, const INDEX_3 & ahash, const T & acont)
1018
+ {
1019
+ hash[pos] = ahash;
1020
+ cont[pos] = acont;
1021
+ }
1022
+
1023
+ void GetData (int pos, INDEX_3 & ahash, T & acont) const
1024
+ {
1025
+ ahash = hash[pos];
1026
+ acont = cont[pos];
1027
+ }
1028
+
1029
+ void SetData (int pos, const T & acont)
1030
+ {
1031
+ cont[pos] = acont;
1032
+ }
1033
+
1034
+ void GetData (int pos, T & acont) const
1035
+ {
1036
+ acont = cont[pos];
1037
+ }
1038
+
1039
+ const T & GetData (int pos) const
1040
+ {
1041
+ return cont[pos];
1042
+ }
1043
+
1044
+ void SetSize (int size)
1045
+ {
1046
+ BaseSetSize(size);
1047
+ cont.SetSize(hash.Size());
1048
+ }
1049
+
1050
+ void PrintMemInfo (ostream & ost) const
1051
+ {
1052
+ cout << "Hashtable: " << Size()
1053
+ << " entries of size " << sizeof(INDEX_3) << " + " << sizeof(T)
1054
+ << " = " << Size() * (sizeof(INDEX_3) + sizeof(T)) << " bytes" << endl;
1055
+
1056
+ }
1057
+
1058
+ void DeleteData ()
1059
+ {
1060
+ SetSize (cont.Size());
1061
+ }
1062
+
1063
+ void SetName (const char * aname)
1064
+ {
1065
+ ;
1066
+ // cont.SetName(aname);
1067
+ // hash.SetName(aname);
1068
+ }
1069
+ };
1070
+
1071
+
1072
+
1073
+ template <typename T>
1074
+ inline ostream & operator<< (ostream & ost, const INDEX_3_CLOSED_HASHTABLE<T> & ht)
1075
+ {
1076
+ for (int i = 0; i < ht.Size(); i++)
1077
+ if (ht.UsedPos(i))
1078
+ {
1079
+ /*
1080
+ INDEX_3 hash;
1081
+ T data;
1082
+ ht.GetData (i, hash, data);
1083
+ */
1084
+ auto [hash, data] = ht.GetBoth();
1085
+ ost << "hash = " << hash << ", data = " << data << endl;
1086
+ }
1087
+ return ost;
1088
+ }
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+ template<class T>
1105
+ inline INDEX_3_HASHTABLE<T> :: INDEX_3_HASHTABLE (int size)
1106
+ : BASE_INDEX_3_HASHTABLE (size), cont(size)
1107
+ {
1108
+ ;
1109
+ }
1110
+
1111
+ template<class T>
1112
+ inline int INDEX_3_HASHTABLE<T> :: PositionCreate (const INDEX_3 & ahash, int & bnr, int & colnr)
1113
+ {
1114
+ bnr = HashValue (ahash);
1115
+ colnr = Position (bnr, ahash);
1116
+ if (!colnr)
1117
+ {
1118
+ hash.Add (bnr, ahash);
1119
+ cont.AddEmpty (bnr);
1120
+ colnr = cont.EntrySize (bnr);
1121
+ return 1;
1122
+ }
1123
+ return 0;
1124
+ }
1125
+
1126
+
1127
+ template<class T>
1128
+ inline void INDEX_3_HASHTABLE<T> :: Set (const INDEX_3 & ahash, const T & acont)
1129
+ {
1130
+ int bnr = HashValue (ahash);
1131
+ int pos = Position (bnr, ahash);
1132
+ if (pos)
1133
+ cont.Set (bnr, pos, acont);
1134
+ else
1135
+ {
1136
+ hash.Add1 (bnr, ahash);
1137
+ cont.Add1 (bnr, acont);
1138
+ }
1139
+ }
1140
+
1141
+ template<class T>
1142
+ inline const T & INDEX_3_HASHTABLE<T> :: Get (const INDEX_3 & ahash) const
1143
+ {
1144
+ int bnr = HashValue (ahash);
1145
+ int pos = Position (bnr, ahash);
1146
+ return cont.Get (bnr, pos);
1147
+ }
1148
+
1149
+ template<class T>
1150
+ inline bool INDEX_3_HASHTABLE<T> :: Used (const INDEX_3 & ahash) const
1151
+ {
1152
+ return (Position (HashValue (ahash), ahash)) ? 1 : 0;
1153
+ }
1154
+
1155
+ template<class T>
1156
+ inline int INDEX_3_HASHTABLE<T> :: GetNBags () const
1157
+ {
1158
+ return cont.Size();
1159
+ }
1160
+
1161
+ template<class T>
1162
+ inline int INDEX_3_HASHTABLE<T> :: GetBagSize (int bnr) const
1163
+ {
1164
+ return cont.EntrySize (bnr);
1165
+ }
1166
+
1167
+ template<class T>
1168
+ inline void INDEX_3_HASHTABLE<T> :: GetData (int bnr, int colnr, INDEX_3 & ahash, T & acont) const
1169
+ {
1170
+ ahash = hash.Get(bnr, colnr);
1171
+ acont = cont.Get(bnr, colnr);
1172
+ }
1173
+
1174
+ template<class T>
1175
+ inline void INDEX_3_HASHTABLE<T> :: SetData (int bnr, int colnr, const INDEX_3 & ahash, const T & acont)
1176
+ {
1177
+ hash.Set(bnr, colnr, ahash);
1178
+ cont.Set(bnr, colnr, acont);
1179
+ }
1180
+
1181
+ template<class T>
1182
+ inline void INDEX_3_HASHTABLE<T> :: SetSize (int size)
1183
+ {
1184
+ hash.SetSize (size);
1185
+ cont.SetSize (size);
1186
+ }
1187
+
1188
+ template<class T>
1189
+ inline void INDEX_3_HASHTABLE<T> :: DeleteData ()
1190
+ {
1191
+ int n = hash.Size();
1192
+ hash.SetSize (n);
1193
+ cont.SetSize (n);
1194
+ }
1195
+
1196
+ template<class T>
1197
+ inline void INDEX_3_HASHTABLE<T> :: PrepareSet (const INDEX_3 & ahash)
1198
+ {
1199
+ int bnr = HashValue (ahash);
1200
+ hash.IncSizePrepare (bnr-1);
1201
+ cont.IncSizePrepare (bnr-1);
1202
+ }
1203
+
1204
+
1205
+ template<class T>
1206
+ inline void INDEX_3_HASHTABLE<T> :: AllocateElements ()
1207
+ {
1208
+ hash.AllocateElementsOneBlock();
1209
+ cont.AllocateElementsOneBlock();
1210
+ }
1211
+
1212
+
1213
+
1214
+ template<class T>
1215
+ inline void INDEX_3_HASHTABLE<T> :: PrintMemInfo (ostream & ost) const
1216
+ {
1217
+ ost << "Hash: " << endl;
1218
+ hash.PrintMemInfo (ost);
1219
+ ost << "Cont: " << endl;
1220
+ cont.PrintMemInfo (ost);
1221
+ }
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+ template<class T>
1228
+ inline INDEX_HASHTABLE<T> :: INDEX_HASHTABLE (int size)
1229
+ : BASE_INDEX_HASHTABLE (size), cont(size)
1230
+ {
1231
+ ;
1232
+ }
1233
+
1234
+ template<class T>
1235
+ inline void INDEX_HASHTABLE<T> :: Set (const INDEX & ahash, const T & acont)
1236
+ {
1237
+ int bnr = HashValue (ahash);
1238
+ int pos = Position (bnr, ahash);
1239
+ if (pos)
1240
+ cont.Set (bnr, pos, acont);
1241
+ else
1242
+ {
1243
+ hash.Add (bnr, ahash);
1244
+ cont.Add (bnr, acont);
1245
+ }
1246
+ }
1247
+
1248
+ template<class T>
1249
+ inline const T & INDEX_HASHTABLE<T> :: Get (const INDEX & ahash) const
1250
+ {
1251
+ int bnr = HashValue (ahash);
1252
+ int pos = Position (bnr, ahash);
1253
+ return cont.Get (bnr, pos);
1254
+ }
1255
+
1256
+ template<class T>
1257
+ inline bool INDEX_HASHTABLE<T> :: Used (const INDEX & ahash) const
1258
+ {
1259
+ return (Position (HashValue (ahash), ahash)) ? 1 : 0;
1260
+ }
1261
+
1262
+ template<class T>
1263
+ inline int INDEX_HASHTABLE<T> :: GetNBags () const
1264
+ {
1265
+ return hash.Size();
1266
+ }
1267
+
1268
+ template<class T>
1269
+ inline int INDEX_HASHTABLE<T> :: GetBagSize (int bnr) const
1270
+ {
1271
+ return hash.EntrySize(bnr);
1272
+ }
1273
+
1274
+ template<class T>
1275
+ inline void INDEX_HASHTABLE<T> :: GetData (int bnr, int colnr, INDEX & ahash, T & acont) const
1276
+ {
1277
+ ahash = hash.Get(bnr, colnr);
1278
+ acont = cont.Get(bnr, colnr);
1279
+ }
1280
+
1281
+ template<class T>
1282
+ inline void INDEX_HASHTABLE<T> :: PrintMemInfo (ostream & ost) const
1283
+ {
1284
+ ost << "Hash: " << endl;
1285
+ hash.PrintMemInfo (ost);
1286
+ ost << "Cont: " << endl;
1287
+ cont.PrintMemInfo (ost);
1288
+ }
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+
1300
+
1301
+
1302
+
1303
+
1304
+ /* *********** Closed Hashing ************************* */
1305
+
1306
+ template<class T>
1307
+ inline void INDEX_2_CLOSED_HASHTABLE<T> ::
1308
+ PrintMemInfo (ostream & ost) const
1309
+ {
1310
+ cout << "Hashtable: " << Size()
1311
+ << " entries of size " << sizeof(INDEX_2) << " + " << sizeof(T)
1312
+ << " = " << Size() * (sizeof(INDEX_2) + sizeof(T)) << " bytes."
1313
+ << " Used els: " << UsedElements()
1314
+ << endl;
1315
+ }
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+
1327
+
1328
+
1329
+
1330
+
1331
+
1332
+ /*
1333
+ template<class T>
1334
+ inline INDEX_3_CLOSED_HASHTABLE<T> ::
1335
+ INDEX_3_CLOSED_HASHTABLE (int size)
1336
+ : BASE_INDEX_3_CLOSED_HASHTABLE(size), cont(size)
1337
+ {
1338
+ cont.SetName ("i3-hashtable, contents");
1339
+ }
1340
+
1341
+ template<class T>
1342
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1343
+ Set (const INDEX_3 & ahash, const T & acont)
1344
+ {
1345
+ int pos;
1346
+ PositionCreate (ahash, pos);
1347
+ hash.Elem(pos) = ahash;
1348
+ cont.Elem(pos) = acont;
1349
+ }
1350
+
1351
+ template<class T>
1352
+ inline const T & INDEX_3_CLOSED_HASHTABLE<T> ::
1353
+ Get (const INDEX_3 & ahash) const
1354
+ {
1355
+ int pos = Position (ahash);
1356
+ return cont[pos];
1357
+ }
1358
+
1359
+ template<class T>
1360
+ inline bool INDEX_3_CLOSED_HASHTABLE<T> ::
1361
+ Used (const INDEX_3 & ahash) const
1362
+ {
1363
+ int pos = Position (ahash);
1364
+ return (pos != 0);
1365
+ }
1366
+
1367
+ template<class T>
1368
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1369
+ SetData (int pos, const INDEX_3 & ahash, const T & acont)
1370
+ {
1371
+ hash.Elem(pos) = ahash;
1372
+ cont.Elem(pos) = acont;
1373
+ }
1374
+
1375
+ template<class T>
1376
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1377
+ GetData (int pos, INDEX_3 & ahash, T & acont) const
1378
+ {
1379
+ ahash = hash.Get(pos);
1380
+ acont = cont.Get(pos);
1381
+ }
1382
+
1383
+ template<class T>
1384
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1385
+ SetData (int pos, const T & acont)
1386
+ {
1387
+ cont.Elem(pos) = acont;
1388
+ }
1389
+
1390
+ template<class T>
1391
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1392
+ GetData (int pos, T & acont) const
1393
+ {
1394
+ acont = cont.Get(pos);
1395
+ }
1396
+
1397
+ template<class T>
1398
+ inline const T & INDEX_3_CLOSED_HASHTABLE<T> ::
1399
+ GetData (int pos) const
1400
+ {
1401
+ return cont.Get(pos);
1402
+ }
1403
+
1404
+
1405
+ template<class T>
1406
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1407
+ SetSize (int size)
1408
+ {
1409
+ BaseSetSize(size);
1410
+ cont.SetSize(size);
1411
+ }
1412
+
1413
+ template<class T>
1414
+ inline void INDEX_3_CLOSED_HASHTABLE<T> ::
1415
+ PrintMemInfo (ostream & ost) const
1416
+ {
1417
+ cout << "Hashtable: " << Size()
1418
+ << " entries of size " << sizeof(INDEX_3) << " + " << sizeof(T)
1419
+ << " = " << Size() * (sizeof(INDEX_3) + sizeof(T)) << " bytes" << endl;
1420
+ }
1421
+ */
1422
+
1423
+
1424
+ inline void SetInvalid (INDEX & i) { i = -1; }
1425
+ inline bool IsInvalid (INDEX i) { return i == -1; }
1426
+ inline size_t HashValue (INDEX i, size_t size) { return (113*size_t(i)) % size; }
1427
+
1428
+ inline void SetInvalid (INDEX_2 & i2) { i2[0] = -1; }
1429
+ inline bool IsInvalid (INDEX_2 i2) { return i2[0] == -1; }
1430
+ inline size_t HashValue (INDEX_2 i2, size_t size) { return (113*size_t(i2[0])+size_t(i2[1])) % size; }
1431
+
1432
+ inline void SetInvalid (INDEX_3 & i3) { i3[0] = -1; }
1433
+ inline bool IsInvalid (INDEX_3 i3) { return i3[0] == -1; }
1434
+ inline size_t HashValue (INDEX_3 i3, size_t size) { return (i3[0]+15*size_t(i3[1])+41*size_t(i3[2])) % size; }
1435
+
1436
+
1437
+ /**
1438
+ A closed hash-table.
1439
+ All information is stored in one fixed array.
1440
+ The array should be allocated with the double size of the expected number of entries.
1441
+ */
1442
+ template <class T_HASH, class T>
1443
+ class NgClosedHashTable
1444
+ {
1445
+ protected:
1446
+ ///
1447
+ size_t size;
1448
+ ///
1449
+ size_t used;
1450
+ ///
1451
+ NgArray<T_HASH> hash;
1452
+ ///
1453
+ NgArray<T> cont;
1454
+ public:
1455
+ ///
1456
+ NgClosedHashTable (size_t asize = 128)
1457
+ : size(asize), used(0), hash(asize), cont(asize)
1458
+ {
1459
+ for (auto & v : hash)
1460
+ SetInvalid(v);
1461
+ }
1462
+
1463
+ NgClosedHashTable (NgClosedHashTable && ht2) = default;
1464
+
1465
+ NgClosedHashTable (NgFlatArray<T_HASH> _hash, NgFlatArray<T> _cont)
1466
+ : size(_hash.Size()), used(0), hash(_hash.Size(), _hash.Addr(0)), cont(_cont.Size(), _cont.Addr(0))
1467
+ {
1468
+ for (auto & v : hash)
1469
+ SetInvalid(v);
1470
+ }
1471
+
1472
+
1473
+ NgClosedHashTable & operator= (NgClosedHashTable && ht2) = default;
1474
+
1475
+ ///
1476
+ size_t Size() const
1477
+ {
1478
+ return size;
1479
+ }
1480
+
1481
+ /// is position used
1482
+ bool UsedPos (size_t pos) const
1483
+ {
1484
+ return ! (IsInvalid(hash[pos]));
1485
+ }
1486
+
1487
+ /// number of used elements
1488
+ size_t UsedElements () const
1489
+ {
1490
+ return used;
1491
+ }
1492
+
1493
+ size_t Position (const T_HASH ind) const
1494
+ {
1495
+ size_t i = HashValue(ind, size);
1496
+ while (1)
1497
+ {
1498
+ if (hash[i] == ind) return i;
1499
+ if (IsInvalid(hash[i])) return size_t(-1);
1500
+ i++;
1501
+ if (i >= size) i = 0;
1502
+ }
1503
+ }
1504
+
1505
+ void DoubleSize()
1506
+ {
1507
+ NgClosedHashTable tmp(2*Size());
1508
+ for (auto both : *this)
1509
+ tmp[both.first] = both.second;
1510
+ *this = std::move(tmp);
1511
+ }
1512
+
1513
+ // returns true if new position is created
1514
+ bool PositionCreate (const T_HASH ind, size_t & apos)
1515
+ {
1516
+ if (UsedElements()*2 > Size()) DoubleSize();
1517
+
1518
+ size_t i = HashValue (ind, size);
1519
+
1520
+ while (1)
1521
+ {
1522
+ if (IsInvalid(hash[i]))
1523
+ {
1524
+ hash[i] = ind;
1525
+ apos = i;
1526
+ used++;
1527
+ return true;
1528
+ }
1529
+ if (hash[i] == ind)
1530
+ {
1531
+ apos = i;
1532
+ return false;
1533
+ }
1534
+ i++;
1535
+ if (i >= size) i = 0;
1536
+ }
1537
+ }
1538
+
1539
+
1540
+ ///
1541
+ void Set (const T_HASH & ahash, const T & acont)
1542
+ {
1543
+ size_t pos;
1544
+ PositionCreate (ahash, pos);
1545
+ hash[pos] = ahash;
1546
+ cont[pos] = acont;
1547
+ }
1548
+
1549
+ ///
1550
+ const T & Get (const T_HASH & ahash) const
1551
+ {
1552
+ size_t pos = Position (ahash);
1553
+ if (pos == size_t(-1))
1554
+ throw Exception (string("illegal key: ") + ToString(ahash) );
1555
+ return cont[pos];
1556
+ }
1557
+
1558
+ ///
1559
+ bool Used (const T_HASH & ahash) const
1560
+ {
1561
+ return (Position (ahash) != size_t(-1));
1562
+ }
1563
+
1564
+ void SetData (size_t pos, const T_HASH & ahash, const T & acont)
1565
+ {
1566
+ hash[pos] = ahash;
1567
+ cont[pos] = acont;
1568
+ }
1569
+
1570
+ void GetData (size_t pos, T_HASH & ahash, T & acont) const
1571
+ {
1572
+ ahash = hash[pos];
1573
+ acont = cont[pos];
1574
+ }
1575
+
1576
+ void SetData (size_t pos, const T & acont)
1577
+ {
1578
+ cont[pos] = acont;
1579
+ }
1580
+
1581
+ void GetData (size_t pos, T & acont) const
1582
+ {
1583
+ acont = cont[pos];
1584
+ }
1585
+
1586
+ pair<T_HASH,T> GetBoth (size_t pos) const
1587
+ {
1588
+ return pair<T_HASH,T> (hash[pos], cont[pos]);
1589
+ }
1590
+
1591
+ const T & operator[] (T_HASH key) const { return Get(key); }
1592
+ T & operator[] (T_HASH key)
1593
+ {
1594
+ size_t pos;
1595
+ PositionCreate(key, pos);
1596
+ return cont[pos];
1597
+ }
1598
+
1599
+ void SetSize (size_t asize)
1600
+ {
1601
+ size = asize;
1602
+ hash.Alloc(size);
1603
+ cont.Alloc(size);
1604
+
1605
+ // for (size_t i = 0; i < size; i++)
1606
+ // hash[i] = invalid;
1607
+ // hash = T_HASH(invalid);
1608
+ for (auto & v : hash)
1609
+ SetInvalid(v);
1610
+ }
1611
+
1612
+ void Delete (T_HASH key)
1613
+ {
1614
+ size_t pos = Position(key);
1615
+ if (pos == size_t(-1)) return;
1616
+ SetInvalid (hash[pos]); used--;
1617
+
1618
+ while (1)
1619
+ {
1620
+ size_t nextpos = pos+1;
1621
+ if (nextpos == size) nextpos = 0;
1622
+ if (IsInvalid(hash[nextpos])) break;
1623
+
1624
+ auto key = hash[nextpos];
1625
+ auto val = cont[nextpos];
1626
+ SetInvalid (hash[nextpos]); used--;
1627
+
1628
+ Set (key, val);
1629
+ pos = nextpos;
1630
+ }
1631
+ }
1632
+
1633
+ void DeleteData()
1634
+ {
1635
+ for (auto & v : hash)
1636
+ SetInvalid(v);
1637
+ used = 0;
1638
+ }
1639
+
1640
+ class Iterator
1641
+ {
1642
+ const NgClosedHashTable & tab;
1643
+ size_t nr;
1644
+ public:
1645
+ Iterator (const NgClosedHashTable & _tab, size_t _nr)
1646
+ : tab(_tab), nr(_nr)
1647
+ {
1648
+ while (nr < tab.Size() && !tab.UsedPos(nr)) nr++;
1649
+ }
1650
+ Iterator & operator++()
1651
+ {
1652
+ nr++;
1653
+ while (nr < tab.Size() && !tab.UsedPos(nr)) nr++;
1654
+ return *this;
1655
+ }
1656
+ bool operator!= (const Iterator & it2) { return nr != it2.nr; }
1657
+ auto operator* () const
1658
+ {
1659
+ T_HASH hash;
1660
+ T val;
1661
+ tab.GetData(nr, hash,val);
1662
+ return std::make_pair(hash,val);
1663
+ }
1664
+ };
1665
+
1666
+ Iterator begin() const { return Iterator(*this, 0); }
1667
+ Iterator end() const { return Iterator(*this, Size()); }
1668
+ };
1669
+
1670
+ template <class T_HASH, class T>
1671
+ ostream & operator<< (ostream & ost,
1672
+ const NgClosedHashTable<T_HASH,T> & tab)
1673
+ {
1674
+ for (size_t i = 0; i < tab.Size(); i++)
1675
+ if (tab.UsedPos(i))
1676
+ {
1677
+ T_HASH key;
1678
+ T val;
1679
+ tab.GetData (i, key, val);
1680
+ ost << key << ": " << val << ", ";
1681
+ }
1682
+ return ost;
1683
+ }
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+ }
1690
+
1691
+
1692
+ #endif