@ladybugmem/icebug 0.1.0

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 (624) hide show
  1. package/README.md +14 -0
  2. package/binding.gyp +54 -0
  3. package/build/Release/.deps/Release/icebug.node.d +1 -0
  4. package/build/Release/.deps/Release/obj.target/icebug/src/addon.o.d +291 -0
  5. package/build/Release/icebug.node +0 -0
  6. package/build/Release/obj.target/icebug/src/addon.o +0 -0
  7. package/lib/index.d.ts +361 -0
  8. package/lib/index.js +102 -0
  9. package/package.json +42 -0
  10. package/src/addon.cpp +1253 -0
  11. package/vendor/include/networkit/GlobalState.hpp +86 -0
  12. package/vendor/include/networkit/Globals.hpp +41 -0
  13. package/vendor/include/networkit/algebraic/AlgebraicGlobals.hpp +27 -0
  14. package/vendor/include/networkit/algebraic/CSRGeneralMatrix.hpp +1292 -0
  15. package/vendor/include/networkit/algebraic/CSRMatrix.hpp +11 -0
  16. package/vendor/include/networkit/algebraic/DenseMatrix.hpp +537 -0
  17. package/vendor/include/networkit/algebraic/DynamicMatrix.hpp +514 -0
  18. package/vendor/include/networkit/algebraic/GraphBLAS.hpp +323 -0
  19. package/vendor/include/networkit/algebraic/MatrixTools.hpp +156 -0
  20. package/vendor/include/networkit/algebraic/Semirings.hpp +171 -0
  21. package/vendor/include/networkit/algebraic/SparseAccumulator.hpp +111 -0
  22. package/vendor/include/networkit/algebraic/Vector.hpp +371 -0
  23. package/vendor/include/networkit/algebraic/algorithms/AlgebraicBFS.hpp +72 -0
  24. package/vendor/include/networkit/algebraic/algorithms/AlgebraicBellmanFord.hpp +88 -0
  25. package/vendor/include/networkit/algebraic/algorithms/AlgebraicMatchingCoarsening.hpp +96 -0
  26. package/vendor/include/networkit/algebraic/algorithms/AlgebraicPageRank.hpp +145 -0
  27. package/vendor/include/networkit/algebraic/algorithms/AlgebraicSpanningEdgeCentrality.hpp +122 -0
  28. package/vendor/include/networkit/algebraic/algorithms/AlgebraicTriangleCounting.hpp +76 -0
  29. package/vendor/include/networkit/auxiliary/AlignedAllocator.hpp +113 -0
  30. package/vendor/include/networkit/auxiliary/ArrayTools.hpp +85 -0
  31. package/vendor/include/networkit/auxiliary/BloomFilter.hpp +70 -0
  32. package/vendor/include/networkit/auxiliary/BucketPQ.hpp +142 -0
  33. package/vendor/include/networkit/auxiliary/Enforce.hpp +117 -0
  34. package/vendor/include/networkit/auxiliary/FunctionTraits.hpp +74 -0
  35. package/vendor/include/networkit/auxiliary/HashUtils.hpp +28 -0
  36. package/vendor/include/networkit/auxiliary/IncrementalUniformRandomSelector.hpp +52 -0
  37. package/vendor/include/networkit/auxiliary/Log.hpp +119 -0
  38. package/vendor/include/networkit/auxiliary/MissingMath.hpp +48 -0
  39. package/vendor/include/networkit/auxiliary/Multiprecision.hpp +17 -0
  40. package/vendor/include/networkit/auxiliary/NumberParsing.hpp +307 -0
  41. package/vendor/include/networkit/auxiliary/NumericTools.hpp +57 -0
  42. package/vendor/include/networkit/auxiliary/Parallel.hpp +56 -0
  43. package/vendor/include/networkit/auxiliary/Parallelism.hpp +33 -0
  44. package/vendor/include/networkit/auxiliary/PrioQueue.hpp +252 -0
  45. package/vendor/include/networkit/auxiliary/Random.hpp +122 -0
  46. package/vendor/include/networkit/auxiliary/SetIntersector.hpp +72 -0
  47. package/vendor/include/networkit/auxiliary/SignalHandling.hpp +39 -0
  48. package/vendor/include/networkit/auxiliary/SortedList.hpp +128 -0
  49. package/vendor/include/networkit/auxiliary/SparseVector.hpp +215 -0
  50. package/vendor/include/networkit/auxiliary/SpinLock.hpp +23 -0
  51. package/vendor/include/networkit/auxiliary/StringBuilder.hpp +322 -0
  52. package/vendor/include/networkit/auxiliary/StringTools.hpp +76 -0
  53. package/vendor/include/networkit/auxiliary/TemplateUtils.hpp +76 -0
  54. package/vendor/include/networkit/auxiliary/Timer.hpp +145 -0
  55. package/vendor/include/networkit/auxiliary/VectorComparator.hpp +32 -0
  56. package/vendor/include/networkit/base/Algorithm.hpp +41 -0
  57. package/vendor/include/networkit/base/DynAlgorithm.hpp +31 -0
  58. package/vendor/include/networkit/centrality/ApproxBetweenness.hpp +62 -0
  59. package/vendor/include/networkit/centrality/ApproxCloseness.hpp +136 -0
  60. package/vendor/include/networkit/centrality/ApproxElectricalCloseness.hpp +156 -0
  61. package/vendor/include/networkit/centrality/ApproxGroupBetweenness.hpp +124 -0
  62. package/vendor/include/networkit/centrality/ApproxSpanningEdge.hpp +84 -0
  63. package/vendor/include/networkit/centrality/Betweenness.hpp +47 -0
  64. package/vendor/include/networkit/centrality/Centrality.hpp +98 -0
  65. package/vendor/include/networkit/centrality/Closeness.hpp +107 -0
  66. package/vendor/include/networkit/centrality/ComplexPaths.hpp +113 -0
  67. package/vendor/include/networkit/centrality/CoreDecomposition.hpp +161 -0
  68. package/vendor/include/networkit/centrality/DegreeCentrality.hpp +55 -0
  69. package/vendor/include/networkit/centrality/DynApproxBetweenness.hpp +95 -0
  70. package/vendor/include/networkit/centrality/DynBetweenness.hpp +99 -0
  71. package/vendor/include/networkit/centrality/DynBetweennessOneNode.hpp +98 -0
  72. package/vendor/include/networkit/centrality/DynKatzCentrality.hpp +115 -0
  73. package/vendor/include/networkit/centrality/DynTopHarmonicCloseness.hpp +223 -0
  74. package/vendor/include/networkit/centrality/EigenvectorCentrality.hpp +41 -0
  75. package/vendor/include/networkit/centrality/EstimateBetweenness.hpp +51 -0
  76. package/vendor/include/networkit/centrality/ForestCentrality.hpp +112 -0
  77. package/vendor/include/networkit/centrality/GedWalk.hpp +225 -0
  78. package/vendor/include/networkit/centrality/GroupCloseness.hpp +115 -0
  79. package/vendor/include/networkit/centrality/GroupClosenessGrowShrink.hpp +78 -0
  80. package/vendor/include/networkit/centrality/GroupClosenessLocalSearch.hpp +77 -0
  81. package/vendor/include/networkit/centrality/GroupClosenessLocalSwaps.hpp +106 -0
  82. package/vendor/include/networkit/centrality/GroupDegree.hpp +155 -0
  83. package/vendor/include/networkit/centrality/GroupHarmonicCloseness.hpp +83 -0
  84. package/vendor/include/networkit/centrality/HarmonicCloseness.hpp +48 -0
  85. package/vendor/include/networkit/centrality/KPathCentrality.hpp +52 -0
  86. package/vendor/include/networkit/centrality/KadabraBetweenness.hpp +242 -0
  87. package/vendor/include/networkit/centrality/KatzCentrality.hpp +62 -0
  88. package/vendor/include/networkit/centrality/LaplacianCentrality.hpp +44 -0
  89. package/vendor/include/networkit/centrality/LocalClusteringCoefficient.hpp +60 -0
  90. package/vendor/include/networkit/centrality/LocalPartitionCoverage.hpp +43 -0
  91. package/vendor/include/networkit/centrality/LocalSquareClusteringCoefficient.hpp +42 -0
  92. package/vendor/include/networkit/centrality/PageRank.hpp +101 -0
  93. package/vendor/include/networkit/centrality/PermanenceCentrality.hpp +48 -0
  94. package/vendor/include/networkit/centrality/Sfigality.hpp +45 -0
  95. package/vendor/include/networkit/centrality/SpanningEdgeCentrality.hpp +86 -0
  96. package/vendor/include/networkit/centrality/TopCloseness.hpp +136 -0
  97. package/vendor/include/networkit/centrality/TopHarmonicCloseness.hpp +151 -0
  98. package/vendor/include/networkit/clique/MaximalCliques.hpp +83 -0
  99. package/vendor/include/networkit/coarsening/ClusteringProjector.hpp +59 -0
  100. package/vendor/include/networkit/coarsening/CoarsenedGraphView.hpp +156 -0
  101. package/vendor/include/networkit/coarsening/GraphCoarsening.hpp +57 -0
  102. package/vendor/include/networkit/coarsening/MatchingCoarsening.hpp +43 -0
  103. package/vendor/include/networkit/coarsening/ParallelPartitionCoarsening.hpp +33 -0
  104. package/vendor/include/networkit/coarsening/ParallelPartitionCoarseningView.hpp +62 -0
  105. package/vendor/include/networkit/community/AdjustedRandMeasure.hpp +31 -0
  106. package/vendor/include/networkit/community/ClusteringGenerator.hpp +75 -0
  107. package/vendor/include/networkit/community/CommunityDetectionAlgorithm.hpp +58 -0
  108. package/vendor/include/networkit/community/Conductance.hpp +32 -0
  109. package/vendor/include/networkit/community/CoverF1Similarity.hpp +53 -0
  110. package/vendor/include/networkit/community/CoverHubDominance.hpp +38 -0
  111. package/vendor/include/networkit/community/Coverage.hpp +25 -0
  112. package/vendor/include/networkit/community/CutClustering.hpp +62 -0
  113. package/vendor/include/networkit/community/DissimilarityMeasure.hpp +31 -0
  114. package/vendor/include/networkit/community/DynamicNMIDistance.hpp +44 -0
  115. package/vendor/include/networkit/community/EdgeCut.hpp +24 -0
  116. package/vendor/include/networkit/community/GraphClusteringTools.hpp +103 -0
  117. package/vendor/include/networkit/community/GraphStructuralRandMeasure.hpp +28 -0
  118. package/vendor/include/networkit/community/HubDominance.hpp +46 -0
  119. package/vendor/include/networkit/community/IntrapartitionDensity.hpp +44 -0
  120. package/vendor/include/networkit/community/IsolatedInterpartitionConductance.hpp +40 -0
  121. package/vendor/include/networkit/community/IsolatedInterpartitionExpansion.hpp +40 -0
  122. package/vendor/include/networkit/community/JaccardMeasure.hpp +25 -0
  123. package/vendor/include/networkit/community/LFM.hpp +49 -0
  124. package/vendor/include/networkit/community/LPDegreeOrdered.hpp +48 -0
  125. package/vendor/include/networkit/community/LocalCommunityEvaluation.hpp +100 -0
  126. package/vendor/include/networkit/community/LocalCoverEvaluation.hpp +31 -0
  127. package/vendor/include/networkit/community/LocalPartitionEvaluation.hpp +31 -0
  128. package/vendor/include/networkit/community/LouvainMapEquation.hpp +135 -0
  129. package/vendor/include/networkit/community/Modularity.hpp +54 -0
  130. package/vendor/include/networkit/community/NMIDistance.hpp +28 -0
  131. package/vendor/include/networkit/community/NodeStructuralRandMeasure.hpp +27 -0
  132. package/vendor/include/networkit/community/OverlappingCommunityDetectionAlgorithm.hpp +51 -0
  133. package/vendor/include/networkit/community/OverlappingNMIDistance.hpp +175 -0
  134. package/vendor/include/networkit/community/PLM.hpp +89 -0
  135. package/vendor/include/networkit/community/PLP.hpp +83 -0
  136. package/vendor/include/networkit/community/ParallelAgglomerativeClusterer.hpp +37 -0
  137. package/vendor/include/networkit/community/ParallelLeiden.hpp +96 -0
  138. package/vendor/include/networkit/community/ParallelLeidenView.hpp +138 -0
  139. package/vendor/include/networkit/community/PartitionFragmentation.hpp +30 -0
  140. package/vendor/include/networkit/community/PartitionHubDominance.hpp +37 -0
  141. package/vendor/include/networkit/community/PartitionIntersection.hpp +25 -0
  142. package/vendor/include/networkit/community/QualityMeasure.hpp +27 -0
  143. package/vendor/include/networkit/community/SampledGraphStructuralRandMeasure.hpp +40 -0
  144. package/vendor/include/networkit/community/SampledNodeStructuralRandMeasure.hpp +40 -0
  145. package/vendor/include/networkit/community/StablePartitionNodes.hpp +48 -0
  146. package/vendor/include/networkit/components/BiconnectedComponents.hpp +116 -0
  147. package/vendor/include/networkit/components/ComponentDecomposition.hpp +72 -0
  148. package/vendor/include/networkit/components/ConnectedComponents.hpp +55 -0
  149. package/vendor/include/networkit/components/DynConnectedComponents.hpp +71 -0
  150. package/vendor/include/networkit/components/DynWeaklyConnectedComponents.hpp +73 -0
  151. package/vendor/include/networkit/components/ParallelConnectedComponents.hpp +44 -0
  152. package/vendor/include/networkit/components/RandomSpanningForest.hpp +36 -0
  153. package/vendor/include/networkit/components/StronglyConnectedComponents.hpp +50 -0
  154. package/vendor/include/networkit/components/WeaklyConnectedComponents.hpp +59 -0
  155. package/vendor/include/networkit/correlation/Assortativity.hpp +64 -0
  156. package/vendor/include/networkit/distance/APSP.hpp +70 -0
  157. package/vendor/include/networkit/distance/AStar.hpp +68 -0
  158. package/vendor/include/networkit/distance/AStarGeneral.hpp +110 -0
  159. package/vendor/include/networkit/distance/AdamicAdarDistance.hpp +52 -0
  160. package/vendor/include/networkit/distance/AffectedNodes.hpp +130 -0
  161. package/vendor/include/networkit/distance/AlgebraicDistance.hpp +63 -0
  162. package/vendor/include/networkit/distance/BFS.hpp +43 -0
  163. package/vendor/include/networkit/distance/BidirectionalBFS.hpp +51 -0
  164. package/vendor/include/networkit/distance/BidirectionalDijkstra.hpp +69 -0
  165. package/vendor/include/networkit/distance/CommuteTimeDistance.hpp +89 -0
  166. package/vendor/include/networkit/distance/Diameter.hpp +97 -0
  167. package/vendor/include/networkit/distance/Dijkstra.hpp +50 -0
  168. package/vendor/include/networkit/distance/DynAPSP.hpp +67 -0
  169. package/vendor/include/networkit/distance/DynBFS.hpp +56 -0
  170. package/vendor/include/networkit/distance/DynDijkstra.hpp +57 -0
  171. package/vendor/include/networkit/distance/DynPrunedLandmarkLabeling.hpp +67 -0
  172. package/vendor/include/networkit/distance/DynSSSP.hpp +87 -0
  173. package/vendor/include/networkit/distance/Eccentricity.hpp +32 -0
  174. package/vendor/include/networkit/distance/EffectiveDiameter.hpp +47 -0
  175. package/vendor/include/networkit/distance/EffectiveDiameterApproximation.hpp +57 -0
  176. package/vendor/include/networkit/distance/FloydWarshall.hpp +93 -0
  177. package/vendor/include/networkit/distance/GraphDistance.hpp +49 -0
  178. package/vendor/include/networkit/distance/HopPlotApproximation.hpp +62 -0
  179. package/vendor/include/networkit/distance/IncompleteDijkstra.hpp +66 -0
  180. package/vendor/include/networkit/distance/IncompleteSSSP.hpp +41 -0
  181. package/vendor/include/networkit/distance/JaccardDistance.hpp +57 -0
  182. package/vendor/include/networkit/distance/MultiTargetBFS.hpp +32 -0
  183. package/vendor/include/networkit/distance/MultiTargetDijkstra.hpp +40 -0
  184. package/vendor/include/networkit/distance/NeighborhoodFunction.hpp +47 -0
  185. package/vendor/include/networkit/distance/NeighborhoodFunctionApproximation.hpp +56 -0
  186. package/vendor/include/networkit/distance/NeighborhoodFunctionHeuristic.hpp +56 -0
  187. package/vendor/include/networkit/distance/NodeDistance.hpp +54 -0
  188. package/vendor/include/networkit/distance/PrunedLandmarkLabeling.hpp +76 -0
  189. package/vendor/include/networkit/distance/ReverseBFS.hpp +46 -0
  190. package/vendor/include/networkit/distance/SPSP.hpp +143 -0
  191. package/vendor/include/networkit/distance/SSSP.hpp +216 -0
  192. package/vendor/include/networkit/distance/STSP.hpp +193 -0
  193. package/vendor/include/networkit/distance/Volume.hpp +66 -0
  194. package/vendor/include/networkit/dynamics/DGSStreamParser.hpp +40 -0
  195. package/vendor/include/networkit/dynamics/DGSWriter.hpp +30 -0
  196. package/vendor/include/networkit/dynamics/GraphDifference.hpp +110 -0
  197. package/vendor/include/networkit/dynamics/GraphEvent.hpp +55 -0
  198. package/vendor/include/networkit/dynamics/GraphEventHandler.hpp +39 -0
  199. package/vendor/include/networkit/dynamics/GraphEventProxy.hpp +55 -0
  200. package/vendor/include/networkit/dynamics/GraphUpdater.hpp +38 -0
  201. package/vendor/include/networkit/edgescores/ChibaNishizekiQuadrangleEdgeScore.hpp +26 -0
  202. package/vendor/include/networkit/edgescores/ChibaNishizekiTriangleEdgeScore.hpp +33 -0
  203. package/vendor/include/networkit/edgescores/EdgeScore.hpp +50 -0
  204. package/vendor/include/networkit/edgescores/EdgeScoreAsWeight.hpp +33 -0
  205. package/vendor/include/networkit/edgescores/EdgeScoreBlender.hpp +33 -0
  206. package/vendor/include/networkit/edgescores/EdgeScoreLinearizer.hpp +32 -0
  207. package/vendor/include/networkit/edgescores/EdgeScoreNormalizer.hpp +35 -0
  208. package/vendor/include/networkit/edgescores/GeometricMeanScore.hpp +29 -0
  209. package/vendor/include/networkit/edgescores/PrefixJaccardScore.hpp +23 -0
  210. package/vendor/include/networkit/edgescores/TriangleEdgeScore.hpp +39 -0
  211. package/vendor/include/networkit/embedding/Node2Vec.hpp +83 -0
  212. package/vendor/include/networkit/flow/EdmondsKarp.hpp +112 -0
  213. package/vendor/include/networkit/generators/BarabasiAlbertGenerator.hpp +87 -0
  214. package/vendor/include/networkit/generators/ChungLuGenerator.hpp +46 -0
  215. package/vendor/include/networkit/generators/ChungLuGeneratorAlamEtAl.hpp +63 -0
  216. package/vendor/include/networkit/generators/ClusteredRandomGraphGenerator.hpp +56 -0
  217. package/vendor/include/networkit/generators/ConfigurationModel.hpp +36 -0
  218. package/vendor/include/networkit/generators/DorogovtsevMendesGenerator.hpp +33 -0
  219. package/vendor/include/networkit/generators/DynamicBarabasiAlbertGenerator.hpp +33 -0
  220. package/vendor/include/networkit/generators/DynamicDGSParser.hpp +51 -0
  221. package/vendor/include/networkit/generators/DynamicDorogovtsevMendesGenerator.hpp +34 -0
  222. package/vendor/include/networkit/generators/DynamicForestFireGenerator.hpp +55 -0
  223. package/vendor/include/networkit/generators/DynamicGraphGenerator.hpp +40 -0
  224. package/vendor/include/networkit/generators/DynamicGraphSource.hpp +79 -0
  225. package/vendor/include/networkit/generators/DynamicHyperbolicGenerator.hpp +143 -0
  226. package/vendor/include/networkit/generators/DynamicPathGenerator.hpp +26 -0
  227. package/vendor/include/networkit/generators/DynamicPubWebGenerator.hpp +54 -0
  228. package/vendor/include/networkit/generators/EdgeSwitchingMarkovChainGenerator.hpp +65 -0
  229. package/vendor/include/networkit/generators/ErdosRenyiEnumerator.hpp +318 -0
  230. package/vendor/include/networkit/generators/ErdosRenyiGenerator.hpp +56 -0
  231. package/vendor/include/networkit/generators/HavelHakimiGenerator.hpp +48 -0
  232. package/vendor/include/networkit/generators/HyperbolicGenerator.hpp +236 -0
  233. package/vendor/include/networkit/generators/LFRGenerator.hpp +175 -0
  234. package/vendor/include/networkit/generators/MocnikGenerator.hpp +147 -0
  235. package/vendor/include/networkit/generators/MocnikGeneratorBasic.hpp +58 -0
  236. package/vendor/include/networkit/generators/PowerlawDegreeSequence.hpp +128 -0
  237. package/vendor/include/networkit/generators/PubWebGenerator.hpp +94 -0
  238. package/vendor/include/networkit/generators/RegularRingLatticeGenerator.hpp +37 -0
  239. package/vendor/include/networkit/generators/RmatGenerator.hpp +67 -0
  240. package/vendor/include/networkit/generators/StaticDegreeSequenceGenerator.hpp +42 -0
  241. package/vendor/include/networkit/generators/StaticGraphGenerator.hpp +30 -0
  242. package/vendor/include/networkit/generators/StochasticBlockmodel.hpp +41 -0
  243. package/vendor/include/networkit/generators/WattsStrogatzGenerator.hpp +43 -0
  244. package/vendor/include/networkit/generators/quadtree/QuadNode.hpp +857 -0
  245. package/vendor/include/networkit/generators/quadtree/QuadNodeCartesianEuclid.hpp +587 -0
  246. package/vendor/include/networkit/generators/quadtree/QuadNodePolarEuclid.hpp +726 -0
  247. package/vendor/include/networkit/generators/quadtree/Quadtree.hpp +232 -0
  248. package/vendor/include/networkit/generators/quadtree/QuadtreeCartesianEuclid.hpp +149 -0
  249. package/vendor/include/networkit/generators/quadtree/QuadtreePolarEuclid.hpp +143 -0
  250. package/vendor/include/networkit/geometric/HyperbolicSpace.hpp +248 -0
  251. package/vendor/include/networkit/geometric/Point2DWithIndex.hpp +145 -0
  252. package/vendor/include/networkit/global/ClusteringCoefficient.hpp +42 -0
  253. package/vendor/include/networkit/global/GlobalClusteringCoefficient.hpp +24 -0
  254. package/vendor/include/networkit/graph/Attributes.hpp +568 -0
  255. package/vendor/include/networkit/graph/BFS.hpp +111 -0
  256. package/vendor/include/networkit/graph/DFS.hpp +71 -0
  257. package/vendor/include/networkit/graph/Dijkstra.hpp +83 -0
  258. package/vendor/include/networkit/graph/EdgeIterators.hpp +171 -0
  259. package/vendor/include/networkit/graph/Graph.hpp +2083 -0
  260. package/vendor/include/networkit/graph/GraphBuilder.hpp +289 -0
  261. package/vendor/include/networkit/graph/GraphR.hpp +133 -0
  262. package/vendor/include/networkit/graph/GraphTools.hpp +589 -0
  263. package/vendor/include/networkit/graph/GraphW.hpp +1236 -0
  264. package/vendor/include/networkit/graph/KruskalMSF.hpp +50 -0
  265. package/vendor/include/networkit/graph/NeighborIterators.hpp +163 -0
  266. package/vendor/include/networkit/graph/NodeIterators.hpp +127 -0
  267. package/vendor/include/networkit/graph/PrimMSF.hpp +66 -0
  268. package/vendor/include/networkit/graph/RandomMaximumSpanningForest.hpp +133 -0
  269. package/vendor/include/networkit/graph/SpanningForest.hpp +41 -0
  270. package/vendor/include/networkit/graph/TopologicalSort.hpp +87 -0
  271. package/vendor/include/networkit/graph/UnionMaximumSpanningForest.hpp +126 -0
  272. package/vendor/include/networkit/graph/test/GraphBuilderBenchmark.hpp +68 -0
  273. package/vendor/include/networkit/independentset/IndependentSetFinder.hpp +44 -0
  274. package/vendor/include/networkit/independentset/Luby.hpp +27 -0
  275. package/vendor/include/networkit/io/BinaryEdgeListPartitionReader.hpp +45 -0
  276. package/vendor/include/networkit/io/BinaryEdgeListPartitionWriter.hpp +47 -0
  277. package/vendor/include/networkit/io/BinaryPartitionReader.hpp +41 -0
  278. package/vendor/include/networkit/io/BinaryPartitionWriter.hpp +44 -0
  279. package/vendor/include/networkit/io/CoverReader.hpp +27 -0
  280. package/vendor/include/networkit/io/CoverWriter.hpp +21 -0
  281. package/vendor/include/networkit/io/DGSReader.hpp +39 -0
  282. package/vendor/include/networkit/io/DibapGraphReader.hpp +43 -0
  283. package/vendor/include/networkit/io/DotGraphWriter.hpp +39 -0
  284. package/vendor/include/networkit/io/DotPartitionWriter.hpp +23 -0
  285. package/vendor/include/networkit/io/DynamicGraphReader.hpp +29 -0
  286. package/vendor/include/networkit/io/EdgeListCoverReader.hpp +35 -0
  287. package/vendor/include/networkit/io/EdgeListPartitionReader.hpp +43 -0
  288. package/vendor/include/networkit/io/EdgeListReader.hpp +61 -0
  289. package/vendor/include/networkit/io/EdgeListWriter.hpp +48 -0
  290. package/vendor/include/networkit/io/GMLGraphReader.hpp +33 -0
  291. package/vendor/include/networkit/io/GMLGraphWriter.hpp +33 -0
  292. package/vendor/include/networkit/io/GraphIO.hpp +52 -0
  293. package/vendor/include/networkit/io/GraphReader.hpp +40 -0
  294. package/vendor/include/networkit/io/GraphToolBinaryReader.hpp +71 -0
  295. package/vendor/include/networkit/io/GraphToolBinaryWriter.hpp +61 -0
  296. package/vendor/include/networkit/io/GraphWriter.hpp +27 -0
  297. package/vendor/include/networkit/io/KONECTGraphReader.hpp +44 -0
  298. package/vendor/include/networkit/io/LineFileReader.hpp +42 -0
  299. package/vendor/include/networkit/io/METISGraphReader.hpp +36 -0
  300. package/vendor/include/networkit/io/METISGraphWriter.hpp +29 -0
  301. package/vendor/include/networkit/io/METISParser.hpp +63 -0
  302. package/vendor/include/networkit/io/MTXGraphReader.hpp +31 -0
  303. package/vendor/include/networkit/io/MTXParser.hpp +87 -0
  304. package/vendor/include/networkit/io/MatrixMarketReader.hpp +33 -0
  305. package/vendor/include/networkit/io/MatrixReader.hpp +33 -0
  306. package/vendor/include/networkit/io/MemoryMappedFile.hpp +80 -0
  307. package/vendor/include/networkit/io/NetworkitBinaryGraph.hpp +144 -0
  308. package/vendor/include/networkit/io/NetworkitBinaryReader.hpp +50 -0
  309. package/vendor/include/networkit/io/NetworkitBinaryWriter.hpp +71 -0
  310. package/vendor/include/networkit/io/PartitionReader.hpp +34 -0
  311. package/vendor/include/networkit/io/PartitionWriter.hpp +31 -0
  312. package/vendor/include/networkit/io/RBGraphReader.hpp +37 -0
  313. package/vendor/include/networkit/io/RBMatrixReader.hpp +49 -0
  314. package/vendor/include/networkit/io/RasterReader.hpp +40 -0
  315. package/vendor/include/networkit/io/SNAPEdgeListPartitionReader.hpp +28 -0
  316. package/vendor/include/networkit/io/SNAPGraphReader.hpp +53 -0
  317. package/vendor/include/networkit/io/SNAPGraphWriter.hpp +53 -0
  318. package/vendor/include/networkit/io/ThrillGraphBinaryReader.hpp +44 -0
  319. package/vendor/include/networkit/io/ThrillGraphBinaryWriter.hpp +27 -0
  320. package/vendor/include/networkit/layout/LayoutAlgorithm.hpp +39 -0
  321. package/vendor/include/networkit/linkprediction/AdamicAdarIndex.hpp +37 -0
  322. package/vendor/include/networkit/linkprediction/AdjustedRandIndex.hpp +36 -0
  323. package/vendor/include/networkit/linkprediction/AlgebraicDistanceIndex.hpp +70 -0
  324. package/vendor/include/networkit/linkprediction/CommonNeighborsIndex.hpp +39 -0
  325. package/vendor/include/networkit/linkprediction/EvaluationMetric.hpp +135 -0
  326. package/vendor/include/networkit/linkprediction/JaccardIndex.hpp +44 -0
  327. package/vendor/include/networkit/linkprediction/KatzIndex.hpp +84 -0
  328. package/vendor/include/networkit/linkprediction/LinkPredictor.hpp +98 -0
  329. package/vendor/include/networkit/linkprediction/LinkThresholder.hpp +56 -0
  330. package/vendor/include/networkit/linkprediction/MissingLinksFinder.hpp +60 -0
  331. package/vendor/include/networkit/linkprediction/NeighborhoodDistanceIndex.hpp +42 -0
  332. package/vendor/include/networkit/linkprediction/NeighborhoodUtility.hpp +54 -0
  333. package/vendor/include/networkit/linkprediction/NeighborsMeasureIndex.hpp +48 -0
  334. package/vendor/include/networkit/linkprediction/PrecisionRecallMetric.hpp +40 -0
  335. package/vendor/include/networkit/linkprediction/PredictionsSorter.hpp +66 -0
  336. package/vendor/include/networkit/linkprediction/PreferentialAttachmentIndex.hpp +37 -0
  337. package/vendor/include/networkit/linkprediction/ROCMetric.hpp +39 -0
  338. package/vendor/include/networkit/linkprediction/RandomLinkSampler.hpp +47 -0
  339. package/vendor/include/networkit/linkprediction/ResourceAllocationIndex.hpp +38 -0
  340. package/vendor/include/networkit/linkprediction/SameCommunityIndex.hpp +50 -0
  341. package/vendor/include/networkit/linkprediction/TotalNeighborsIndex.hpp +39 -0
  342. package/vendor/include/networkit/linkprediction/UDegreeIndex.hpp +35 -0
  343. package/vendor/include/networkit/linkprediction/VDegreeIndex.hpp +35 -0
  344. package/vendor/include/networkit/matching/BMatcher.hpp +52 -0
  345. package/vendor/include/networkit/matching/BMatching.hpp +115 -0
  346. package/vendor/include/networkit/matching/BSuitorMatcher.hpp +170 -0
  347. package/vendor/include/networkit/matching/DynamicBSuitorMatcher.hpp +78 -0
  348. package/vendor/include/networkit/matching/LocalMaxMatcher.hpp +35 -0
  349. package/vendor/include/networkit/matching/Matcher.hpp +55 -0
  350. package/vendor/include/networkit/matching/Matching.hpp +111 -0
  351. package/vendor/include/networkit/matching/PathGrowingMatcher.hpp +46 -0
  352. package/vendor/include/networkit/matching/SuitorMatcher.hpp +62 -0
  353. package/vendor/include/networkit/numerics/ConjugateGradient.hpp +163 -0
  354. package/vendor/include/networkit/numerics/GaussSeidelRelaxation.hpp +99 -0
  355. package/vendor/include/networkit/numerics/LAMG/LAMGSettings.hpp +70 -0
  356. package/vendor/include/networkit/numerics/LAMG/Lamg.hpp +460 -0
  357. package/vendor/include/networkit/numerics/LAMG/Level/EliminationStage.hpp +47 -0
  358. package/vendor/include/networkit/numerics/LAMG/Level/Level.hpp +56 -0
  359. package/vendor/include/networkit/numerics/LAMG/Level/LevelAggregation.hpp +52 -0
  360. package/vendor/include/networkit/numerics/LAMG/Level/LevelElimination.hpp +133 -0
  361. package/vendor/include/networkit/numerics/LAMG/Level/LevelFinest.hpp +28 -0
  362. package/vendor/include/networkit/numerics/LAMG/LevelHierarchy.hpp +165 -0
  363. package/vendor/include/networkit/numerics/LAMG/MultiLevelSetup.hpp +1090 -0
  364. package/vendor/include/networkit/numerics/LAMG/SolverLamg.hpp +316 -0
  365. package/vendor/include/networkit/numerics/LinearSolver.hpp +151 -0
  366. package/vendor/include/networkit/numerics/Preconditioner/DiagonalPreconditioner.hpp +61 -0
  367. package/vendor/include/networkit/numerics/Preconditioner/IdentityPreconditioner.hpp +36 -0
  368. package/vendor/include/networkit/numerics/Smoother.hpp +37 -0
  369. package/vendor/include/networkit/overlap/HashingOverlapper.hpp +28 -0
  370. package/vendor/include/networkit/overlap/Overlapper.hpp +27 -0
  371. package/vendor/include/networkit/planarity/LeftRightPlanarityCheck.hpp +113 -0
  372. package/vendor/include/networkit/randomization/Curveball.hpp +49 -0
  373. package/vendor/include/networkit/randomization/CurveballGlobalTradeGenerator.hpp +39 -0
  374. package/vendor/include/networkit/randomization/CurveballUniformTradeGenerator.hpp +39 -0
  375. package/vendor/include/networkit/randomization/DegreePreservingShuffle.hpp +82 -0
  376. package/vendor/include/networkit/randomization/EdgeSwitching.hpp +157 -0
  377. package/vendor/include/networkit/randomization/GlobalCurveball.hpp +69 -0
  378. package/vendor/include/networkit/randomization/GlobalTradeSequence.hpp +303 -0
  379. package/vendor/include/networkit/reachability/AllSimplePaths.hpp +122 -0
  380. package/vendor/include/networkit/reachability/ReachableNodes.hpp +83 -0
  381. package/vendor/include/networkit/scd/ApproximatePageRank.hpp +51 -0
  382. package/vendor/include/networkit/scd/CliqueDetect.hpp +55 -0
  383. package/vendor/include/networkit/scd/CombinedSCD.hpp +51 -0
  384. package/vendor/include/networkit/scd/GCE.hpp +42 -0
  385. package/vendor/include/networkit/scd/LFMLocal.hpp +54 -0
  386. package/vendor/include/networkit/scd/LocalT.hpp +40 -0
  387. package/vendor/include/networkit/scd/LocalTightnessExpansion.hpp +46 -0
  388. package/vendor/include/networkit/scd/PageRankNibble.hpp +55 -0
  389. package/vendor/include/networkit/scd/RandomBFS.hpp +33 -0
  390. package/vendor/include/networkit/scd/SCDGroundTruthComparison.hpp +121 -0
  391. package/vendor/include/networkit/scd/SelectiveCommunityDetector.hpp +76 -0
  392. package/vendor/include/networkit/scd/SetConductance.hpp +47 -0
  393. package/vendor/include/networkit/scd/TCE.hpp +41 -0
  394. package/vendor/include/networkit/scd/TwoPhaseL.hpp +40 -0
  395. package/vendor/include/networkit/scoring/EdgeScoring.hpp +44 -0
  396. package/vendor/include/networkit/scoring/ModularityScoring.hpp +79 -0
  397. package/vendor/include/networkit/simulation/EpidemicSimulationSEIR.hpp +59 -0
  398. package/vendor/include/networkit/sparsification/ChanceCorrectedTriangleScore.hpp +28 -0
  399. package/vendor/include/networkit/sparsification/ForestFireScore.hpp +34 -0
  400. package/vendor/include/networkit/sparsification/GlobalThresholdFilter.hpp +40 -0
  401. package/vendor/include/networkit/sparsification/LocalDegreeScore.hpp +30 -0
  402. package/vendor/include/networkit/sparsification/LocalFilterScore.hpp +124 -0
  403. package/vendor/include/networkit/sparsification/LocalSimilarityScore.hpp +63 -0
  404. package/vendor/include/networkit/sparsification/MultiscaleScore.hpp +38 -0
  405. package/vendor/include/networkit/sparsification/RandomEdgeScore.hpp +33 -0
  406. package/vendor/include/networkit/sparsification/RandomNodeEdgeScore.hpp +29 -0
  407. package/vendor/include/networkit/sparsification/SCANStructuralSimilarityScore.hpp +23 -0
  408. package/vendor/include/networkit/sparsification/SimmelianOverlapScore.hpp +35 -0
  409. package/vendor/include/networkit/sparsification/SimmelianScore.hpp +92 -0
  410. package/vendor/include/networkit/sparsification/Sparsifiers.hpp +166 -0
  411. package/vendor/include/networkit/structures/Cover.hpp +248 -0
  412. package/vendor/include/networkit/structures/LocalCommunity.hpp +363 -0
  413. package/vendor/include/networkit/structures/Partition.hpp +335 -0
  414. package/vendor/include/networkit/structures/UnionFind.hpp +66 -0
  415. package/vendor/include/networkit/viz/GraphLayoutAlgorithm.hpp +157 -0
  416. package/vendor/include/networkit/viz/MaxentStress.hpp +346 -0
  417. package/vendor/include/networkit/viz/Octree.hpp +428 -0
  418. package/vendor/include/networkit/viz/PivotMDS.hpp +63 -0
  419. package/vendor/include/networkit/viz/Point.hpp +415 -0
  420. package/vendor/include/networkit/viz/PostscriptWriter.hpp +78 -0
  421. package/vendor/include/tlx/algorithm/exclusive_scan.hpp +56 -0
  422. package/vendor/include/tlx/algorithm/is_sorted_cmp.hpp +56 -0
  423. package/vendor/include/tlx/algorithm/merge_advance.hpp +177 -0
  424. package/vendor/include/tlx/algorithm/merge_combine.hpp +76 -0
  425. package/vendor/include/tlx/algorithm/multisequence_partition.hpp +346 -0
  426. package/vendor/include/tlx/algorithm/multisequence_selection.hpp +351 -0
  427. package/vendor/include/tlx/algorithm/multiway_merge.hpp +1385 -0
  428. package/vendor/include/tlx/algorithm/multiway_merge_splitting.hpp +257 -0
  429. package/vendor/include/tlx/algorithm/parallel_multiway_merge.hpp +408 -0
  430. package/vendor/include/tlx/algorithm/random_bipartition_shuffle.hpp +116 -0
  431. package/vendor/include/tlx/algorithm.hpp +36 -0
  432. package/vendor/include/tlx/allocator_base.hpp +100 -0
  433. package/vendor/include/tlx/backtrace.hpp +54 -0
  434. package/vendor/include/tlx/cmdline_parser.hpp +498 -0
  435. package/vendor/include/tlx/container/btree.hpp +3977 -0
  436. package/vendor/include/tlx/container/btree_map.hpp +634 -0
  437. package/vendor/include/tlx/container/btree_multimap.hpp +627 -0
  438. package/vendor/include/tlx/container/btree_multiset.hpp +612 -0
  439. package/vendor/include/tlx/container/btree_set.hpp +612 -0
  440. package/vendor/include/tlx/container/d_ary_addressable_int_heap.hpp +416 -0
  441. package/vendor/include/tlx/container/d_ary_heap.hpp +311 -0
  442. package/vendor/include/tlx/container/loser_tree.hpp +1009 -0
  443. package/vendor/include/tlx/container/lru_cache.hpp +319 -0
  444. package/vendor/include/tlx/container/radix_heap.hpp +735 -0
  445. package/vendor/include/tlx/container/ring_buffer.hpp +428 -0
  446. package/vendor/include/tlx/container/simple_vector.hpp +304 -0
  447. package/vendor/include/tlx/container/splay_tree.hpp +399 -0
  448. package/vendor/include/tlx/container/string_view.hpp +805 -0
  449. package/vendor/include/tlx/container.hpp +40 -0
  450. package/vendor/include/tlx/counting_ptr.hpp +522 -0
  451. package/vendor/include/tlx/define/attribute_always_inline.hpp +34 -0
  452. package/vendor/include/tlx/define/attribute_fallthrough.hpp +36 -0
  453. package/vendor/include/tlx/define/attribute_format_printf.hpp +34 -0
  454. package/vendor/include/tlx/define/attribute_packed.hpp +34 -0
  455. package/vendor/include/tlx/define/attribute_warn_unused_result.hpp +34 -0
  456. package/vendor/include/tlx/define/constexpr.hpp +31 -0
  457. package/vendor/include/tlx/define/deprecated.hpp +39 -0
  458. package/vendor/include/tlx/define/endian.hpp +49 -0
  459. package/vendor/include/tlx/define/likely.hpp +33 -0
  460. package/vendor/include/tlx/define/visibility_hidden.hpp +34 -0
  461. package/vendor/include/tlx/define.hpp +36 -0
  462. package/vendor/include/tlx/delegate.hpp +524 -0
  463. package/vendor/include/tlx/die/core.hpp +311 -0
  464. package/vendor/include/tlx/die.hpp +106 -0
  465. package/vendor/include/tlx/digest/md5.hpp +81 -0
  466. package/vendor/include/tlx/digest/sha1.hpp +81 -0
  467. package/vendor/include/tlx/digest/sha256.hpp +81 -0
  468. package/vendor/include/tlx/digest/sha512.hpp +81 -0
  469. package/vendor/include/tlx/digest.hpp +30 -0
  470. package/vendor/include/tlx/logger/all.hpp +33 -0
  471. package/vendor/include/tlx/logger/array.hpp +43 -0
  472. package/vendor/include/tlx/logger/core.hpp +287 -0
  473. package/vendor/include/tlx/logger/deque.hpp +42 -0
  474. package/vendor/include/tlx/logger/map.hpp +65 -0
  475. package/vendor/include/tlx/logger/set.hpp +60 -0
  476. package/vendor/include/tlx/logger/tuple.hpp +66 -0
  477. package/vendor/include/tlx/logger/unordered_map.hpp +68 -0
  478. package/vendor/include/tlx/logger/unordered_set.hpp +64 -0
  479. package/vendor/include/tlx/logger/wrap_unprintable.hpp +75 -0
  480. package/vendor/include/tlx/logger.hpp +44 -0
  481. package/vendor/include/tlx/math/abs_diff.hpp +35 -0
  482. package/vendor/include/tlx/math/aggregate.hpp +231 -0
  483. package/vendor/include/tlx/math/aggregate_min_max.hpp +116 -0
  484. package/vendor/include/tlx/math/bswap.hpp +148 -0
  485. package/vendor/include/tlx/math/bswap_be.hpp +79 -0
  486. package/vendor/include/tlx/math/bswap_le.hpp +79 -0
  487. package/vendor/include/tlx/math/clz.hpp +174 -0
  488. package/vendor/include/tlx/math/ctz.hpp +174 -0
  489. package/vendor/include/tlx/math/div_ceil.hpp +36 -0
  490. package/vendor/include/tlx/math/ffs.hpp +123 -0
  491. package/vendor/include/tlx/math/integer_log2.hpp +189 -0
  492. package/vendor/include/tlx/math/is_power_of_two.hpp +74 -0
  493. package/vendor/include/tlx/math/polynomial_regression.hpp +243 -0
  494. package/vendor/include/tlx/math/popcount.hpp +173 -0
  495. package/vendor/include/tlx/math/power_to_the.hpp +44 -0
  496. package/vendor/include/tlx/math/rol.hpp +112 -0
  497. package/vendor/include/tlx/math/ror.hpp +112 -0
  498. package/vendor/include/tlx/math/round_to_power_of_two.hpp +121 -0
  499. package/vendor/include/tlx/math/round_up.hpp +36 -0
  500. package/vendor/include/tlx/math/sgn.hpp +38 -0
  501. package/vendor/include/tlx/math.hpp +46 -0
  502. package/vendor/include/tlx/meta/apply_tuple.hpp +55 -0
  503. package/vendor/include/tlx/meta/call_for_range.hpp +78 -0
  504. package/vendor/include/tlx/meta/call_foreach.hpp +60 -0
  505. package/vendor/include/tlx/meta/call_foreach_tuple.hpp +60 -0
  506. package/vendor/include/tlx/meta/call_foreach_tuple_with_index.hpp +61 -0
  507. package/vendor/include/tlx/meta/call_foreach_with_index.hpp +64 -0
  508. package/vendor/include/tlx/meta/enable_if.hpp +37 -0
  509. package/vendor/include/tlx/meta/fold_left.hpp +63 -0
  510. package/vendor/include/tlx/meta/fold_left_tuple.hpp +60 -0
  511. package/vendor/include/tlx/meta/fold_right.hpp +63 -0
  512. package/vendor/include/tlx/meta/fold_right_tuple.hpp +60 -0
  513. package/vendor/include/tlx/meta/function_chain.hpp +197 -0
  514. package/vendor/include/tlx/meta/function_stack.hpp +189 -0
  515. package/vendor/include/tlx/meta/has_member.hpp +80 -0
  516. package/vendor/include/tlx/meta/has_method.hpp +117 -0
  517. package/vendor/include/tlx/meta/index_sequence.hpp +66 -0
  518. package/vendor/include/tlx/meta/is_std_array.hpp +40 -0
  519. package/vendor/include/tlx/meta/is_std_pair.hpp +39 -0
  520. package/vendor/include/tlx/meta/is_std_tuple.hpp +39 -0
  521. package/vendor/include/tlx/meta/is_std_vector.hpp +39 -0
  522. package/vendor/include/tlx/meta/log2.hpp +101 -0
  523. package/vendor/include/tlx/meta/no_operation.hpp +55 -0
  524. package/vendor/include/tlx/meta/static_index.hpp +42 -0
  525. package/vendor/include/tlx/meta/vexpand.hpp +34 -0
  526. package/vendor/include/tlx/meta/vmap_for_range.hpp +84 -0
  527. package/vendor/include/tlx/meta/vmap_foreach.hpp +63 -0
  528. package/vendor/include/tlx/meta/vmap_foreach_tuple.hpp +59 -0
  529. package/vendor/include/tlx/meta/vmap_foreach_tuple_with_index.hpp +62 -0
  530. package/vendor/include/tlx/meta/vmap_foreach_with_index.hpp +70 -0
  531. package/vendor/include/tlx/meta.hpp +55 -0
  532. package/vendor/include/tlx/multi_timer.hpp +148 -0
  533. package/vendor/include/tlx/port/setenv.hpp +31 -0
  534. package/vendor/include/tlx/port.hpp +27 -0
  535. package/vendor/include/tlx/semaphore.hpp +119 -0
  536. package/vendor/include/tlx/simple_vector.hpp +20 -0
  537. package/vendor/include/tlx/siphash.hpp +282 -0
  538. package/vendor/include/tlx/sort/networks/best.hpp +611 -0
  539. package/vendor/include/tlx/sort/networks/bose_nelson.hpp +412 -0
  540. package/vendor/include/tlx/sort/networks/bose_nelson_parameter.hpp +507 -0
  541. package/vendor/include/tlx/sort/networks/cswap.hpp +60 -0
  542. package/vendor/include/tlx/sort/parallel_mergesort.hpp +398 -0
  543. package/vendor/include/tlx/sort/strings/insertion_sort.hpp +232 -0
  544. package/vendor/include/tlx/sort/strings/multikey_quicksort.hpp +185 -0
  545. package/vendor/include/tlx/sort/strings/parallel_sample_sort.hpp +1647 -0
  546. package/vendor/include/tlx/sort/strings/radix_sort.hpp +934 -0
  547. package/vendor/include/tlx/sort/strings/sample_sort_tools.hpp +756 -0
  548. package/vendor/include/tlx/sort/strings/string_ptr.hpp +426 -0
  549. package/vendor/include/tlx/sort/strings/string_set.hpp +800 -0
  550. package/vendor/include/tlx/sort/strings.hpp +329 -0
  551. package/vendor/include/tlx/sort/strings_parallel.hpp +325 -0
  552. package/vendor/include/tlx/sort.hpp +29 -0
  553. package/vendor/include/tlx/stack_allocator.hpp +226 -0
  554. package/vendor/include/tlx/string/appendline.hpp +35 -0
  555. package/vendor/include/tlx/string/base64.hpp +87 -0
  556. package/vendor/include/tlx/string/bitdump.hpp +139 -0
  557. package/vendor/include/tlx/string/compare_icase.hpp +42 -0
  558. package/vendor/include/tlx/string/contains.hpp +36 -0
  559. package/vendor/include/tlx/string/contains_word.hpp +42 -0
  560. package/vendor/include/tlx/string/ends_with.hpp +79 -0
  561. package/vendor/include/tlx/string/equal_icase.hpp +42 -0
  562. package/vendor/include/tlx/string/erase_all.hpp +70 -0
  563. package/vendor/include/tlx/string/escape_html.hpp +34 -0
  564. package/vendor/include/tlx/string/escape_uri.hpp +34 -0
  565. package/vendor/include/tlx/string/expand_environment_variables.hpp +49 -0
  566. package/vendor/include/tlx/string/extract_between.hpp +40 -0
  567. package/vendor/include/tlx/string/format_iec_units.hpp +32 -0
  568. package/vendor/include/tlx/string/format_si_iec_units.hpp +19 -0
  569. package/vendor/include/tlx/string/format_si_units.hpp +32 -0
  570. package/vendor/include/tlx/string/hash_djb2.hpp +87 -0
  571. package/vendor/include/tlx/string/hash_sdbm.hpp +86 -0
  572. package/vendor/include/tlx/string/hexdump.hpp +154 -0
  573. package/vendor/include/tlx/string/index_of.hpp +56 -0
  574. package/vendor/include/tlx/string/join.hpp +65 -0
  575. package/vendor/include/tlx/string/join_generic.hpp +89 -0
  576. package/vendor/include/tlx/string/join_quoted.hpp +46 -0
  577. package/vendor/include/tlx/string/less_icase.hpp +64 -0
  578. package/vendor/include/tlx/string/levenshtein.hpp +193 -0
  579. package/vendor/include/tlx/string/pad.hpp +39 -0
  580. package/vendor/include/tlx/string/parse_si_iec_units.hpp +46 -0
  581. package/vendor/include/tlx/string/parse_uri.hpp +66 -0
  582. package/vendor/include/tlx/string/parse_uri_form_data.hpp +136 -0
  583. package/vendor/include/tlx/string/replace.hpp +141 -0
  584. package/vendor/include/tlx/string/split.hpp +170 -0
  585. package/vendor/include/tlx/string/split_quoted.hpp +49 -0
  586. package/vendor/include/tlx/string/split_view.hpp +218 -0
  587. package/vendor/include/tlx/string/split_words.hpp +53 -0
  588. package/vendor/include/tlx/string/ssprintf.hpp +45 -0
  589. package/vendor/include/tlx/string/ssprintf_generic.hpp +95 -0
  590. package/vendor/include/tlx/string/starts_with.hpp +44 -0
  591. package/vendor/include/tlx/string/to_lower.hpp +47 -0
  592. package/vendor/include/tlx/string/to_upper.hpp +47 -0
  593. package/vendor/include/tlx/string/trim.hpp +298 -0
  594. package/vendor/include/tlx/string/union_words.hpp +33 -0
  595. package/vendor/include/tlx/string/word_wrap.hpp +35 -0
  596. package/vendor/include/tlx/string.hpp +68 -0
  597. package/vendor/include/tlx/thread_barrier_mutex.hpp +109 -0
  598. package/vendor/include/tlx/thread_barrier_spin.hpp +127 -0
  599. package/vendor/include/tlx/thread_pool.hpp +151 -0
  600. package/vendor/include/tlx/timestamp.hpp +23 -0
  601. package/vendor/include/tlx/unused.hpp +28 -0
  602. package/vendor/include/tlx/vector_free.hpp +30 -0
  603. package/vendor/include/tlx/version.hpp +49 -0
  604. package/vendor/include/ttmath/ttmath.h +2881 -0
  605. package/vendor/include/ttmath/ttmathbig.h +6111 -0
  606. package/vendor/include/ttmath/ttmathdec.h +419 -0
  607. package/vendor/include/ttmath/ttmathint.h +1923 -0
  608. package/vendor/include/ttmath/ttmathmisc.h +250 -0
  609. package/vendor/include/ttmath/ttmathobjects.h +812 -0
  610. package/vendor/include/ttmath/ttmathparser.h +2791 -0
  611. package/vendor/include/ttmath/ttmaththreads.h +252 -0
  612. package/vendor/include/ttmath/ttmathtypes.h +707 -0
  613. package/vendor/include/ttmath/ttmathuint.h +4190 -0
  614. package/vendor/include/ttmath/ttmathuint_noasm.h +1038 -0
  615. package/vendor/include/ttmath/ttmathuint_x86.h +1620 -0
  616. package/vendor/include/ttmath/ttmathuint_x86_64.h +1177 -0
  617. package/vendor/lib/cmake/tlx/tlx-config.cmake +51 -0
  618. package/vendor/lib/cmake/tlx/tlx-targets-release.cmake +19 -0
  619. package/vendor/lib/cmake/tlx/tlx-targets.cmake +106 -0
  620. package/vendor/lib/cmake/tlx/tlx-version.cmake +11 -0
  621. package/vendor/lib/libnetworkit.dylib +0 -0
  622. package/vendor/lib/libtlx.a +0 -0
  623. package/vendor/lib/pkgconfig/networkit.pc +11 -0
  624. package/vendor/lib/pkgconfig/tlx.pc +11 -0
@@ -0,0 +1,4190 @@
1
+ /*
2
+ * This file is a part of TTMath Bignum Library
3
+ * and is distributed under the 3-Clause BSD Licence.
4
+ * Author: Tomasz Sowa <t.sowa@ttmath.org>
5
+ */
6
+
7
+ /*
8
+ * Copyright (c) 2006-2017, Tomasz Sowa
9
+ * All rights reserved.
10
+ *
11
+ * Redistribution and use in source and binary forms, with or without
12
+ * modification, are permitted provided that the following conditions are met:
13
+ *
14
+ * * Redistributions of source code must retain the above copyright notice,
15
+ * this list of conditions and the following disclaimer.
16
+ *
17
+ * * Redistributions in binary form must reproduce the above copyright
18
+ * notice, this list of conditions and the following disclaimer in the
19
+ * documentation and/or other materials provided with the distribution.
20
+ *
21
+ * * Neither the name Tomasz Sowa nor the names of contributors to this
22
+ * project may be used to endorse or promote products derived
23
+ * from this software without specific prior written permission.
24
+ *
25
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35
+ * THE POSSIBILITY OF SUCH DAMAGE.
36
+ */
37
+
38
+
39
+
40
+ #ifndef headerfilettmathuint
41
+ #define headerfilettmathuint
42
+
43
+
44
+ /*!
45
+ \file ttmathuint.h
46
+ \brief template class UInt<uint>
47
+ */
48
+
49
+ #include <iostream>
50
+ #include <iomanip>
51
+
52
+
53
+ #include "ttmathtypes.h"
54
+ #include "ttmathmisc.h"
55
+
56
+
57
+
58
+ /*!
59
+ \brief a namespace for the TTMath library
60
+ */
61
+ namespace ttmath
62
+ {
63
+
64
+ /*!
65
+ \brief UInt implements a big integer value without a sign
66
+
67
+ value_size - how many bytes specify our value
68
+ - on 32bit platforms: value_size=1 -> 4 bytes -> 32 bits
69
+ - on 64bit platforms: value_size=1 -> 8 bytes -> 64 bits
70
+ value_size = 1,2,3,4,5,6....
71
+ */
72
+ template<uint value_size>
73
+ class UInt
74
+ {
75
+ public:
76
+
77
+ /*!
78
+ buffer for the integer value
79
+ table[0] - the lowest word of the value
80
+ */
81
+ uint table[value_size];
82
+
83
+
84
+
85
+ /*!
86
+ some methods used for debugging purposes
87
+ */
88
+
89
+
90
+ /*!
91
+ this method is only for debugging purposes or when we want to make
92
+ a table of a variable (constant) in ttmathbig.h
93
+
94
+ it prints the table in a nice form of several columns
95
+ */
96
+ template<class ostream_type>
97
+ void PrintTable(ostream_type & output) const
98
+ {
99
+ // how many columns there'll be
100
+ const int columns = 8;
101
+
102
+ int c = 1;
103
+ for(int i=value_size-1 ; i>=0 ; --i)
104
+ {
105
+ output << "0x" << std::setfill('0');
106
+
107
+ #ifdef TTMATH_PLATFORM32
108
+ output << std::setw(8);
109
+ #else
110
+ output << std::setw(16);
111
+ #endif
112
+
113
+ output << std::hex << table[i];
114
+
115
+ if( i>0 )
116
+ {
117
+ output << ", ";
118
+
119
+ if( ++c > columns )
120
+ {
121
+ output << std::endl;
122
+ c = 1;
123
+ }
124
+ }
125
+ }
126
+
127
+ output << std::dec << std::endl;
128
+ }
129
+
130
+
131
+ /*!
132
+ this method is used when macro TTMATH_DEBUG_LOG is defined
133
+ */
134
+ template<class char_type, class ostream_type>
135
+ static void PrintVectorLog(const char_type * msg, ostream_type & output, const uint * vector, uint vector_len)
136
+ {
137
+ output << msg << std::endl;
138
+
139
+ for(uint i=0 ; i<vector_len ; ++i)
140
+ output << " table[" << i << "]: " << vector[i] << std::endl;
141
+ }
142
+
143
+
144
+ /*!
145
+ this method is used when macro TTMATH_DEBUG_LOG is defined
146
+ */
147
+ template<class char_type, class ostream_type>
148
+ static void PrintVectorLog(const char_type * msg, uint carry, ostream_type & output, const uint * vector, uint vector_len)
149
+ {
150
+ PrintVectorLog(msg, output, vector, vector_len);
151
+ output << " carry: " << carry << std::endl;
152
+ }
153
+
154
+
155
+ /*!
156
+ this method is used when macro TTMATH_DEBUG_LOG is defined
157
+ */
158
+ template<class char_type, class ostream_type>
159
+ void PrintLog(const char_type * msg, ostream_type & output) const
160
+ {
161
+ PrintVectorLog(msg, output, table, value_size);
162
+ }
163
+
164
+
165
+ /*!
166
+ this method is used when macro TTMATH_DEBUG_LOG is defined
167
+ */
168
+ template<class char_type, class ostream_type>
169
+ void PrintLog(const char_type * msg, uint carry, ostream_type & output) const
170
+ {
171
+ PrintVectorLog(msg, output, table, value_size);
172
+ output << " carry: " << carry << std::endl;
173
+ }
174
+
175
+
176
+ /*!
177
+ this method returns the size of the table
178
+ */
179
+ uint Size() const
180
+ {
181
+ return value_size;
182
+ }
183
+
184
+
185
+ /*!
186
+ this method sets zero
187
+ */
188
+ void SetZero()
189
+ {
190
+ // in the future here can be 'memset'
191
+
192
+ for(uint i=0 ; i<value_size ; ++i)
193
+ table[i] = 0;
194
+
195
+ TTMATH_LOG("UInt::SetZero")
196
+ }
197
+
198
+
199
+ /*!
200
+ this method sets one
201
+ */
202
+ void SetOne()
203
+ {
204
+ SetZero();
205
+ table[0] = 1;
206
+
207
+ TTMATH_LOG("UInt::SetOne")
208
+ }
209
+
210
+
211
+ /*!
212
+ this method sets the max value which this class can hold
213
+ (all bits will be one)
214
+ */
215
+ void SetMax()
216
+ {
217
+ for(uint i=0 ; i<value_size ; ++i)
218
+ table[i] = TTMATH_UINT_MAX_VALUE;
219
+
220
+ TTMATH_LOG("UInt::SetMax")
221
+ }
222
+
223
+
224
+ /*!
225
+ this method sets the min value which this class can hold
226
+ (for an unsigned integer value the zero is the smallest value)
227
+ */
228
+ void SetMin()
229
+ {
230
+ SetZero();
231
+
232
+ TTMATH_LOG("UInt::SetMin")
233
+ }
234
+
235
+
236
+ /*!
237
+ this method swappes this for an argument
238
+ */
239
+ void Swap(UInt<value_size> & ss2)
240
+ {
241
+ for(uint i=0 ; i<value_size ; ++i)
242
+ {
243
+ uint temp = table[i];
244
+ table[i] = ss2.table[i];
245
+ ss2.table[i] = temp;
246
+ }
247
+ }
248
+
249
+
250
+ #ifdef TTMATH_PLATFORM32
251
+
252
+ /*!
253
+ this method copies the value stored in an another table
254
+ (warning: first values in temp_table are the highest words -- it's different
255
+ from our table)
256
+
257
+ we copy as many words as it is possible
258
+
259
+ if temp_table_len is bigger than value_size we'll try to round
260
+ the lowest word from table depending on the last not used bit in temp_table
261
+ (this rounding isn't a perfect rounding -- look at the description below)
262
+
263
+ and if temp_table_len is smaller than value_size we'll clear the rest words
264
+ in the table
265
+ */
266
+ void SetFromTable(const uint * temp_table, uint temp_table_len)
267
+ {
268
+ uint temp_table_index = 0;
269
+ sint i; // 'i' with a sign
270
+
271
+ for(i=value_size-1 ; i>=0 && temp_table_index<temp_table_len; --i, ++temp_table_index)
272
+ table[i] = temp_table[ temp_table_index ];
273
+
274
+
275
+ // rounding mantissa
276
+ if( temp_table_index < temp_table_len )
277
+ {
278
+ if( (temp_table[temp_table_index] & TTMATH_UINT_HIGHEST_BIT) != 0 )
279
+ {
280
+ /*
281
+ very simply rounding
282
+ if the bit from not used last word from temp_table is set to one
283
+ we're rouding the lowest word in the table
284
+
285
+ in fact there should be a normal addition but
286
+ we don't use Add() or AddTwoInts() because these methods
287
+ can set a carry and then there'll be a small problem
288
+ for optimization
289
+ */
290
+ if( table[0] != TTMATH_UINT_MAX_VALUE )
291
+ ++table[0];
292
+ }
293
+ }
294
+
295
+ // cleaning the rest of the mantissa
296
+ for( ; i>=0 ; --i)
297
+ table[i] = 0;
298
+
299
+
300
+ TTMATH_LOG("UInt::SetFromTable")
301
+ }
302
+
303
+ #endif
304
+
305
+
306
+ #ifdef TTMATH_PLATFORM64
307
+ /*!
308
+ this method copies the value stored in an another table
309
+ (warning: first values in temp_table are the highest words -- it's different
310
+ from our table)
311
+
312
+ ***this method is created only on a 64bit platform***
313
+
314
+ we copy as many words as it is possible
315
+
316
+ if temp_table_len is bigger than value_size we'll try to round
317
+ the lowest word from table depending on the last not used bit in temp_table
318
+ (this rounding isn't a perfect rounding -- look at the description below)
319
+
320
+ and if temp_table_len is smaller than value_size we'll clear the rest words
321
+ in the table
322
+
323
+ warning: we're using 'temp_table' as a pointer at 32bit words
324
+ */
325
+ void SetFromTable(const unsigned int * temp_table, uint temp_table_len)
326
+ {
327
+ uint temp_table_index = 0;
328
+ sint i; // 'i' with a sign
329
+
330
+ for(i=value_size-1 ; i>=0 && temp_table_index<temp_table_len; --i, ++temp_table_index)
331
+ {
332
+ table[i] = uint(temp_table[ temp_table_index ]) << 32;
333
+
334
+ ++temp_table_index;
335
+
336
+ if( temp_table_index<temp_table_len )
337
+ table[i] |= temp_table[ temp_table_index ];
338
+ }
339
+
340
+
341
+ // rounding mantissa
342
+ if( temp_table_index < temp_table_len )
343
+ {
344
+ if( (temp_table[temp_table_index] & TTMATH_UINT_HIGHEST_BIT) != 0 )
345
+ {
346
+ /*
347
+ very simply rounding
348
+ if the bit from not used last word from temp_table is set to one
349
+ we're rouding the lowest word in the table
350
+
351
+ in fact there should be a normal addition but
352
+ we don't use Add() or AddTwoInts() because these methods
353
+ can set a carry and then there'll be a small problem
354
+ for optimization
355
+ */
356
+ if( table[0] != TTMATH_UINT_MAX_VALUE )
357
+ ++table[0];
358
+ }
359
+ }
360
+
361
+ // cleaning the rest of the mantissa
362
+ for( ; i >= 0 ; --i)
363
+ table[i] = 0;
364
+
365
+ TTMATH_LOG("UInt::SetFromTable")
366
+ }
367
+
368
+ #endif
369
+
370
+
371
+
372
+
373
+
374
+ /*!
375
+ *
376
+ * basic mathematic functions
377
+ *
378
+ */
379
+
380
+
381
+
382
+
383
+ /*!
384
+ this method adds one to the existing value
385
+ */
386
+ uint AddOne()
387
+ {
388
+ return AddInt(1);
389
+ }
390
+
391
+
392
+ /*!
393
+ this method subtracts one from the existing value
394
+ */
395
+ uint SubOne()
396
+ {
397
+ return SubInt(1);
398
+ }
399
+
400
+
401
+ private:
402
+
403
+
404
+ /*!
405
+ an auxiliary method for moving bits into the left hand side
406
+
407
+ this method moves only words
408
+ */
409
+ void RclMoveAllWords(uint & rest_bits, uint & last_c, uint bits, uint c)
410
+ {
411
+ rest_bits = bits % TTMATH_BITS_PER_UINT;
412
+ uint all_words = bits / TTMATH_BITS_PER_UINT;
413
+ uint mask = ( c ) ? TTMATH_UINT_MAX_VALUE : 0;
414
+
415
+
416
+ if( all_words >= value_size )
417
+ {
418
+ if( all_words == value_size && rest_bits == 0 )
419
+ last_c = table[0] & 1;
420
+ // else: last_c is default set to 0
421
+
422
+ // clearing
423
+ for(uint i = 0 ; i<value_size ; ++i)
424
+ table[i] = mask;
425
+
426
+ rest_bits = 0;
427
+ }
428
+ else
429
+ if( all_words > 0 )
430
+ {
431
+ // 0 < all_words < value_size
432
+
433
+ sint first, second;
434
+ last_c = table[value_size - all_words] & 1; // all_words is greater than 0
435
+
436
+ // copying the first part of the value
437
+ for(first = value_size-1, second=first-all_words ; second>=0 ; --first, --second)
438
+ table[first] = table[second];
439
+
440
+ // setting the rest to 'c'
441
+ for( ; first>=0 ; --first )
442
+ table[first] = mask;
443
+ }
444
+
445
+ TTMATH_LOG("UInt::RclMoveAllWords")
446
+ }
447
+
448
+ public:
449
+
450
+ /*!
451
+ moving all bits into the left side 'bits' times
452
+ return value <- this <- C
453
+
454
+ bits is from a range of <0, man * TTMATH_BITS_PER_UINT>
455
+ or it can be even bigger then all bits will be set to 'c'
456
+
457
+ the value c will be set into the lowest bits
458
+ and the method returns state of the last moved bit
459
+ */
460
+ uint Rcl(uint bits, uint c=0)
461
+ {
462
+ uint last_c = 0;
463
+ uint rest_bits = bits;
464
+
465
+ if( bits == 0 )
466
+ return 0;
467
+
468
+ if( bits >= TTMATH_BITS_PER_UINT )
469
+ RclMoveAllWords(rest_bits, last_c, bits, c);
470
+
471
+ if( rest_bits == 0 )
472
+ {
473
+ TTMATH_LOG("UInt::Rcl")
474
+ return last_c;
475
+ }
476
+
477
+ // rest_bits is from 1 to TTMATH_BITS_PER_UINT-1 now
478
+ if( rest_bits == 1 )
479
+ {
480
+ last_c = Rcl2_one(c);
481
+ }
482
+ else if( rest_bits == 2 )
483
+ {
484
+ // performance tests showed that for rest_bits==2 it's better to use Rcl2_one twice instead of Rcl2(2,c)
485
+ Rcl2_one(c);
486
+ last_c = Rcl2_one(c);
487
+ }
488
+ else
489
+ {
490
+ last_c = Rcl2(rest_bits, c);
491
+ }
492
+
493
+ TTMATH_LOGC("UInt::Rcl", last_c)
494
+
495
+ return last_c;
496
+ }
497
+
498
+ private:
499
+
500
+ /*!
501
+ an auxiliary method for moving bits into the right hand side
502
+
503
+ this method moves only words
504
+ */
505
+ void RcrMoveAllWords(uint & rest_bits, uint & last_c, uint bits, uint c)
506
+ {
507
+ rest_bits = bits % TTMATH_BITS_PER_UINT;
508
+ uint all_words = bits / TTMATH_BITS_PER_UINT;
509
+ uint mask = ( c ) ? TTMATH_UINT_MAX_VALUE : 0;
510
+
511
+
512
+ if( all_words >= value_size )
513
+ {
514
+ if( all_words == value_size && rest_bits == 0 )
515
+ last_c = (table[value_size-1] & TTMATH_UINT_HIGHEST_BIT) ? 1 : 0;
516
+ // else: last_c is default set to 0
517
+
518
+ // clearing
519
+ for(uint i = 0 ; i<value_size ; ++i)
520
+ table[i] = mask;
521
+
522
+ rest_bits = 0;
523
+ }
524
+ else if( all_words > 0 )
525
+ {
526
+ // 0 < all_words < value_size
527
+
528
+ uint first, second;
529
+ last_c = (table[all_words - 1] & TTMATH_UINT_HIGHEST_BIT) ? 1 : 0; // all_words is > 0
530
+
531
+ // copying the first part of the value
532
+ for(first=0, second=all_words ; second<value_size ; ++first, ++second)
533
+ table[first] = table[second];
534
+
535
+ // setting the rest to 'c'
536
+ for( ; first<value_size ; ++first )
537
+ table[first] = mask;
538
+ }
539
+
540
+ TTMATH_LOG("UInt::RcrMoveAllWords")
541
+ }
542
+
543
+ public:
544
+
545
+ /*!
546
+ moving all bits into the right side 'bits' times
547
+ c -> this -> return value
548
+
549
+ bits is from a range of <0, man * TTMATH_BITS_PER_UINT>
550
+ or it can be even bigger then all bits will be set to 'c'
551
+
552
+ the value c will be set into the highest bits
553
+ and the method returns state of the last moved bit
554
+ */
555
+ uint Rcr(uint bits, uint c=0)
556
+ {
557
+ uint last_c = 0;
558
+ uint rest_bits = bits;
559
+
560
+ if( bits == 0 )
561
+ return 0;
562
+
563
+ if( bits >= TTMATH_BITS_PER_UINT )
564
+ RcrMoveAllWords(rest_bits, last_c, bits, c);
565
+
566
+ if( rest_bits == 0 )
567
+ {
568
+ TTMATH_LOG("UInt::Rcr")
569
+ return last_c;
570
+ }
571
+
572
+ // rest_bits is from 1 to TTMATH_BITS_PER_UINT-1 now
573
+ if( rest_bits == 1 )
574
+ {
575
+ last_c = Rcr2_one(c);
576
+ }
577
+ else if( rest_bits == 2 )
578
+ {
579
+ // performance tests showed that for rest_bits==2 it's better to use Rcr2_one twice instead of Rcr2(2,c)
580
+ Rcr2_one(c);
581
+ last_c = Rcr2_one(c);
582
+ }
583
+ else
584
+ {
585
+ last_c = Rcr2(rest_bits, c);
586
+ }
587
+
588
+ TTMATH_LOGC("UInt::Rcr", last_c)
589
+
590
+ return last_c;
591
+ }
592
+
593
+
594
+ /*!
595
+ this method moves all bits into the left side
596
+ (it returns value how many bits have been moved)
597
+ */
598
+ uint CompensationToLeft()
599
+ {
600
+ uint moving = 0;
601
+
602
+ // a - index a last word which is different from zero
603
+ sint a;
604
+ for(a=value_size-1 ; a>=0 && table[a]==0 ; --a);
605
+
606
+ if( a < 0 )
607
+ return moving; // all words in table have zero
608
+
609
+ if( a != value_size-1 )
610
+ {
611
+ moving += ( value_size-1 - a ) * TTMATH_BITS_PER_UINT;
612
+
613
+ // moving all words
614
+ sint i;
615
+ for(i=value_size-1 ; a>=0 ; --i, --a)
616
+ table[i] = table[a];
617
+
618
+ // setting the rest word to zero
619
+ for(; i>=0 ; --i)
620
+ table[i] = 0;
621
+ }
622
+
623
+ uint moving2 = FindLeadingBitInWord( table[value_size-1] );
624
+ // moving2 is different from -1 because the value table[value_size-1]
625
+ // is not zero
626
+
627
+ moving2 = TTMATH_BITS_PER_UINT - moving2 - 1;
628
+ Rcl(moving2);
629
+
630
+ TTMATH_LOG("UInt::CompensationToLeft")
631
+
632
+ return moving + moving2;
633
+ }
634
+
635
+
636
+ /*!
637
+ this method looks for the highest set bit
638
+
639
+ result:
640
+ - if 'this' is not zero:
641
+ return value - true,
642
+ 'table_id' - the index of a word <0..value_size-1>,
643
+ 'index' - the index of this set bit in the word <0..TTMATH_BITS_PER_UINT)
644
+
645
+ - if 'this' is zero:
646
+ return value - false,
647
+ both 'table_id' and 'index' are zero
648
+ */
649
+ bool FindLeadingBit(uint & table_id, uint & index) const
650
+ {
651
+ for(table_id=value_size-1 ; table_id!=0 && table[table_id]==0 ; --table_id);
652
+
653
+ if( table_id==0 && table[table_id]==0 )
654
+ {
655
+ // is zero
656
+ index = 0;
657
+
658
+ return false;
659
+ }
660
+
661
+ // table[table_id] is different from 0
662
+ index = FindLeadingBitInWord( table[table_id] );
663
+
664
+ return true;
665
+ }
666
+
667
+
668
+ /*!
669
+ this method looks for the smallest set bit
670
+
671
+ result:
672
+ - if 'this' is not zero:
673
+ return value - true,
674
+ 'table_id' - the index of a word <0..value_size-1>,
675
+ 'index' - the index of this set bit in the word <0..TTMATH_BITS_PER_UINT)
676
+
677
+ - if 'this' is zero:
678
+ return value - false,
679
+ both 'table_id' and 'index' are zero
680
+ */
681
+ bool FindLowestBit(uint & table_id, uint & index) const
682
+ {
683
+ for(table_id=0 ; table_id<value_size && table[table_id]==0 ; ++table_id);
684
+
685
+ if( table_id >= value_size )
686
+ {
687
+ // is zero
688
+ index = 0;
689
+ table_id = 0;
690
+
691
+ return false;
692
+ }
693
+
694
+ // table[table_id] is different from 0
695
+ index = FindLowestBitInWord( table[table_id] );
696
+
697
+ return true;
698
+ }
699
+
700
+
701
+ /*!
702
+ getting the 'bit_index' bit
703
+
704
+ bit_index bigger or equal zero
705
+ */
706
+ uint GetBit(uint bit_index) const
707
+ {
708
+ TTMATH_ASSERT( bit_index < value_size * TTMATH_BITS_PER_UINT )
709
+
710
+ uint index = bit_index / TTMATH_BITS_PER_UINT;
711
+ uint bit = bit_index % TTMATH_BITS_PER_UINT;
712
+
713
+ uint temp = table[index];
714
+ uint res = SetBitInWord(temp, bit);
715
+
716
+ return res;
717
+ }
718
+
719
+
720
+ /*!
721
+ setting the 'bit_index' bit
722
+ and returning the last state of the bit
723
+
724
+ bit_index bigger or equal zero
725
+ */
726
+ uint SetBit(uint bit_index)
727
+ {
728
+ TTMATH_ASSERT( bit_index < value_size * TTMATH_BITS_PER_UINT )
729
+
730
+ uint index = bit_index / TTMATH_BITS_PER_UINT;
731
+ uint bit = bit_index % TTMATH_BITS_PER_UINT;
732
+ uint res = SetBitInWord(table[index], bit);
733
+
734
+ TTMATH_LOG("UInt::SetBit")
735
+
736
+ return res;
737
+ }
738
+
739
+
740
+ /*!
741
+ this method performs a bitwise operation AND
742
+ */
743
+ void BitAnd(const UInt<value_size> & ss2)
744
+ {
745
+ for(uint x=0 ; x<value_size ; ++x)
746
+ table[x] &= ss2.table[x];
747
+
748
+ TTMATH_LOG("UInt::BitAnd")
749
+ }
750
+
751
+
752
+ /*!
753
+ this method performs a bitwise operation OR
754
+ */
755
+ void BitOr(const UInt<value_size> & ss2)
756
+ {
757
+ for(uint x=0 ; x<value_size ; ++x)
758
+ table[x] |= ss2.table[x];
759
+
760
+ TTMATH_LOG("UInt::BitOr")
761
+ }
762
+
763
+
764
+ /*!
765
+ this method performs a bitwise operation XOR
766
+ */
767
+ void BitXor(const UInt<value_size> & ss2)
768
+ {
769
+ for(uint x=0 ; x<value_size ; ++x)
770
+ table[x] ^= ss2.table[x];
771
+
772
+ TTMATH_LOG("UInt::BitXor")
773
+ }
774
+
775
+
776
+ /*!
777
+ this method performs a bitwise operation NOT
778
+ */
779
+ void BitNot()
780
+ {
781
+ for(uint x=0 ; x<value_size ; ++x)
782
+ table[x] = ~table[x];
783
+
784
+ TTMATH_LOG("UInt::BitNot")
785
+ }
786
+
787
+
788
+ /*!
789
+ this method performs a bitwise operation NOT but only
790
+ on the range of <0, leading_bit>
791
+
792
+ for example:
793
+ BitNot2(8) = BitNot2( 1000(bin) ) = 111(bin) = 7
794
+ */
795
+ void BitNot2()
796
+ {
797
+ uint table_id, index;
798
+
799
+ if( FindLeadingBit(table_id, index) )
800
+ {
801
+ for(uint x=0 ; x<table_id ; ++x)
802
+ table[x] = ~table[x];
803
+
804
+ uint mask = TTMATH_UINT_MAX_VALUE;
805
+ uint shift = TTMATH_BITS_PER_UINT - index - 1;
806
+
807
+ if(shift)
808
+ mask >>= shift;
809
+
810
+ table[table_id] ^= mask;
811
+ }
812
+ else
813
+ table[0] = 1;
814
+
815
+
816
+ TTMATH_LOG("UInt::BitNot2")
817
+ }
818
+
819
+
820
+
821
+ /*!
822
+ *
823
+ * Multiplication
824
+ *
825
+ *
826
+ */
827
+
828
+ public:
829
+
830
+ /*!
831
+ multiplication: this = this * ss2
832
+
833
+ it can return a carry
834
+ */
835
+ uint MulInt(uint ss2)
836
+ {
837
+ uint r1, r2, x1;
838
+ uint c = 0;
839
+
840
+ UInt<value_size> u(*this);
841
+ SetZero();
842
+
843
+ if( ss2 == 0 )
844
+ {
845
+ TTMATH_LOGC("UInt::MulInt(uint)", 0)
846
+ return 0;
847
+ }
848
+
849
+ for(x1=0 ; x1<value_size-1 ; ++x1)
850
+ {
851
+ MulTwoWords(u.table[x1], ss2, &r2, &r1);
852
+ c += AddTwoInts(r2,r1,x1);
853
+ }
854
+
855
+ // x1 = value_size-1 (last word)
856
+ MulTwoWords(u.table[x1], ss2, &r2, &r1);
857
+ c += (r2!=0) ? 1 : 0;
858
+ c += AddInt(r1, x1);
859
+
860
+ TTMATH_LOGC("UInt::MulInt(uint)", c)
861
+
862
+ return (c==0)? 0 : 1;
863
+ }
864
+
865
+
866
+ /*!
867
+ multiplication: result = this * ss2
868
+
869
+ we're using this method only when result_size is greater than value_size
870
+ if so there will not be a carry
871
+ */
872
+ template<uint result_size>
873
+ void MulInt(uint ss2, UInt<result_size> & result) const
874
+ {
875
+ TTMATH_ASSERT( result_size > value_size )
876
+
877
+ uint r2,r1;
878
+ uint x1size=value_size;
879
+ uint x1start=0;
880
+
881
+ result.SetZero();
882
+
883
+ if( ss2 == 0 )
884
+ {
885
+ TTMATH_VECTOR_LOG("UInt::MulInt(uint, UInt<>)", result.table, result_size)
886
+ return;
887
+ }
888
+
889
+ if( value_size > 2 )
890
+ {
891
+ // if the value_size is smaller than or equal to 2
892
+ // there is no sense to set x1size and x1start to another values
893
+
894
+ for(x1size=value_size ; x1size>0 && table[x1size-1]==0 ; --x1size);
895
+
896
+ if( x1size == 0 )
897
+ {
898
+ TTMATH_VECTOR_LOG("UInt::MulInt(uint, UInt<>)", result.table, result_size)
899
+ return;
900
+ }
901
+
902
+ for(x1start=0 ; x1start<x1size && table[x1start]==0 ; ++x1start);
903
+ }
904
+
905
+ for(uint x1=x1start ; x1<x1size ; ++x1)
906
+ {
907
+ MulTwoWords(table[x1], ss2, &r2, &r1 );
908
+ result.AddTwoInts(r2,r1,x1);
909
+ }
910
+
911
+ TTMATH_VECTOR_LOG("UInt::MulInt(uint, UInt<>)", result.table, result_size)
912
+
913
+ return;
914
+ }
915
+
916
+
917
+
918
+ /*!
919
+ the multiplication 'this' = 'this' * ss2
920
+
921
+ algorithm: 100 - means automatically choose the fastest algorithm
922
+ */
923
+ uint Mul(const UInt<value_size> & ss2, uint algorithm = 100)
924
+ {
925
+ switch( algorithm )
926
+ {
927
+ case 1:
928
+ return Mul1(ss2);
929
+
930
+ case 2:
931
+ return Mul2(ss2);
932
+
933
+ case 3:
934
+ return Mul3(ss2);
935
+
936
+ case 100:
937
+ default:
938
+ return MulFastest(ss2);
939
+ }
940
+ }
941
+
942
+
943
+ /*!
944
+ the multiplication 'result' = 'this' * ss2
945
+
946
+ since the 'result' is twice bigger than 'this' and 'ss2'
947
+ this method never returns a carry
948
+
949
+ algorithm: 100 - means automatically choose the fastest algorithm
950
+ */
951
+ void MulBig(const UInt<value_size> & ss2,
952
+ UInt<value_size*2> & result,
953
+ uint algorithm = 100)
954
+ {
955
+ switch( algorithm )
956
+ {
957
+ case 1:
958
+ Mul1Big(ss2, result);
959
+ break;
960
+
961
+ case 2:
962
+ Mul2Big(ss2, result);
963
+ break;
964
+
965
+ case 3:
966
+ Mul3Big(ss2, result);
967
+ break;
968
+
969
+ case 100:
970
+ default:
971
+ MulFastestBig(ss2, result);
972
+ }
973
+ }
974
+
975
+
976
+
977
+ /*!
978
+ the first version of the multiplication algorithm
979
+ */
980
+
981
+ private:
982
+
983
+ /*!
984
+ multiplication: this = this * ss2
985
+
986
+ it returns carry if it has been
987
+ */
988
+ uint Mul1Ref(const UInt<value_size> & ss2)
989
+ {
990
+ TTMATH_REFERENCE_ASSERT( ss2 )
991
+
992
+ UInt<value_size> ss1( *this );
993
+ SetZero();
994
+
995
+ for(uint i=0; i < value_size*TTMATH_BITS_PER_UINT ; ++i)
996
+ {
997
+ if( Add(*this) )
998
+ {
999
+ TTMATH_LOGC("UInt::Mul1", 1)
1000
+ return 1;
1001
+ }
1002
+
1003
+ if( ss1.Rcl(1) )
1004
+ if( Add(ss2) )
1005
+ {
1006
+ TTMATH_LOGC("UInt::Mul1", 1)
1007
+ return 1;
1008
+ }
1009
+ }
1010
+
1011
+ TTMATH_LOGC("UInt::Mul1", 0)
1012
+
1013
+ return 0;
1014
+ }
1015
+
1016
+
1017
+ public:
1018
+
1019
+ /*!
1020
+ multiplication: this = this * ss2
1021
+ can return carry
1022
+ */
1023
+ uint Mul1(const UInt<value_size> & ss2)
1024
+ {
1025
+ if( this == &ss2 )
1026
+ {
1027
+ UInt<value_size> copy_ss2(ss2);
1028
+ return Mul1Ref(copy_ss2);
1029
+ }
1030
+ else
1031
+ {
1032
+ return Mul1Ref(ss2);
1033
+ }
1034
+ }
1035
+
1036
+
1037
+ /*!
1038
+ multiplication: result = this * ss2
1039
+
1040
+ result is twice bigger than 'this' and 'ss2'
1041
+ this method never returns carry
1042
+ */
1043
+ void Mul1Big(const UInt<value_size> & ss2_, UInt<value_size*2> & result)
1044
+ {
1045
+ UInt<value_size*2> ss2;
1046
+ uint i;
1047
+
1048
+ // copying *this into result and ss2_ into ss2
1049
+ for(i=0 ; i<value_size ; ++i)
1050
+ {
1051
+ result.table[i] = table[i];
1052
+ ss2.table[i] = ss2_.table[i];
1053
+ }
1054
+
1055
+ // cleaning the highest bytes in result and ss2
1056
+ for( ; i < value_size*2 ; ++i)
1057
+ {
1058
+ result.table[i] = 0;
1059
+ ss2.table[i] = 0;
1060
+ }
1061
+
1062
+ // multiply
1063
+ // (there will not be a carry)
1064
+ result.Mul1( ss2 );
1065
+
1066
+ TTMATH_LOG("UInt::Mul1Big")
1067
+ }
1068
+
1069
+
1070
+
1071
+ /*!
1072
+ the second version of the multiplication algorithm
1073
+
1074
+ this algorithm is similar to the 'schoolbook method' which is done by hand
1075
+ */
1076
+
1077
+ /*!
1078
+ multiplication: this = this * ss2
1079
+
1080
+ it returns carry if it has been
1081
+ */
1082
+ uint Mul2(const UInt<value_size> & ss2)
1083
+ {
1084
+ UInt<value_size*2> result;
1085
+ uint i, c = 0;
1086
+
1087
+ Mul2Big(ss2, result);
1088
+
1089
+ // copying result
1090
+ for(i=0 ; i<value_size ; ++i)
1091
+ table[i] = result.table[i];
1092
+
1093
+ // testing carry
1094
+ for( ; i<value_size*2 ; ++i)
1095
+ if( result.table[i] != 0 )
1096
+ {
1097
+ c = 1;
1098
+ break;
1099
+ }
1100
+
1101
+ TTMATH_LOGC("UInt::Mul2", c)
1102
+
1103
+ return c;
1104
+ }
1105
+
1106
+
1107
+ /*!
1108
+ multiplication: result = this * ss2
1109
+
1110
+ result is twice bigger than this and ss2
1111
+ this method never returns carry
1112
+ */
1113
+ void Mul2Big(const UInt<value_size> & ss2, UInt<value_size*2> & result)
1114
+ {
1115
+ Mul2Big2<value_size>(table, ss2.table, result);
1116
+
1117
+ TTMATH_LOG("UInt::Mul2Big")
1118
+ }
1119
+
1120
+
1121
+ private:
1122
+
1123
+ /*!
1124
+ an auxiliary method for calculating the multiplication
1125
+
1126
+ arguments we're taking as pointers (this is to improve the Mul3Big2()- avoiding
1127
+ unnecessary copying objects), the result should be taken as a pointer too,
1128
+ but at the moment there is no method AddTwoInts() which can operate on pointers
1129
+ */
1130
+ template<uint ss_size>
1131
+ void Mul2Big2(const uint * ss1, const uint * ss2, UInt<ss_size*2> & result)
1132
+ {
1133
+ uint x1size = ss_size, x2size = ss_size;
1134
+ uint x1start = 0, x2start = 0;
1135
+
1136
+ if( ss_size > 2 )
1137
+ {
1138
+ // if the ss_size is smaller than or equal to 2
1139
+ // there is no sense to set x1size (and others) to another values
1140
+
1141
+ for(x1size=ss_size ; x1size>0 && ss1[x1size-1]==0 ; --x1size);
1142
+ for(x2size=ss_size ; x2size>0 && ss2[x2size-1]==0 ; --x2size);
1143
+
1144
+ for(x1start=0 ; x1start<x1size && ss1[x1start]==0 ; ++x1start);
1145
+ for(x2start=0 ; x2start<x2size && ss2[x2start]==0 ; ++x2start);
1146
+ }
1147
+
1148
+ Mul2Big3<ss_size>(ss1, ss2, result, x1start, x1size, x2start, x2size);
1149
+ }
1150
+
1151
+
1152
+
1153
+ /*!
1154
+ an auxiliary method for calculating the multiplication
1155
+ */
1156
+ template<uint ss_size>
1157
+ void Mul2Big3(const uint * ss1, const uint * ss2, UInt<ss_size*2> & result, uint x1start, uint x1size, uint x2start, uint x2size)
1158
+ {
1159
+ uint r2, r1;
1160
+
1161
+ result.SetZero();
1162
+
1163
+ if( x1size==0 || x2size==0 )
1164
+ return;
1165
+
1166
+ for(uint x1=x1start ; x1<x1size ; ++x1)
1167
+ {
1168
+ for(uint x2=x2start ; x2<x2size ; ++x2)
1169
+ {
1170
+ MulTwoWords(ss1[x1], ss2[x2], &r2, &r1);
1171
+ result.AddTwoInts(r2, r1, x2+x1);
1172
+ // here will never be a carry
1173
+ }
1174
+ }
1175
+ }
1176
+
1177
+
1178
+ public:
1179
+
1180
+
1181
+ /*!
1182
+ multiplication: this = this * ss2
1183
+
1184
+ This is Karatsuba Multiplication algorithm, we're using it when value_size is greater than
1185
+ or equal to TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE macro (defined in ttmathuint.h).
1186
+ If value_size is smaller then we're using Mul2Big() instead.
1187
+
1188
+ Karatsuba multiplication:
1189
+ Assume we have:
1190
+
1191
+ this = x = x1*B^m + x0
1192
+ ss2 = y = y1*B^m + y0
1193
+
1194
+ where x0 and y0 are less than B^m
1195
+ the product from multiplication we can show as:
1196
+ x*y = (x1*B^m + x0)(y1*B^m + y0) = z2*B^(2m) + z1*B^m + z0
1197
+ where
1198
+
1199
+ z2 = x1*y1
1200
+ z1 = x1*y0 + x0*y1
1201
+ z0 = x0*y0
1202
+
1203
+ this is standard schoolbook algorithm with O(n^2), Karatsuba observed that z1 can be given in other form:
1204
+
1205
+ z1 = (x1 + x0)*(y1 + y0) - z2 - z0 / z1 = (x1*y1 + x1*y0 + x0*y1 + x0*y0) - x1*y1 - x0*y0 = x1*y0 + x0*y1 /
1206
+
1207
+ and to calculate the multiplication we need only three multiplications (with some additions and subtractions)
1208
+
1209
+ Our objects 'this' and 'ss2' we divide into two parts and by using recurrence we calculate the multiplication.
1210
+ Karatsuba multiplication has O( n^(ln(3)/ln(2)) )
1211
+ */
1212
+ uint Mul3(const UInt<value_size> & ss2)
1213
+ {
1214
+ UInt<value_size*2> result;
1215
+ uint i, c = 0;
1216
+
1217
+ Mul3Big(ss2, result);
1218
+
1219
+ // copying result
1220
+ for(i=0 ; i<value_size ; ++i)
1221
+ table[i] = result.table[i];
1222
+
1223
+ // testing carry
1224
+ for( ; i<value_size*2 ; ++i)
1225
+ if( result.table[i] != 0 )
1226
+ {
1227
+ c = 1;
1228
+ break;
1229
+ }
1230
+
1231
+ TTMATH_LOGC("UInt::Mul3", c)
1232
+
1233
+ return c;
1234
+ }
1235
+
1236
+
1237
+
1238
+ /*!
1239
+ multiplication: result = this * ss2
1240
+
1241
+ result is twice bigger than this and ss2,
1242
+ this method never returns carry,
1243
+ (Karatsuba multiplication)
1244
+ */
1245
+ void Mul3Big(const UInt<value_size> & ss2, UInt<value_size*2> & result)
1246
+ {
1247
+ Mul3Big2<value_size>(table, ss2.table, result.table);
1248
+
1249
+ TTMATH_LOG("UInt::Mul3Big")
1250
+ }
1251
+
1252
+
1253
+
1254
+ private:
1255
+
1256
+ /*!
1257
+ an auxiliary method for calculating the Karatsuba multiplication
1258
+
1259
+ result_size is equal ss_size*2
1260
+ */
1261
+ template<uint ss_size>
1262
+ void Mul3Big2(const uint * ss1, const uint * ss2, uint * result)
1263
+ {
1264
+ const uint * x1, * x0, * y1, * y0;
1265
+
1266
+
1267
+ if( ss_size>1 && ss_size<TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE )
1268
+ {
1269
+ UInt<ss_size*2> res;
1270
+ Mul2Big2<ss_size>(ss1, ss2, res);
1271
+
1272
+ #ifdef __clang__
1273
+ #pragma clang diagnostic push
1274
+ #pragma clang diagnostic ignored "-Wtautological-compare"
1275
+ #endif
1276
+
1277
+ for(uint i=0 ; i<ss_size*2 ; ++i)
1278
+ result[i] = res.table[i];
1279
+
1280
+ #ifdef __clang__
1281
+ #pragma clang diagnostic pop
1282
+ #endif
1283
+
1284
+ return;
1285
+ }
1286
+ else
1287
+ if( ss_size == 1 )
1288
+ {
1289
+ return MulTwoWords(*ss1, *ss2, &result[1], &result[0]);
1290
+ }
1291
+
1292
+
1293
+ if( (ss_size & 1) == 1 )
1294
+ {
1295
+ // ss_size is odd
1296
+ x0 = ss1;
1297
+ y0 = ss2;
1298
+ x1 = ss1 + ss_size / 2 + 1;
1299
+ y1 = ss2 + ss_size / 2 + 1;
1300
+
1301
+ // the second vectors (x1 and y1) are smaller about one from the first ones (x0 and y0)
1302
+ Mul3Big3<ss_size/2 + 1, ss_size/2, ss_size*2>(x1, x0, y1, y0, result);
1303
+ }
1304
+ else
1305
+ {
1306
+ // ss_size is even
1307
+ x0 = ss1;
1308
+ y0 = ss2;
1309
+ x1 = ss1 + ss_size / 2;
1310
+ y1 = ss2 + ss_size / 2;
1311
+
1312
+ // all four vectors (x0 x1 y0 y1) are equal in size
1313
+ Mul3Big3<ss_size/2, ss_size/2, ss_size*2>(x1, x0, y1, y0, result);
1314
+ }
1315
+ }
1316
+
1317
+
1318
+
1319
+ #ifdef _MSC_VER
1320
+ #pragma warning (disable : 4717)
1321
+ //warning C4717: recursive on all control paths, function will cause runtime stack overflow
1322
+ //we have the stop point in Mul3Big2() method
1323
+ #endif
1324
+
1325
+ #if defined(__GNUC__) && !defined(__clang__)
1326
+ #pragma GCC diagnostic push
1327
+ #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
1328
+ #endif
1329
+
1330
+
1331
+ /*!
1332
+ an auxiliary method for calculating the Karatsuba multiplication
1333
+
1334
+ x = x1*B^m + x0
1335
+ y = y1*B^m + y0
1336
+
1337
+ first_size - is the size of vectors: x0 and y0
1338
+ second_size - is the size of vectors: x1 and y1 (can be either equal first_size or smaller about one from first_size)
1339
+
1340
+ x*y = (x1*B^m + x0)(y1*B^m + y0) = z2*B^(2m) + z1*B^m + z0
1341
+ where
1342
+ z0 = x0*y0
1343
+ z2 = x1*y1
1344
+ z1 = (x1 + x0)*(y1 + y0) - z2 - z0
1345
+ */
1346
+ template<uint first_size, uint second_size, uint result_size>
1347
+ uint Mul3Big3(const uint * x1, const uint * x0, const uint * y1, const uint * y0, uint * result)
1348
+ {
1349
+ uint i, c, xc, yc;
1350
+
1351
+ UInt<first_size> temp, temp2;
1352
+ UInt<first_size*3> z1;
1353
+
1354
+ // z0 and z2 we store directly in the result (we don't use any temporary variables)
1355
+ Mul3Big2<first_size>(x0, y0, result); // z0
1356
+ Mul3Big2<second_size>(x1, y1, result+first_size*2); // z2
1357
+
1358
+ // now we calculate z1
1359
+ // temp = (x0 + x1)
1360
+ // temp2 = (y0 + y1)
1361
+ // we're using temp and temp2 with UInt<first_size>, although there can be a carry but
1362
+ // we simple remember it in xc and yc (xc and yc can be either 0 or 1),
1363
+ // and (x0 + x1)*(y0 + y1) we calculate in this way (schoolbook algorithm):
1364
+ //
1365
+ // xc | temp
1366
+ // yc | temp2
1367
+ // --------------------
1368
+ // (temp * temp2)
1369
+ // xc*temp2 |
1370
+ // yc*temp |
1371
+ // xc*yc |
1372
+ // ---------- z1 --------
1373
+ //
1374
+ // and the result is never larger in size than 3*first_size
1375
+
1376
+ xc = AddVector(x0, x1, first_size, second_size, temp.table);
1377
+ yc = AddVector(y0, y1, first_size, second_size, temp2.table);
1378
+
1379
+ Mul3Big2<first_size>(temp.table, temp2.table, z1.table);
1380
+
1381
+ #ifdef __clang__
1382
+ #pragma clang diagnostic push
1383
+ #pragma clang diagnostic ignored "-Wtautological-compare"
1384
+ #endif
1385
+
1386
+ // clearing the rest of z1
1387
+ for(i=first_size*2 ; i<first_size*3 ; ++i)
1388
+ z1.table[i] = 0;
1389
+
1390
+ #ifdef __clang__
1391
+ #pragma clang diagnostic pop
1392
+ #endif
1393
+
1394
+ if( xc )
1395
+ {
1396
+ c = AddVector(z1.table+first_size, temp2.table, first_size*3-first_size, first_size, z1.table+first_size);
1397
+ TTMATH_ASSERT( c==0 )
1398
+ }
1399
+
1400
+ if( yc )
1401
+ {
1402
+ c = AddVector(z1.table+first_size, temp.table, first_size*3-first_size, first_size, z1.table+first_size);
1403
+ TTMATH_ASSERT( c==0 )
1404
+ }
1405
+
1406
+
1407
+ if( xc && yc )
1408
+ {
1409
+ #ifdef __clang__
1410
+ #pragma clang diagnostic push
1411
+ #pragma clang diagnostic ignored "-Wtautological-compare"
1412
+ #endif
1413
+
1414
+ for( i=first_size*2 ; i<first_size*3 ; ++i )
1415
+ if( ++z1.table[i] != 0 )
1416
+ break; // break if there was no carry
1417
+
1418
+ #ifdef __clang__
1419
+ #pragma clang diagnostic pop
1420
+ #endif
1421
+ }
1422
+
1423
+ // z1 = z1 - z2
1424
+ c = SubVector(z1.table, result+first_size*2, first_size*3, second_size*2, z1.table);
1425
+ TTMATH_ASSERT(c==0)
1426
+
1427
+ // z1 = z1 - z0
1428
+ c = SubVector(z1.table, result, first_size*3, first_size*2, z1.table);
1429
+ TTMATH_ASSERT(c==0)
1430
+
1431
+ // here we've calculated the z1
1432
+ // now we're adding it to the result
1433
+
1434
+ if( first_size > second_size )
1435
+ {
1436
+ uint z1_size = result_size - first_size;
1437
+ TTMATH_ASSERT( z1_size <= first_size*3 )
1438
+
1439
+ #ifdef __clang__
1440
+ #pragma clang diagnostic push
1441
+ #pragma clang diagnostic ignored "-Wtautological-compare"
1442
+ #endif
1443
+
1444
+ for(i=z1_size ; i<first_size*3 ; ++i)
1445
+ {
1446
+ TTMATH_ASSERT( z1.table[i] == 0 )
1447
+ }
1448
+
1449
+ #ifdef __clang__
1450
+ #pragma clang diagnostic pop
1451
+ #endif
1452
+
1453
+ c = AddVector(result+first_size, z1.table, result_size-first_size, z1_size, result+first_size);
1454
+ TTMATH_ASSERT(c==0)
1455
+ }
1456
+ else
1457
+ {
1458
+ c = AddVector(result+first_size, z1.table, result_size-first_size, first_size*3, result+first_size);
1459
+ TTMATH_ASSERT(c==0)
1460
+ }
1461
+ return c;
1462
+ }
1463
+
1464
+
1465
+ #if defined(__GNUC__) && !defined(__clang__)
1466
+ #pragma GCC diagnostic pop
1467
+ #endif
1468
+
1469
+ #ifdef _MSC_VER
1470
+ #pragma warning (default : 4717)
1471
+ #endif
1472
+
1473
+
1474
+ public:
1475
+
1476
+
1477
+ /*!
1478
+ multiplication this = this * ss2
1479
+ */
1480
+ uint MulFastest(const UInt<value_size> & ss2)
1481
+ {
1482
+ UInt<value_size*2> result;
1483
+ uint i, c = 0;
1484
+
1485
+ MulFastestBig(ss2, result);
1486
+
1487
+ // copying result
1488
+ for(i=0 ; i<value_size ; ++i)
1489
+ table[i] = result.table[i];
1490
+
1491
+ // testing carry
1492
+ for( ; i<value_size*2 ; ++i)
1493
+ if( result.table[i] != 0 )
1494
+ {
1495
+ c = 1;
1496
+ break;
1497
+ }
1498
+
1499
+ TTMATH_LOGC("UInt::MulFastest", c)
1500
+
1501
+ return c;
1502
+ }
1503
+
1504
+
1505
+ /*!
1506
+ multiplication result = this * ss2
1507
+
1508
+ this method is trying to select the fastest algorithm
1509
+ (in the future this method can be improved)
1510
+ */
1511
+ void MulFastestBig(const UInt<value_size> & ss2, UInt<value_size*2> & result)
1512
+ {
1513
+ if( value_size < TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE )
1514
+ {
1515
+ Mul2Big(ss2, result);
1516
+ return;
1517
+ }
1518
+
1519
+ uint x1size = value_size, x2size = value_size;
1520
+ uint x1start = 0, x2start = 0;
1521
+
1522
+ for(x1size=value_size ; x1size>0 && table[x1size-1]==0 ; --x1size);
1523
+ for(x2size=value_size ; x2size>0 && ss2.table[x2size-1]==0 ; --x2size);
1524
+
1525
+ if( x1size==0 || x2size==0 )
1526
+ {
1527
+ // either 'this' or 'ss2' is equal zero - the result is zero too
1528
+ result.SetZero();
1529
+ return;
1530
+ }
1531
+
1532
+ for(x1start=0 ; x1start<x1size && table[x1start]==0 ; ++x1start);
1533
+ for(x2start=0 ; x2start<x2size && ss2.table[x2start]==0 ; ++x2start);
1534
+
1535
+ uint distancex1 = x1size - x1start;
1536
+ uint distancex2 = x2size - x2start;
1537
+
1538
+ if( distancex1 < 3 || distancex2 < 3 )
1539
+ {
1540
+ // either 'this' or 'ss2' have only 2 (or 1) items different from zero (side by side)
1541
+ // (this condition in the future can be improved)
1542
+ Mul2Big3<value_size>(table, ss2.table, result, x1start, x1size, x2start, x2size);
1543
+ return;
1544
+ }
1545
+
1546
+
1547
+ // Karatsuba multiplication
1548
+ Mul3Big(ss2, result);
1549
+
1550
+ TTMATH_LOG("UInt::MulFastestBig")
1551
+ }
1552
+
1553
+
1554
+ /*!
1555
+ *
1556
+ * Division
1557
+ *
1558
+ *
1559
+ */
1560
+
1561
+ public:
1562
+
1563
+
1564
+ /*!
1565
+ division by one unsigned word
1566
+
1567
+ returns 1 when divisor is zero
1568
+ */
1569
+ uint DivInt(uint divisor, uint * remainder = 0)
1570
+ {
1571
+ if( divisor == 0 )
1572
+ {
1573
+ if( remainder )
1574
+ *remainder = 0; // this is for convenience, without it the compiler can report that 'remainder' is uninitialized
1575
+
1576
+ TTMATH_LOG("UInt::DivInt")
1577
+
1578
+ return 1;
1579
+ }
1580
+
1581
+ if( divisor == 1 )
1582
+ {
1583
+ if( remainder )
1584
+ *remainder = 0;
1585
+
1586
+ TTMATH_LOG("UInt::DivInt")
1587
+
1588
+ return 0;
1589
+ }
1590
+
1591
+ UInt<value_size> dividend(*this);
1592
+ SetZero();
1593
+
1594
+ sint i; // i must be with a sign
1595
+ uint r = 0;
1596
+
1597
+ // we're looking for the last word in ss1
1598
+ for(i=value_size-1 ; i>0 && dividend.table[i]==0 ; --i);
1599
+
1600
+ for( ; i>=0 ; --i)
1601
+ DivTwoWords(r, dividend.table[i], divisor, &table[i], &r);
1602
+
1603
+ if( remainder )
1604
+ *remainder = r;
1605
+
1606
+ TTMATH_LOG("UInt::DivInt")
1607
+
1608
+ return 0;
1609
+ }
1610
+
1611
+ uint DivInt(uint divisor, uint & remainder)
1612
+ {
1613
+ return DivInt(divisor, &remainder);
1614
+ }
1615
+
1616
+
1617
+
1618
+ /*!
1619
+ division this = this / ss2
1620
+
1621
+ return values:
1622
+ - 0 - ok
1623
+ - 1 - division by zero
1624
+ - 'this' will be the quotient
1625
+ - 'remainder' - remainder
1626
+ */
1627
+ uint Div( const UInt<value_size> & divisor,
1628
+ UInt<value_size> * remainder = 0,
1629
+ uint algorithm = 3)
1630
+ {
1631
+ switch( algorithm )
1632
+ {
1633
+ case 1:
1634
+ return Div1(divisor, remainder);
1635
+
1636
+ case 2:
1637
+ return Div2(divisor, remainder);
1638
+
1639
+ case 3:
1640
+ default:
1641
+ return Div3(divisor, remainder);
1642
+ }
1643
+ }
1644
+
1645
+ uint Div(const UInt<value_size> & divisor, UInt<value_size> & remainder, uint algorithm = 3)
1646
+ {
1647
+ return Div(divisor, &remainder, algorithm);
1648
+ }
1649
+
1650
+
1651
+
1652
+ private:
1653
+
1654
+ /*!
1655
+ return values:
1656
+ - 0 - none has to be done
1657
+ - 1 - division by zero
1658
+ - 2 - division should be made
1659
+ */
1660
+ uint Div_StandardTest( const UInt<value_size> & v,
1661
+ uint & m, uint & n,
1662
+ UInt<value_size> * remainder = 0)
1663
+ {
1664
+ switch( Div_CalculatingSize(v, m, n) )
1665
+ {
1666
+ case 4: // 'this' is equal v
1667
+ if( remainder )
1668
+ remainder->SetZero();
1669
+
1670
+ SetOne();
1671
+ TTMATH_LOG("UInt::Div_StandardTest")
1672
+ return 0;
1673
+
1674
+ case 3: // 'this' is smaller than v
1675
+ if( remainder )
1676
+ *remainder = *this;
1677
+
1678
+ SetZero();
1679
+ TTMATH_LOG("UInt::Div_StandardTest")
1680
+ return 0;
1681
+
1682
+ case 2: // 'this' is zero
1683
+ if( remainder )
1684
+ remainder->SetZero();
1685
+
1686
+ SetZero();
1687
+ TTMATH_LOG("UInt::Div_StandardTest")
1688
+ return 0;
1689
+
1690
+ case 1: // v is zero
1691
+ TTMATH_LOG("UInt::Div_StandardTest")
1692
+ return 1;
1693
+ }
1694
+
1695
+ TTMATH_LOG("UInt::Div_StandardTest")
1696
+
1697
+ return 2;
1698
+ }
1699
+
1700
+
1701
+
1702
+ /*!
1703
+ return values:
1704
+ - 0 - ok
1705
+ - 'm' - is the index (from 0) of last non-zero word in table ('this')
1706
+ - 'n' - is the index (from 0) of last non-zero word in v.table
1707
+ - 1 - v is zero
1708
+ - 2 - 'this' is zero
1709
+ - 3 - 'this' is smaller than v
1710
+ - 4 - 'this' is equal v
1711
+
1712
+ if the return value is different than zero the 'm' and 'n' are undefined
1713
+ */
1714
+ uint Div_CalculatingSize(const UInt<value_size> & v, uint & m, uint & n)
1715
+ {
1716
+ m = n = value_size-1;
1717
+
1718
+ for( ; n!=0 && v.table[n]==0 ; --n);
1719
+
1720
+ if( n==0 && v.table[n]==0 )
1721
+ return 1;
1722
+
1723
+ for( ; m!=0 && table[m]==0 ; --m);
1724
+
1725
+ if( m==0 && table[m]==0 )
1726
+ return 2;
1727
+
1728
+ if( m < n )
1729
+ return 3;
1730
+ else
1731
+ if( m == n )
1732
+ {
1733
+ uint i;
1734
+ for(i = n ; i!=0 && table[i]==v.table[i] ; --i);
1735
+
1736
+ if( table[i] < v.table[i] )
1737
+ return 3;
1738
+ else
1739
+ if (table[i] == v.table[i] )
1740
+ return 4;
1741
+ }
1742
+
1743
+ return 0;
1744
+ }
1745
+
1746
+
1747
+ public:
1748
+
1749
+ /*!
1750
+ the first division algorithm
1751
+ (radix 2)
1752
+ */
1753
+ uint Div1(const UInt<value_size> & divisor, UInt<value_size> * remainder = 0)
1754
+ {
1755
+ uint m,n, test;
1756
+
1757
+ test = Div_StandardTest(divisor, m, n, remainder);
1758
+ if( test < 2 )
1759
+ return test;
1760
+
1761
+ if( !remainder )
1762
+ {
1763
+ UInt<value_size> rem;
1764
+
1765
+ return Div1_Calculate(divisor, rem);
1766
+ }
1767
+
1768
+ return Div1_Calculate(divisor, *remainder);
1769
+ }
1770
+
1771
+
1772
+ /*!
1773
+ the first division algorithm
1774
+ (radix 2)
1775
+ */
1776
+ uint Div1(const UInt<value_size> & divisor, UInt<value_size> & remainder)
1777
+ {
1778
+ return Div1(divisor, &remainder);
1779
+ }
1780
+
1781
+
1782
+ private:
1783
+
1784
+ uint Div1_Calculate(const UInt<value_size> & divisor, UInt<value_size> & rest)
1785
+ {
1786
+ if( this == &divisor )
1787
+ {
1788
+ UInt<value_size> divisor_copy(divisor);
1789
+ return Div1_CalculateRef(divisor_copy, rest);
1790
+ }
1791
+ else
1792
+ {
1793
+ return Div1_CalculateRef(divisor, rest);
1794
+ }
1795
+ }
1796
+
1797
+
1798
+ uint Div1_CalculateRef(const UInt<value_size> & divisor, UInt<value_size> & rest)
1799
+ {
1800
+ TTMATH_REFERENCE_ASSERT( divisor )
1801
+
1802
+ sint loop;
1803
+ sint c;
1804
+
1805
+ rest.SetZero();
1806
+ loop = value_size * TTMATH_BITS_PER_UINT;
1807
+ c = 0;
1808
+
1809
+
1810
+ div_a:
1811
+ c = Rcl(1, c);
1812
+ c = rest.Add(rest,c);
1813
+ c = rest.Sub(divisor,c);
1814
+
1815
+ c = !c;
1816
+
1817
+ if(!c)
1818
+ goto div_d;
1819
+
1820
+
1821
+ div_b:
1822
+ --loop;
1823
+ if(loop)
1824
+ goto div_a;
1825
+
1826
+ c = Rcl(1, c);
1827
+ TTMATH_LOG("UInt::Div1_Calculate")
1828
+ return 0;
1829
+
1830
+
1831
+ div_c:
1832
+ c = Rcl(1, c);
1833
+ c = rest.Add(rest,c);
1834
+ c = rest.Add(divisor);
1835
+
1836
+ if(c)
1837
+ goto div_b;
1838
+
1839
+
1840
+ div_d:
1841
+ --loop;
1842
+ if(loop)
1843
+ goto div_c;
1844
+
1845
+ c = Rcl(1, c);
1846
+ c = rest.Add(divisor);
1847
+
1848
+ TTMATH_LOG("UInt::Div1_Calculate")
1849
+
1850
+ return 0;
1851
+ }
1852
+
1853
+
1854
+ public:
1855
+
1856
+ /*!
1857
+ the second division algorithm
1858
+
1859
+ return values:
1860
+ - 0 - ok
1861
+ - 1 - division by zero
1862
+ */
1863
+ uint Div2(const UInt<value_size> & divisor, UInt<value_size> * remainder = 0)
1864
+ {
1865
+ if( this == &divisor )
1866
+ {
1867
+ UInt<value_size> divisor_copy(divisor);
1868
+ return Div2Ref(divisor_copy, remainder);
1869
+ }
1870
+ else
1871
+ {
1872
+ return Div2Ref(divisor, remainder);
1873
+ }
1874
+ }
1875
+
1876
+
1877
+ /*!
1878
+ the second division algorithm
1879
+
1880
+ return values:
1881
+ - 0 - ok
1882
+ - 1 - division by zero
1883
+ */
1884
+ uint Div2(const UInt<value_size> & divisor, UInt<value_size> & remainder)
1885
+ {
1886
+ return Div2(divisor, &remainder);
1887
+ }
1888
+
1889
+
1890
+ private:
1891
+
1892
+ /*!
1893
+ the second division algorithm
1894
+
1895
+ return values:
1896
+ - 0 - ok
1897
+ - 1 - division by zero
1898
+ */
1899
+ uint Div2Ref(const UInt<value_size> & divisor, UInt<value_size> * remainder = 0)
1900
+ {
1901
+ uint bits_diff;
1902
+ uint status = Div2_Calculate(divisor, remainder, bits_diff);
1903
+ if( status < 2 )
1904
+ return status;
1905
+
1906
+ if( CmpBiggerEqual(divisor) )
1907
+ {
1908
+ Div2(divisor, remainder);
1909
+ SetBit(bits_diff);
1910
+ }
1911
+ else
1912
+ {
1913
+ if( remainder )
1914
+ *remainder = *this;
1915
+
1916
+ SetZero();
1917
+ SetBit(bits_diff);
1918
+ }
1919
+
1920
+ TTMATH_LOG("UInt::Div2")
1921
+
1922
+ return 0;
1923
+ }
1924
+
1925
+
1926
+ /*!
1927
+ return values:
1928
+ - 0 - we've calculated the division
1929
+ - 1 - division by zero
1930
+ - 2 - we have to still calculate
1931
+
1932
+ */
1933
+ uint Div2_Calculate(const UInt<value_size> & divisor, UInt<value_size> * remainder,
1934
+ uint & bits_diff)
1935
+ {
1936
+ uint table_id, index;
1937
+ uint divisor_table_id, divisor_index;
1938
+
1939
+ uint status = Div2_FindLeadingBitsAndCheck( divisor, remainder,
1940
+ table_id, index,
1941
+ divisor_table_id, divisor_index);
1942
+
1943
+ if( status < 2 )
1944
+ {
1945
+ TTMATH_LOG("UInt::Div2_Calculate")
1946
+ return status;
1947
+ }
1948
+
1949
+ // here we know that 'this' is greater than divisor
1950
+ // then 'index' is greater or equal 'divisor_index'
1951
+ bits_diff = index - divisor_index;
1952
+
1953
+ UInt<value_size> divisor_copy(divisor);
1954
+ divisor_copy.Rcl(bits_diff, 0);
1955
+
1956
+ if( CmpSmaller(divisor_copy, table_id) )
1957
+ {
1958
+ divisor_copy.Rcr(1);
1959
+ --bits_diff;
1960
+ }
1961
+
1962
+ Sub(divisor_copy, 0);
1963
+
1964
+ TTMATH_LOG("UInt::Div2_Calculate")
1965
+
1966
+ return 2;
1967
+ }
1968
+
1969
+
1970
+ /*!
1971
+ return values:
1972
+ - 0 - we've calculated the division
1973
+ - 1 - division by zero
1974
+ - 2 - we have to still calculate
1975
+ */
1976
+ uint Div2_FindLeadingBitsAndCheck( const UInt<value_size> & divisor,
1977
+ UInt<value_size> * remainder,
1978
+ uint & table_id, uint & index,
1979
+ uint & divisor_table_id, uint & divisor_index)
1980
+ {
1981
+ if( !divisor.FindLeadingBit(divisor_table_id, divisor_index) )
1982
+ {
1983
+ // division by zero
1984
+ TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck")
1985
+ return 1;
1986
+ }
1987
+
1988
+ if( !FindLeadingBit(table_id, index) )
1989
+ {
1990
+ // zero is divided by something
1991
+
1992
+ SetZero();
1993
+
1994
+ if( remainder )
1995
+ remainder->SetZero();
1996
+
1997
+ TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck")
1998
+
1999
+ return 0;
2000
+ }
2001
+
2002
+ divisor_index += divisor_table_id * TTMATH_BITS_PER_UINT;
2003
+ index += table_id * TTMATH_BITS_PER_UINT;
2004
+
2005
+ if( divisor_table_id == 0 )
2006
+ {
2007
+ // dividor has only one 32-bit word
2008
+
2009
+ uint r;
2010
+ DivInt(divisor.table[0], &r);
2011
+
2012
+ if( remainder )
2013
+ {
2014
+ remainder->SetZero();
2015
+ remainder->table[0] = r;
2016
+ }
2017
+
2018
+ TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck")
2019
+
2020
+ return 0;
2021
+ }
2022
+
2023
+
2024
+ if( Div2_DivisorGreaterOrEqual( divisor, remainder,
2025
+ table_id, index,
2026
+ divisor_index) )
2027
+ {
2028
+ TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck")
2029
+ return 0;
2030
+ }
2031
+
2032
+
2033
+ TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck")
2034
+
2035
+ return 2;
2036
+ }
2037
+
2038
+
2039
+ /*!
2040
+ return values:
2041
+ - true if divisor is equal or greater than 'this'
2042
+ */
2043
+ bool Div2_DivisorGreaterOrEqual( const UInt<value_size> & divisor,
2044
+ UInt<value_size> * remainder,
2045
+ uint table_id, uint index,
2046
+ uint divisor_index )
2047
+ {
2048
+ if( divisor_index > index )
2049
+ {
2050
+ // divisor is greater than this
2051
+
2052
+ if( remainder )
2053
+ *remainder = *this;
2054
+
2055
+ SetZero();
2056
+
2057
+ TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual")
2058
+
2059
+ return true;
2060
+ }
2061
+
2062
+ if( divisor_index == index )
2063
+ {
2064
+ // table_id == divisor_table_id as well
2065
+
2066
+ uint i;
2067
+ for(i = table_id ; i!=0 && table[i]==divisor.table[i] ; --i);
2068
+
2069
+ if( table[i] < divisor.table[i] )
2070
+ {
2071
+ // divisor is greater than 'this'
2072
+
2073
+ if( remainder )
2074
+ *remainder = *this;
2075
+
2076
+ SetZero();
2077
+
2078
+ TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual")
2079
+
2080
+ return true;
2081
+ }
2082
+ else
2083
+ if( table[i] == divisor.table[i] )
2084
+ {
2085
+ // divisor is equal 'this'
2086
+
2087
+ if( remainder )
2088
+ remainder->SetZero();
2089
+
2090
+ SetOne();
2091
+
2092
+ TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual")
2093
+
2094
+ return true;
2095
+ }
2096
+ }
2097
+
2098
+ TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual")
2099
+
2100
+ return false;
2101
+ }
2102
+
2103
+
2104
+ public:
2105
+
2106
+ /*!
2107
+ the third division algorithm
2108
+ */
2109
+ uint Div3(const UInt<value_size> & ss2, UInt<value_size> * remainder = 0)
2110
+ {
2111
+ if( this == &ss2 )
2112
+ {
2113
+ UInt<value_size> copy_ss2(ss2);
2114
+ return Div3Ref(copy_ss2, remainder);
2115
+ }
2116
+ else
2117
+ {
2118
+ return Div3Ref(ss2, remainder);
2119
+ }
2120
+ }
2121
+
2122
+
2123
+ /*!
2124
+ the third division algorithm
2125
+ */
2126
+ uint Div3(const UInt<value_size> & ss2, UInt<value_size> & remainder)
2127
+ {
2128
+ return Div3(ss2, &remainder);
2129
+ }
2130
+
2131
+
2132
+ private:
2133
+
2134
+ /*!
2135
+ the third division algorithm
2136
+
2137
+ this algorithm is described in the following book:
2138
+ "The art of computer programming 2" (4.3.1 page 272)
2139
+ Donald E. Knuth
2140
+ !! give the description here (from the book)
2141
+ */
2142
+ uint Div3Ref(const UInt<value_size> & v, UInt<value_size> * remainder = 0)
2143
+ {
2144
+ uint m,n, test;
2145
+
2146
+ test = Div_StandardTest(v, m, n, remainder);
2147
+ if( test < 2 )
2148
+ return test;
2149
+
2150
+ if( n == 0 )
2151
+ {
2152
+ uint r;
2153
+ DivInt( v.table[0], &r );
2154
+
2155
+ if( remainder )
2156
+ {
2157
+ remainder->SetZero();
2158
+ remainder->table[0] = r;
2159
+ }
2160
+
2161
+ TTMATH_LOG("UInt::Div3")
2162
+
2163
+ return 0;
2164
+ }
2165
+
2166
+
2167
+ // we can only use the third division algorithm when
2168
+ // the divisor is greater or equal 2^32 (has more than one 32-bit word)
2169
+ ++m;
2170
+ ++n;
2171
+ m = m - n;
2172
+ Div3_Division(v, remainder, m, n);
2173
+
2174
+ TTMATH_LOG("UInt::Div3")
2175
+
2176
+ return 0;
2177
+ }
2178
+
2179
+
2180
+
2181
+ private:
2182
+
2183
+
2184
+ void Div3_Division(UInt<value_size> v, UInt<value_size> * remainder, uint m, uint n)
2185
+ {
2186
+ TTMATH_ASSERT( n>=2 && n<=value_size && m<=value_size && m+n<=value_size )
2187
+
2188
+ UInt<value_size+1> uu, vv;
2189
+ UInt<value_size> q;
2190
+ uint d, u_value_size, u0, u1, u2, v1, v0, j=m;
2191
+
2192
+ u_value_size = Div3_Normalize(v, n, d);
2193
+
2194
+ if( j+n == value_size )
2195
+ u2 = u_value_size;
2196
+ else
2197
+ u2 = table[j+n];
2198
+
2199
+ Div3_MakeBiggerV(v, vv);
2200
+
2201
+ for(uint i = j+1 ; i<value_size ; ++i)
2202
+ q.table[i] = 0;
2203
+
2204
+ while( true )
2205
+ {
2206
+ u1 = table[j+n-1];
2207
+ u0 = table[j+n-2];
2208
+ v1 = v.table[n-1];
2209
+ v0 = v.table[n-2];
2210
+
2211
+ uint qp = Div3_Calculate(u2,u1,u0, v1,v0);
2212
+
2213
+ Div3_MakeNewU(uu, j, n, u2);
2214
+ Div3_MultiplySubtract(uu, vv, qp);
2215
+ Div3_CopyNewU(uu, j, n);
2216
+
2217
+ q.table[j] = qp;
2218
+
2219
+ // the next loop
2220
+ if( j-- == 0 )
2221
+ break;
2222
+
2223
+ u2 = table[j+n];
2224
+ }
2225
+
2226
+ if( remainder )
2227
+ Div3_Unnormalize(remainder, n, d);
2228
+
2229
+ *this = q;
2230
+
2231
+ TTMATH_LOG("UInt::Div3_Division")
2232
+ }
2233
+
2234
+
2235
+ void Div3_MakeNewU(UInt<value_size+1> & uu, uint j, uint n, uint u_max)
2236
+ {
2237
+ uint i;
2238
+
2239
+ for(i=0 ; i<n ; ++i, ++j)
2240
+ uu.table[i] = table[j];
2241
+
2242
+ // 'n' is from <1..value_size> so and 'i' is from <0..value_size>
2243
+ // then table[i] is always correct (look at the declaration of 'uu')
2244
+ uu.table[i] = u_max;
2245
+
2246
+ for( ++i ; i<value_size+1 ; ++i)
2247
+ uu.table[i] = 0;
2248
+
2249
+ TTMATH_LOG("UInt::Div3_MakeNewU")
2250
+ }
2251
+
2252
+
2253
+ void Div3_CopyNewU(const UInt<value_size+1> & uu, uint j, uint n)
2254
+ {
2255
+ uint i;
2256
+
2257
+ for(i=0 ; i<n ; ++i)
2258
+ table[i+j] = uu.table[i];
2259
+
2260
+ if( i+j < value_size )
2261
+ table[i+j] = uu.table[i];
2262
+
2263
+ TTMATH_LOG("UInt::Div3_CopyNewU")
2264
+ }
2265
+
2266
+
2267
+ /*!
2268
+ we're making the new 'vv'
2269
+ the value is actually the same but the 'table' is bigger (value_size+1)
2270
+ */
2271
+ void Div3_MakeBiggerV(const UInt<value_size> & v, UInt<value_size+1> & vv)
2272
+ {
2273
+ for(uint i=0 ; i<value_size ; ++i)
2274
+ vv.table[i] = v.table[i];
2275
+
2276
+ vv.table[value_size] = 0;
2277
+
2278
+ TTMATH_LOG("UInt::Div3_MakeBiggerV")
2279
+ }
2280
+
2281
+
2282
+ /*!
2283
+ we're moving all bits from 'v' into the left side of the n-1 word
2284
+ (the highest bit at v.table[n-1] will be equal one,
2285
+ the bits from 'this' we're moving the same times as 'v')
2286
+
2287
+ return values:
2288
+ - d - how many times we've moved
2289
+ - return - the next-left value from 'this' (that after table[value_size-1])
2290
+ */
2291
+ uint Div3_Normalize(UInt<value_size> & v, uint n, uint & d)
2292
+ {
2293
+ // v.table[n-1] is != 0
2294
+
2295
+ uint bit = (uint)FindLeadingBitInWord(v.table[n-1]);
2296
+ uint move = (TTMATH_BITS_PER_UINT - bit - 1);
2297
+ uint res = table[value_size-1];
2298
+ d = move;
2299
+
2300
+ if( move > 0 )
2301
+ {
2302
+ v.Rcl(move, 0);
2303
+ Rcl(move, 0);
2304
+ res = res >> (bit + 1);
2305
+ }
2306
+ else
2307
+ {
2308
+ res = 0;
2309
+ }
2310
+
2311
+ TTMATH_LOG("UInt::Div3_Normalize")
2312
+
2313
+ return res;
2314
+ }
2315
+
2316
+
2317
+ void Div3_Unnormalize(UInt<value_size> * remainder, uint n, uint d)
2318
+ {
2319
+ for(uint i=n ; i<value_size ; ++i)
2320
+ table[i] = 0;
2321
+
2322
+ Rcr(d,0);
2323
+
2324
+ *remainder = *this;
2325
+
2326
+ TTMATH_LOG("UInt::Div3_Unnormalize")
2327
+ }
2328
+
2329
+
2330
+ uint Div3_Calculate(uint u2, uint u1, uint u0, uint v1, uint v0)
2331
+ {
2332
+ UInt<2> u_temp;
2333
+ uint rp;
2334
+ bool next_test;
2335
+
2336
+ TTMATH_ASSERT( v1 != 0 )
2337
+
2338
+ u_temp.table[1] = u2;
2339
+ u_temp.table[0] = u1;
2340
+ u_temp.DivInt(v1, &rp);
2341
+
2342
+ TTMATH_ASSERT( u_temp.table[1]==0 || u_temp.table[1]==1 )
2343
+
2344
+ do
2345
+ {
2346
+ bool decrease = false;
2347
+
2348
+ if( u_temp.table[1] == 1 )
2349
+ decrease = true;
2350
+ else
2351
+ {
2352
+ UInt<2> temp1, temp2;
2353
+
2354
+ UInt<2>::MulTwoWords(u_temp.table[0], v0, temp1.table+1, temp1.table);
2355
+ temp2.table[1] = rp;
2356
+ temp2.table[0] = u0;
2357
+
2358
+ if( temp1 > temp2 )
2359
+ decrease = true;
2360
+ }
2361
+
2362
+ next_test = false;
2363
+
2364
+ if( decrease )
2365
+ {
2366
+ u_temp.SubOne();
2367
+
2368
+ rp += v1;
2369
+
2370
+ if( rp >= v1 ) // it means that there wasn't a carry (r<b from the book)
2371
+ next_test = true;
2372
+ }
2373
+ }
2374
+ while( next_test );
2375
+
2376
+ TTMATH_LOG("UInt::Div3_Calculate")
2377
+
2378
+ return u_temp.table[0];
2379
+ }
2380
+
2381
+
2382
+
2383
+ void Div3_MultiplySubtract( UInt<value_size+1> & uu,
2384
+ const UInt<value_size+1> & vv, uint & qp)
2385
+ {
2386
+ // D4 (in the book)
2387
+
2388
+ UInt<value_size+1> vv_temp(vv);
2389
+ vv_temp.MulInt(qp);
2390
+
2391
+ if( uu.Sub(vv_temp) )
2392
+ {
2393
+ // there was a carry
2394
+
2395
+ //
2396
+ // !!! this part of code was not tested
2397
+ //
2398
+
2399
+ --qp;
2400
+ uu.Add(vv);
2401
+
2402
+ // can be a carry from this additions but it should be ignored
2403
+ // because it cancels with the borrow from uu.Sub(vv_temp)
2404
+ }
2405
+
2406
+ TTMATH_LOG("UInt::Div3_MultiplySubtract")
2407
+ }
2408
+
2409
+
2410
+
2411
+
2412
+
2413
+
2414
+ public:
2415
+
2416
+
2417
+ /*!
2418
+ power this = this ^ pow
2419
+ binary algorithm (r-to-l)
2420
+
2421
+ return values:
2422
+ - 0 - ok
2423
+ - 1 - carry
2424
+ - 2 - incorrect argument (0^0)
2425
+ */
2426
+ uint Pow(UInt<value_size> pow)
2427
+ {
2428
+ if(pow.IsZero() && IsZero())
2429
+ // we don't define zero^zero
2430
+ return 2;
2431
+
2432
+ UInt<value_size> start(*this);
2433
+ UInt<value_size> result;
2434
+ result.SetOne();
2435
+ uint c = 0;
2436
+
2437
+ while( !c )
2438
+ {
2439
+ if( pow.table[0] & 1 )
2440
+ c += result.Mul(start);
2441
+
2442
+ pow.Rcr2_one(0);
2443
+ if( pow.IsZero() )
2444
+ break;
2445
+
2446
+ c += start.Mul(start);
2447
+ }
2448
+
2449
+ *this = result;
2450
+
2451
+ TTMATH_LOGC("UInt::Pow(UInt<>)", c)
2452
+
2453
+ return (c==0)? 0 : 1;
2454
+ }
2455
+
2456
+
2457
+ /*!
2458
+ square root
2459
+ e.g. Sqrt(9) = 3
2460
+ ('digit-by-digit' algorithm)
2461
+ */
2462
+ void Sqrt()
2463
+ {
2464
+ UInt<value_size> bit, temp;
2465
+
2466
+ if( IsZero() )
2467
+ return;
2468
+
2469
+ UInt<value_size> value(*this);
2470
+
2471
+ SetZero();
2472
+ bit.SetZero();
2473
+ bit.table[value_size-1] = (TTMATH_UINT_HIGHEST_BIT >> 1);
2474
+
2475
+ while( bit > value )
2476
+ bit.Rcr(2);
2477
+
2478
+ while( !bit.IsZero() )
2479
+ {
2480
+ temp = *this;
2481
+ temp.Add(bit);
2482
+
2483
+ if( value >= temp )
2484
+ {
2485
+ value.Sub(temp);
2486
+ Rcr(1);
2487
+ Add(bit);
2488
+ }
2489
+ else
2490
+ {
2491
+ Rcr(1);
2492
+ }
2493
+
2494
+ bit.Rcr(2);
2495
+ }
2496
+
2497
+ TTMATH_LOG("UInt::Sqrt")
2498
+ }
2499
+
2500
+
2501
+
2502
+
2503
+ /*!
2504
+ this method sets n first bits to value zero
2505
+
2506
+ For example:
2507
+ let n=2 then if there's a value 111 (bin) there'll be '100' (bin)
2508
+ */
2509
+ void ClearFirstBits(uint n)
2510
+ {
2511
+ if( n >= value_size*TTMATH_BITS_PER_UINT )
2512
+ {
2513
+ SetZero();
2514
+ TTMATH_LOG("UInt::ClearFirstBits")
2515
+ return;
2516
+ }
2517
+
2518
+ uint * p = table;
2519
+
2520
+ // first we're clearing the whole words
2521
+ while( n >= TTMATH_BITS_PER_UINT )
2522
+ {
2523
+ *p++ = 0;
2524
+ n -= TTMATH_BITS_PER_UINT;
2525
+ }
2526
+
2527
+ if( n == 0 )
2528
+ {
2529
+ TTMATH_LOG("UInt::ClearFirstBits")
2530
+ return;
2531
+ }
2532
+
2533
+ // and then we're clearing one word which has left
2534
+ // mask -- all bits are set to one
2535
+ uint mask = TTMATH_UINT_MAX_VALUE;
2536
+
2537
+ mask = mask << n;
2538
+
2539
+ (*p) &= mask;
2540
+
2541
+ TTMATH_LOG("UInt::ClearFirstBits")
2542
+ }
2543
+
2544
+
2545
+ /*!
2546
+ this method returns true if the highest bit of the value is set
2547
+ */
2548
+ bool IsTheHighestBitSet() const
2549
+ {
2550
+ return (table[value_size-1] & TTMATH_UINT_HIGHEST_BIT) != 0;
2551
+ }
2552
+
2553
+
2554
+ /*!
2555
+ this method returns true if the lowest bit of the value is set
2556
+ */
2557
+ bool IsTheLowestBitSet() const
2558
+ {
2559
+ return (*table & 1) != 0;
2560
+ }
2561
+
2562
+
2563
+ /*!
2564
+ returning true if only the highest bit is set
2565
+ */
2566
+ bool IsOnlyTheHighestBitSet() const
2567
+ {
2568
+ #ifdef __clang__
2569
+ #pragma clang diagnostic push
2570
+ #pragma clang diagnostic ignored "-Wtautological-compare"
2571
+ #endif
2572
+
2573
+ for(uint i=0 ; i<value_size-1 ; ++i)
2574
+ if( table[i] != 0 )
2575
+ return false;
2576
+
2577
+ #ifdef __clang__
2578
+ #pragma clang diagnostic pop
2579
+ #endif
2580
+ if( table[value_size-1] != TTMATH_UINT_HIGHEST_BIT )
2581
+ return false;
2582
+
2583
+ return true;
2584
+ }
2585
+
2586
+
2587
+ /*!
2588
+ returning true if only the lowest bit is set
2589
+ */
2590
+ bool IsOnlyTheLowestBitSet() const
2591
+ {
2592
+ if( table[0] != 1 )
2593
+ return false;
2594
+
2595
+ for(uint i=1 ; i<value_size ; ++i)
2596
+ if( table[i] != 0 )
2597
+ return false;
2598
+
2599
+ return true;
2600
+ }
2601
+
2602
+
2603
+ /*!
2604
+ this method returns true if the value is equal zero
2605
+ */
2606
+ bool IsZero() const
2607
+ {
2608
+ for(uint i=0 ; i<value_size ; ++i)
2609
+ if(table[i] != 0)
2610
+ return false;
2611
+
2612
+ return true;
2613
+ }
2614
+
2615
+
2616
+ /*!
2617
+ returning true if first 'bits' bits are equal zero
2618
+ */
2619
+ bool AreFirstBitsZero(uint bits) const
2620
+ {
2621
+ TTMATH_ASSERT( bits <= value_size * TTMATH_BITS_PER_UINT )
2622
+
2623
+ uint index = bits / TTMATH_BITS_PER_UINT;
2624
+ uint rest = bits % TTMATH_BITS_PER_UINT;
2625
+ uint i;
2626
+
2627
+ for(i=0 ; i<index ; ++i)
2628
+ if(table[i] != 0 )
2629
+ return false;
2630
+
2631
+ if( rest == 0 )
2632
+ return true;
2633
+
2634
+ uint mask = TTMATH_UINT_MAX_VALUE >> (TTMATH_BITS_PER_UINT - rest);
2635
+
2636
+ return (table[i] & mask) == 0;
2637
+ }
2638
+
2639
+
2640
+
2641
+ /*!
2642
+ *
2643
+ * conversion methods
2644
+ *
2645
+ */
2646
+
2647
+
2648
+
2649
+ /*!
2650
+ this method converts an UInt<another_size> type to this class
2651
+
2652
+ this operation has mainly sense if the value from p is
2653
+ equal or smaller than that one which is returned from UInt<value_size>::SetMax()
2654
+
2655
+ it returns a carry if the value 'p' is too big
2656
+ */
2657
+ template<uint argument_size>
2658
+ uint FromUInt(const UInt<argument_size> & p)
2659
+ {
2660
+ uint min_size = (value_size < argument_size)? value_size : argument_size;
2661
+ uint i;
2662
+
2663
+ for(i=0 ; i<min_size ; ++i)
2664
+ table[i] = p.table[i];
2665
+
2666
+
2667
+ if( value_size > argument_size )
2668
+ {
2669
+ // 'this' is longer than 'p'
2670
+
2671
+ for( ; i<value_size ; ++i)
2672
+ table[i] = 0;
2673
+ }
2674
+ else
2675
+ {
2676
+ for( ; i<argument_size ; ++i)
2677
+ if( p.table[i] != 0 )
2678
+ {
2679
+ TTMATH_LOGC("UInt::FromUInt(UInt<>)", 1)
2680
+ return 1;
2681
+ }
2682
+ }
2683
+
2684
+ TTMATH_LOGC("UInt::FromUInt(UInt<>)", 0)
2685
+
2686
+ return 0;
2687
+ }
2688
+
2689
+
2690
+ /*!
2691
+ this method converts an UInt<another_size> type to this class
2692
+
2693
+ this operation has mainly sense if the value from p is
2694
+ equal or smaller than that one which is returned from UInt<value_size>::SetMax()
2695
+
2696
+ it returns a carry if the value 'p' is too big
2697
+ */
2698
+ template<uint argument_size>
2699
+ uint FromInt(const UInt<argument_size> & p)
2700
+ {
2701
+ return FromUInt(p);
2702
+ }
2703
+
2704
+
2705
+ /*!
2706
+ this method converts the uint type to this class
2707
+ */
2708
+ uint FromUInt(uint value)
2709
+ {
2710
+ for(uint i=1 ; i<value_size ; ++i)
2711
+ table[i] = 0;
2712
+
2713
+ table[0] = value;
2714
+
2715
+ TTMATH_LOG("UInt::FromUInt(uint)")
2716
+
2717
+ // there'll never be a carry here
2718
+ return 0;
2719
+ }
2720
+
2721
+
2722
+ /*!
2723
+ this method converts the uint type to this class
2724
+ */
2725
+ uint FromInt(uint value)
2726
+ {
2727
+ return FromUInt(value);
2728
+ }
2729
+
2730
+
2731
+ /*!
2732
+ this method converts the sint type to this class
2733
+ */
2734
+ uint FromInt(sint value)
2735
+ {
2736
+ uint c = FromUInt(uint(value));
2737
+
2738
+ if( c || value < 0 )
2739
+ return 1;
2740
+
2741
+ return 0;
2742
+ }
2743
+
2744
+
2745
+ /*!
2746
+ this operator converts an UInt<another_size> type to this class
2747
+
2748
+ it doesn't return a carry
2749
+ */
2750
+ template<uint argument_size>
2751
+ UInt<value_size> & operator=(const UInt<argument_size> & p)
2752
+ {
2753
+ FromUInt(p);
2754
+
2755
+ return *this;
2756
+ }
2757
+
2758
+
2759
+ /*!
2760
+ the assignment operator
2761
+ */
2762
+ UInt<value_size> & operator=(const UInt<value_size> & p)
2763
+ {
2764
+ for(uint i=0 ; i<value_size ; ++i)
2765
+ table[i] = p.table[i];
2766
+
2767
+ TTMATH_LOG("UInt::operator=(UInt<>)")
2768
+
2769
+ return *this;
2770
+ }
2771
+
2772
+
2773
+ /*!
2774
+ this method converts the uint type to this class
2775
+ */
2776
+ UInt<value_size> & operator=(uint i)
2777
+ {
2778
+ FromUInt(i);
2779
+
2780
+ return *this;
2781
+ }
2782
+
2783
+
2784
+ /*!
2785
+ a constructor for converting the uint to this class
2786
+ */
2787
+ UInt(uint i)
2788
+ {
2789
+ FromUInt(i);
2790
+ }
2791
+
2792
+
2793
+ /*!
2794
+ this method converts the sint type to this class
2795
+ */
2796
+ UInt<value_size> & operator=(sint i)
2797
+ {
2798
+ FromInt(i);
2799
+
2800
+ return *this;
2801
+ }
2802
+
2803
+
2804
+ /*!
2805
+ a constructor for converting the sint to this class
2806
+
2807
+ look at the description of UInt::operator=(sint)
2808
+ */
2809
+ UInt(sint i)
2810
+ {
2811
+ FromInt(i);
2812
+ }
2813
+
2814
+
2815
+ #ifdef TTMATH_PLATFORM32
2816
+
2817
+
2818
+ /*!
2819
+ this method converts unsigned 64 bit int type to this class
2820
+ ***this method is created only on a 32bit platform***
2821
+ */
2822
+ uint FromUInt(ulint n)
2823
+ {
2824
+ table[0] = (uint)n;
2825
+
2826
+ if( value_size == 1 )
2827
+ {
2828
+ uint c = ((n >> TTMATH_BITS_PER_UINT) == 0) ? 0 : 1;
2829
+
2830
+ TTMATH_LOGC("UInt::FromUInt(ulint)", c)
2831
+ return c;
2832
+ }
2833
+
2834
+ table[1] = (uint)(n >> TTMATH_BITS_PER_UINT);
2835
+
2836
+ for(uint i=2 ; i<value_size ; ++i)
2837
+ table[i] = 0;
2838
+
2839
+ TTMATH_LOG("UInt::FromUInt(ulint)")
2840
+
2841
+ return 0;
2842
+ }
2843
+
2844
+
2845
+ /*!
2846
+ this method converts unsigned 64 bit int type to this class
2847
+ ***this method is created only on a 32bit platform***
2848
+ */
2849
+ uint FromInt(ulint n)
2850
+ {
2851
+ return FromUInt(n);
2852
+ }
2853
+
2854
+
2855
+ /*!
2856
+ this method converts signed 64 bit int type to this class
2857
+ ***this method is created only on a 32bit platform***
2858
+ */
2859
+ uint FromInt(slint n)
2860
+ {
2861
+ uint c = FromUInt(ulint(n));
2862
+
2863
+ if( c || n < 0 )
2864
+ return 1;
2865
+
2866
+ return 0;
2867
+ }
2868
+
2869
+
2870
+ /*!
2871
+ this operator converts unsigned 64 bit int type to this class
2872
+ ***this operator is created only on a 32bit platform***
2873
+ */
2874
+ UInt<value_size> & operator=(ulint n)
2875
+ {
2876
+ FromUInt(n);
2877
+
2878
+ return *this;
2879
+ }
2880
+
2881
+
2882
+ /*!
2883
+ a constructor for converting unsigned 64 bit int to this class
2884
+ ***this constructor is created only on a 32bit platform***
2885
+ */
2886
+ UInt(ulint n)
2887
+ {
2888
+ FromUInt(n);
2889
+ }
2890
+
2891
+
2892
+ /*!
2893
+ this operator converts signed 64 bit int type to this class
2894
+ ***this operator is created only on a 32bit platform***
2895
+ */
2896
+ UInt<value_size> & operator=(slint n)
2897
+ {
2898
+ FromInt(n);
2899
+
2900
+ return *this;
2901
+ }
2902
+
2903
+
2904
+ /*!
2905
+ a constructor for converting signed 64 bit int to this class
2906
+ ***this constructor is created only on a 32bit platform***
2907
+ */
2908
+ UInt(slint n)
2909
+ {
2910
+ FromInt(n);
2911
+ }
2912
+
2913
+ #endif
2914
+
2915
+
2916
+
2917
+ #ifdef TTMATH_PLATFORM64
2918
+
2919
+
2920
+ /*!
2921
+ this method converts 32 bit unsigned int type to this class
2922
+ ***this operator is created only on a 64bit platform***
2923
+ */
2924
+ uint FromUInt(unsigned int i)
2925
+ {
2926
+ return FromUInt(uint(i));
2927
+ }
2928
+
2929
+ /*!
2930
+ this method converts 32 bit unsigned int type to this class
2931
+ ***this operator is created only on a 64bit platform***
2932
+ */
2933
+ uint FromInt(unsigned int i)
2934
+ {
2935
+ return FromUInt(uint(i));
2936
+ }
2937
+
2938
+
2939
+ /*!
2940
+ this method converts 32 bit signed int type to this class
2941
+ ***this operator is created only on a 64bit platform***
2942
+ */
2943
+ uint FromInt(signed int i)
2944
+ {
2945
+ return FromInt(sint(i));
2946
+ }
2947
+
2948
+
2949
+ /*!
2950
+ this operator converts 32 bit unsigned int type to this class
2951
+ ***this operator is created only on a 64bit platform***
2952
+ */
2953
+ UInt<value_size> & operator=(unsigned int i)
2954
+ {
2955
+ FromUInt(i);
2956
+
2957
+ return *this;
2958
+ }
2959
+
2960
+
2961
+ /*!
2962
+ a constructor for converting 32 bit unsigned int to this class
2963
+ ***this constructor is created only on a 64bit platform***
2964
+ */
2965
+ UInt(unsigned int i)
2966
+ {
2967
+ FromUInt(i);
2968
+ }
2969
+
2970
+
2971
+ /*!
2972
+ an operator for converting 32 bit signed int to this class
2973
+ ***this constructor is created only on a 64bit platform***
2974
+ */
2975
+ UInt<value_size> & operator=(signed int i)
2976
+ {
2977
+ FromInt(i);
2978
+
2979
+ return *this;
2980
+ }
2981
+
2982
+
2983
+ /*!
2984
+ a constructor for converting 32 bit signed int to this class
2985
+ ***this constructor is created only on a 64bit platform***
2986
+ */
2987
+ UInt(signed int i)
2988
+ {
2989
+ FromInt(i);
2990
+ }
2991
+
2992
+
2993
+ #endif
2994
+
2995
+
2996
+
2997
+
2998
+
2999
+ /*!
3000
+ a constructor for converting a string to this class (with the base=10)
3001
+ */
3002
+ UInt(const char * s)
3003
+ {
3004
+ FromString(s);
3005
+ }
3006
+
3007
+
3008
+ /*!
3009
+ a constructor for converting a string to this class (with the base=10)
3010
+ */
3011
+ UInt(const std::string & s)
3012
+ {
3013
+ FromString( s.c_str() );
3014
+ }
3015
+
3016
+
3017
+ #ifndef TTMATH_DONT_USE_WCHAR
3018
+
3019
+ /*!
3020
+ a constructor for converting a string to this class (with the base=10)
3021
+ */
3022
+ UInt(const wchar_t * s)
3023
+ {
3024
+ FromString(s);
3025
+ }
3026
+
3027
+
3028
+ /*!
3029
+ a constructor for converting a string to this class (with the base=10)
3030
+ */
3031
+ UInt(const std::wstring & s)
3032
+ {
3033
+ FromString( s.c_str() );
3034
+ }
3035
+
3036
+ #endif
3037
+
3038
+
3039
+
3040
+
3041
+ /*!
3042
+ a default constructor
3043
+
3044
+ we don't clear the table
3045
+ */
3046
+ UInt()
3047
+ {
3048
+ // when macro TTMATH_DEBUG_LOG is defined
3049
+ // we set special values to the table
3050
+ // in order to be everywhere the same value of the UInt object
3051
+ // without this it would be difficult to analyse the log file
3052
+ #ifdef TTMATH_DEBUG_LOG
3053
+ #ifdef TTMATH_PLATFORM32
3054
+ for(uint i=0 ; i<value_size ; ++i)
3055
+ table[i] = 0xc1c1c1c1;
3056
+ #else
3057
+ for(uint i=0 ; i<value_size ; ++i)
3058
+ table[i] = 0xc1c1c1c1c1c1c1c1;
3059
+ #endif
3060
+ #endif
3061
+ }
3062
+
3063
+
3064
+ /*!
3065
+ a copy constructor
3066
+ */
3067
+ UInt(const UInt<value_size> & u)
3068
+ {
3069
+ for(uint i=0 ; i<value_size ; ++i)
3070
+ table[i] = u.table[i];
3071
+
3072
+ TTMATH_LOG("UInt::UInt(UInt<>)")
3073
+ }
3074
+
3075
+
3076
+
3077
+ /*!
3078
+ a template for producting constructors for copying from another types
3079
+ */
3080
+ template<uint argument_size>
3081
+ UInt(const UInt<argument_size> & u)
3082
+ {
3083
+ // look that 'size' we still set as 'value_size' and not as u.value_size
3084
+ FromUInt(u);
3085
+ }
3086
+
3087
+
3088
+
3089
+
3090
+ /*!
3091
+ a destructor
3092
+ */
3093
+ ~UInt()
3094
+ {
3095
+ }
3096
+
3097
+
3098
+ /*!
3099
+ this method returns the lowest value from table
3100
+
3101
+ we must be sure when we using this method whether the value
3102
+ will hold in an uint type or not (the rest value from the table must be zero)
3103
+ */
3104
+ uint ToUInt() const
3105
+ {
3106
+ return table[0];
3107
+ }
3108
+
3109
+
3110
+ /*!
3111
+ this method converts the value to uint type
3112
+ can return a carry if the value is too long to store it in uint type
3113
+ */
3114
+ uint ToUInt(uint & result) const
3115
+ {
3116
+ result = table[0];
3117
+
3118
+ for(uint i=1 ; i<value_size ; ++i)
3119
+ if( table[i] != 0 )
3120
+ return 1;
3121
+
3122
+ return 0;
3123
+ }
3124
+
3125
+
3126
+ /*!
3127
+ this method converts the value to uint type
3128
+ can return a carry if the value is too long to store it in uint type
3129
+ */
3130
+ uint ToInt(uint & result) const
3131
+ {
3132
+ return ToUInt(result);
3133
+ }
3134
+
3135
+
3136
+ /*!
3137
+ this method converts the value to sint type (signed integer)
3138
+ can return a carry if the value is too long to store it in sint type
3139
+ */
3140
+ uint ToInt(sint & result) const
3141
+ {
3142
+ result = sint(table[0]);
3143
+
3144
+ if( (result & TTMATH_UINT_HIGHEST_BIT) != 0 )
3145
+ return 1;
3146
+
3147
+ for(uint i=1 ; i<value_size ; ++i)
3148
+ if( table[i] != 0 )
3149
+ return 1;
3150
+
3151
+ return 0;
3152
+ }
3153
+
3154
+
3155
+ #ifdef TTMATH_PLATFORM32
3156
+
3157
+ /*!
3158
+ this method converts the value to ulint type (64 bit unsigned integer)
3159
+ can return a carry if the value is too long to store it in ulint type
3160
+ *** this method is created only on a 32 bit platform ***
3161
+ */
3162
+ uint ToUInt(ulint & result) const
3163
+ {
3164
+ if( value_size == 1 )
3165
+ {
3166
+ result = table[0];
3167
+ }
3168
+ else
3169
+ {
3170
+ uint low = table[0];
3171
+ uint high = table[1];
3172
+
3173
+ result = low;
3174
+ result |= (ulint(high) << TTMATH_BITS_PER_UINT);
3175
+
3176
+ for(uint i=2 ; i<value_size ; ++i)
3177
+ if( table[i] != 0 )
3178
+ return 1;
3179
+ }
3180
+
3181
+ return 0;
3182
+ }
3183
+
3184
+
3185
+ /*!
3186
+ this method converts the value to ulint type (64 bit unsigned integer)
3187
+ can return a carry if the value is too long to store it in ulint type
3188
+ *** this method is created only on a 32 bit platform ***
3189
+ */
3190
+ uint ToInt(ulint & result) const
3191
+ {
3192
+ return ToUInt(result);
3193
+ }
3194
+
3195
+
3196
+ /*!
3197
+ this method converts the value to slint type (64 bit signed integer)
3198
+ can return a carry if the value is too long to store it in slint type
3199
+ *** this method is created only on a 32 bit platform ***
3200
+ */
3201
+ uint ToInt(slint & result) const
3202
+ {
3203
+ ulint temp;
3204
+
3205
+ uint c = ToUInt(temp);
3206
+ result = slint(temp);
3207
+
3208
+ if( c || result < 0 )
3209
+ return 1;
3210
+
3211
+ return 0;
3212
+ }
3213
+
3214
+ #endif
3215
+
3216
+
3217
+
3218
+ #ifdef TTMATH_PLATFORM64
3219
+
3220
+ /*!
3221
+ this method converts the value to a 32 unsigned integer
3222
+ can return a carry if the value is too long to store it in this type
3223
+ *** this method is created only on a 64 bit platform ***
3224
+ */
3225
+ uint ToUInt(unsigned int & result) const
3226
+ {
3227
+ result = (unsigned int)table[0];
3228
+
3229
+ if( (table[0] >> 32) != 0 )
3230
+ return 1;
3231
+
3232
+ for(uint i=1 ; i<value_size ; ++i)
3233
+ if( table[i] != 0 )
3234
+ return 1;
3235
+
3236
+ return 0;
3237
+ }
3238
+
3239
+
3240
+ /*!
3241
+ this method converts the value to a 32 unsigned integer
3242
+ can return a carry if the value is too long to store it in this type
3243
+ *** this method is created only on a 64 bit platform ***
3244
+ */
3245
+ uint ToInt(unsigned int & result) const
3246
+ {
3247
+ return ToUInt(result);
3248
+ }
3249
+
3250
+
3251
+ /*!
3252
+ this method converts the value to a 32 signed integer
3253
+ can return a carry if the value is too long to store it in this type
3254
+ *** this method is created only on a 64 bit platform ***
3255
+ */
3256
+ uint ToInt(int & result) const
3257
+ {
3258
+ unsigned int temp;
3259
+
3260
+ uint c = ToUInt(temp);
3261
+ result = int(temp);
3262
+
3263
+ if( c || result < 0 )
3264
+ return 1;
3265
+
3266
+ return 0;
3267
+ }
3268
+
3269
+
3270
+ #endif
3271
+
3272
+
3273
+
3274
+
3275
+ protected:
3276
+
3277
+ /*!
3278
+ an auxiliary method for converting into the string
3279
+ it returns the log (with the base 2) from x
3280
+ where x is in <2;16>
3281
+ */
3282
+ double ToStringLog2(uint x) const
3283
+ {
3284
+ static double log_tab[] = {
3285
+ 1.000000000000000000,
3286
+ 0.630929753571457437,
3287
+ 0.500000000000000000,
3288
+ 0.430676558073393050,
3289
+ 0.386852807234541586,
3290
+ 0.356207187108022176,
3291
+ 0.333333333333333333,
3292
+ 0.315464876785728718,
3293
+ 0.301029995663981195,
3294
+ 0.289064826317887859,
3295
+ 0.278942945651129843,
3296
+ 0.270238154427319741,
3297
+ 0.262649535037193547,
3298
+ 0.255958024809815489,
3299
+ 0.250000000000000000
3300
+ };
3301
+
3302
+ if( x<2 || x>16 )
3303
+ return 0;
3304
+
3305
+ return log_tab[x-2];
3306
+ }
3307
+
3308
+
3309
+ public:
3310
+
3311
+
3312
+ /*!
3313
+ an auxiliary method for converting to a string
3314
+ it's used from Int::ToString() too (negative is set true then)
3315
+ */
3316
+ template<class string_type>
3317
+ void ToStringBase(string_type & result, uint b = 10, bool negative = false) const
3318
+ {
3319
+ UInt<value_size> temp(*this);
3320
+ uint rest, table_id, index, digits;
3321
+ double digits_d;
3322
+ char character;
3323
+
3324
+ result.clear();
3325
+
3326
+ if( b<2 || b>16 )
3327
+ return;
3328
+
3329
+ if( !FindLeadingBit(table_id, index) )
3330
+ {
3331
+ result = '0';
3332
+ return;
3333
+ }
3334
+
3335
+ if( negative )
3336
+ result = '-';
3337
+
3338
+ digits_d = static_cast<double>(table_id); // for not making an overflow in uint type
3339
+ digits_d *= TTMATH_BITS_PER_UINT;
3340
+ digits_d += index + 1;
3341
+ digits_d *= ToStringLog2(b);
3342
+ digits = static_cast<uint>(digits_d) + 3; // plus some epsilon
3343
+
3344
+ if( result.capacity() < digits )
3345
+ result.reserve(digits);
3346
+
3347
+ do
3348
+ {
3349
+ temp.DivInt(b, &rest);
3350
+ character = static_cast<char>(Misc::DigitToChar(rest));
3351
+ result.insert(result.end(), character);
3352
+ }
3353
+ while( !temp.IsZero() );
3354
+
3355
+ size_t i1 = negative ? 1 : 0; // the first is a hyphen (when negative is true)
3356
+ size_t i2 = result.size() - 1;
3357
+
3358
+ for( ; i1 < i2 ; ++i1, --i2 )
3359
+ {
3360
+ char tempc = static_cast<char>(result[i1]);
3361
+ result[i1] = result[i2];
3362
+ result[i2] = tempc;
3363
+ }
3364
+ }
3365
+
3366
+
3367
+
3368
+ /*!
3369
+ this method converts the value to a string with a base equal 'b'
3370
+ */
3371
+ void ToString(std::string & result, uint b = 10) const
3372
+ {
3373
+ return ToStringBase(result, b);
3374
+ }
3375
+
3376
+
3377
+ std::string ToString(uint b = 10) const
3378
+ {
3379
+ std::string result;
3380
+ ToStringBase(result, b);
3381
+
3382
+ return result;
3383
+ }
3384
+
3385
+
3386
+ #ifndef TTMATH_DONT_USE_WCHAR
3387
+
3388
+ void ToString(std::wstring & result, uint b = 10) const
3389
+ {
3390
+ return ToStringBase(result, b);
3391
+ }
3392
+
3393
+ std::wstring ToWString(uint b = 10) const
3394
+ {
3395
+ std::wstring result;
3396
+ ToStringBase(result, b);
3397
+
3398
+ return result;
3399
+ }
3400
+
3401
+ #endif
3402
+
3403
+
3404
+
3405
+ private:
3406
+
3407
+ /*!
3408
+ an auxiliary method for converting from a string
3409
+ */
3410
+ template<class char_type>
3411
+ uint FromStringBase(const char_type * s, uint b = 10, const char_type ** after_source = 0, bool * value_read = 0)
3412
+ {
3413
+ UInt<value_size> base( b );
3414
+ UInt<value_size> temp;
3415
+ sint z;
3416
+ uint c = 0;
3417
+
3418
+ SetZero();
3419
+ temp.SetZero();
3420
+ Misc::SkipWhiteCharacters(s);
3421
+
3422
+ if( after_source )
3423
+ *after_source = s;
3424
+
3425
+ if( value_read )
3426
+ *value_read = false;
3427
+
3428
+ if( b<2 || b>16 )
3429
+ return 1;
3430
+
3431
+
3432
+ for( ; (z=Misc::CharToDigit(*s, b)) != -1 ; ++s)
3433
+ {
3434
+ if( value_read )
3435
+ *value_read = true;
3436
+
3437
+ if( c == 0 )
3438
+ {
3439
+ temp.table[0] = z;
3440
+
3441
+ c += Mul(base); // !! IMPROVE ME: there can be used MulInt here
3442
+ c += Add(temp);
3443
+ }
3444
+ }
3445
+
3446
+ if( after_source )
3447
+ *after_source = s;
3448
+
3449
+ TTMATH_LOGC("UInt::FromString", c)
3450
+
3451
+ return (c==0)? 0 : 1;
3452
+ }
3453
+
3454
+
3455
+ public:
3456
+
3457
+
3458
+ /*!
3459
+ this method converts a string into its value
3460
+ it returns carry=1 if the value will be too big or an incorrect base 'b' is given
3461
+
3462
+ string is ended with a non-digit value, for example:
3463
+ "12" will be translated to 12
3464
+ as well as:
3465
+ "12foo" will be translated to 12 too
3466
+
3467
+ existing first white characters will be ommited
3468
+
3469
+ if the value from s is too large the rest digits will be skipped
3470
+
3471
+ after_source (if exists) is pointing at the end of the parsed string
3472
+
3473
+ value_read (if exists) tells whether something has actually been read (at least one digit)
3474
+ */
3475
+ uint FromString(const char * s, uint b = 10, const char ** after_source = 0, bool * value_read = 0)
3476
+ {
3477
+ return FromStringBase(s, b, after_source, value_read);
3478
+ }
3479
+
3480
+
3481
+ /*!
3482
+ this method converts a string into its value
3483
+
3484
+ (it returns carry=1 if the value will be too big or an incorrect base 'b' is given)
3485
+ */
3486
+ uint FromString(const std::string & s, uint b = 10)
3487
+ {
3488
+ return FromString( s.c_str(), b );
3489
+ }
3490
+
3491
+
3492
+ /*!
3493
+ this operator converts a string into its value (with base = 10)
3494
+ */
3495
+ UInt<value_size> & operator=(const char * s)
3496
+ {
3497
+ FromString(s);
3498
+
3499
+ return *this;
3500
+ }
3501
+
3502
+
3503
+ /*!
3504
+ this operator converts a string into its value (with base = 10)
3505
+ */
3506
+ UInt<value_size> & operator=(const std::string & s)
3507
+ {
3508
+ FromString( s.c_str() );
3509
+
3510
+ return *this;
3511
+ }
3512
+
3513
+
3514
+
3515
+ #ifndef TTMATH_DONT_USE_WCHAR
3516
+
3517
+ /*!
3518
+ this method converts a string into its value
3519
+ */
3520
+ uint FromString(const wchar_t * s, uint b = 10, const wchar_t ** after_source = 0, bool * value_read = 0)
3521
+ {
3522
+ return FromStringBase(s, b, after_source, value_read);
3523
+ }
3524
+
3525
+
3526
+ /*!
3527
+ this method converts a string into its value
3528
+
3529
+ (it returns carry=1 if the value will be too big or an incorrect base 'b' is given)
3530
+ */
3531
+ uint FromString(const std::wstring & s, uint b = 10)
3532
+ {
3533
+ return FromString( s.c_str(), b );
3534
+ }
3535
+
3536
+
3537
+ /*!
3538
+ this operator converts a string into its value (with base = 10)
3539
+ */
3540
+ UInt<value_size> & operator=(const wchar_t * s)
3541
+ {
3542
+ FromString(s);
3543
+
3544
+ return *this;
3545
+ }
3546
+
3547
+
3548
+ /*!
3549
+ this operator converts a string into its value (with base = 10)
3550
+ */
3551
+ UInt<value_size> & operator=(const std::wstring & s)
3552
+ {
3553
+ FromString( s.c_str() );
3554
+
3555
+ return *this;
3556
+ }
3557
+
3558
+ #endif
3559
+
3560
+
3561
+ /*!
3562
+ *
3563
+ * methods for comparing
3564
+ *
3565
+ */
3566
+
3567
+
3568
+ /*!
3569
+ this method returns true if 'this' is smaller than 'l'
3570
+
3571
+ 'index' is an index of the first word from will be the comparison performed
3572
+ (note: we start the comparison from back - from the last word, when index is -1 /default/
3573
+ it is automatically set into the last word)
3574
+ I introduced it for some kind of optimization made in the second division algorithm (Div2)
3575
+ */
3576
+ bool CmpSmaller(const UInt<value_size> & l, sint index = -1) const
3577
+ {
3578
+ sint i;
3579
+
3580
+ if( index==-1 || index>=sint(value_size) )
3581
+ i = value_size - 1;
3582
+ else
3583
+ i = index;
3584
+
3585
+
3586
+ for( ; i>=0 ; --i)
3587
+ {
3588
+ if( table[i] != l.table[i] )
3589
+ return table[i] < l.table[i];
3590
+ }
3591
+
3592
+ // they're equal
3593
+ return false;
3594
+ }
3595
+
3596
+
3597
+
3598
+ /*!
3599
+ this method returns true if 'this' is bigger than 'l'
3600
+
3601
+ 'index' is an index of the first word from will be the comparison performed
3602
+ (note: we start the comparison from back - from the last word, when index is -1 /default/
3603
+ it is automatically set into the last word)
3604
+
3605
+ I introduced it for some kind of optimization made in the second division algorithm (Div2)
3606
+ */
3607
+ bool CmpBigger(const UInt<value_size> & l, sint index = -1) const
3608
+ {
3609
+ sint i;
3610
+
3611
+ if( index==-1 || index>=sint(value_size) )
3612
+ i = value_size - 1;
3613
+ else
3614
+ i = index;
3615
+
3616
+
3617
+ for( ; i>=0 ; --i)
3618
+ {
3619
+ if( table[i] != l.table[i] )
3620
+ return table[i] > l.table[i];
3621
+ }
3622
+
3623
+ // they're equal
3624
+ return false;
3625
+ }
3626
+
3627
+
3628
+ /*!
3629
+ this method returns true if 'this' is equal 'l'
3630
+
3631
+ 'index' is an index of the first word from will be the comparison performed
3632
+ (note: we start the comparison from back - from the last word, when index is -1 /default/
3633
+ it is automatically set into the last word)
3634
+ */
3635
+ bool CmpEqual(const UInt<value_size> & l, sint index = -1) const
3636
+ {
3637
+ sint i;
3638
+
3639
+ if( index==-1 || index>=sint(value_size) )
3640
+ i = value_size - 1;
3641
+ else
3642
+ i = index;
3643
+
3644
+
3645
+ for( ; i>=0 ; --i)
3646
+ if( table[i] != l.table[i] )
3647
+ return false;
3648
+
3649
+ return true;
3650
+ }
3651
+
3652
+
3653
+
3654
+ /*!
3655
+ this method returns true if 'this' is smaller than or equal 'l'
3656
+
3657
+ 'index' is an index of the first word from will be the comparison performed
3658
+ (note: we start the comparison from back - from the last word, when index is -1 /default/
3659
+ it is automatically set into the last word)
3660
+ */
3661
+ bool CmpSmallerEqual(const UInt<value_size> & l, sint index=-1) const
3662
+ {
3663
+ sint i;
3664
+
3665
+ if( index==-1 || index>=sint(value_size) )
3666
+ i = value_size - 1;
3667
+ else
3668
+ i = index;
3669
+
3670
+
3671
+ for( ; i>=0 ; --i)
3672
+ {
3673
+ if( table[i] != l.table[i] )
3674
+ return table[i] < l.table[i];
3675
+ }
3676
+
3677
+ // they're equal
3678
+ return true;
3679
+ }
3680
+
3681
+
3682
+
3683
+ /*!
3684
+ this method returns true if 'this' is bigger than or equal 'l'
3685
+
3686
+ 'index' is an index of the first word from will be the comparison performed
3687
+ (note: we start the comparison from back - from the last word, when index is -1 /default/
3688
+ it is automatically set into the last word)
3689
+ */
3690
+ bool CmpBiggerEqual(const UInt<value_size> & l, sint index=-1) const
3691
+ {
3692
+ sint i;
3693
+
3694
+ if( index==-1 || index>=sint(value_size) )
3695
+ i = value_size - 1;
3696
+ else
3697
+ i = index;
3698
+
3699
+
3700
+ for( ; i>=0 ; --i)
3701
+ {
3702
+ if( table[i] != l.table[i] )
3703
+ return table[i] > l.table[i];
3704
+ }
3705
+
3706
+ // they're equal
3707
+ return true;
3708
+ }
3709
+
3710
+
3711
+ /*
3712
+ operators for comparising
3713
+ */
3714
+
3715
+ bool operator<(const UInt<value_size> & l) const
3716
+ {
3717
+ return CmpSmaller(l);
3718
+ }
3719
+
3720
+
3721
+ bool operator>(const UInt<value_size> & l) const
3722
+ {
3723
+ return CmpBigger(l);
3724
+ }
3725
+
3726
+
3727
+ bool operator==(const UInt<value_size> & l) const
3728
+ {
3729
+ return CmpEqual(l);
3730
+ }
3731
+
3732
+
3733
+ bool operator!=(const UInt<value_size> & l) const
3734
+ {
3735
+ return !operator==(l);
3736
+ }
3737
+
3738
+
3739
+ bool operator<=(const UInt<value_size> & l) const
3740
+ {
3741
+ return CmpSmallerEqual(l);
3742
+ }
3743
+
3744
+ bool operator>=(const UInt<value_size> & l) const
3745
+ {
3746
+ return CmpBiggerEqual(l);
3747
+ }
3748
+
3749
+
3750
+ /*!
3751
+ *
3752
+ * standard mathematical operators
3753
+ *
3754
+ */
3755
+
3756
+ UInt<value_size> operator-(const UInt<value_size> & p2) const
3757
+ {
3758
+ UInt<value_size> temp(*this);
3759
+
3760
+ temp.Sub(p2);
3761
+
3762
+ return temp;
3763
+ }
3764
+
3765
+ UInt<value_size> & operator-=(const UInt<value_size> & p2)
3766
+ {
3767
+ Sub(p2);
3768
+
3769
+ return *this;
3770
+ }
3771
+
3772
+ UInt<value_size> operator+(const UInt<value_size> & p2) const
3773
+ {
3774
+ UInt<value_size> temp(*this);
3775
+
3776
+ temp.Add(p2);
3777
+
3778
+ return temp;
3779
+ }
3780
+
3781
+ UInt<value_size> & operator+=(const UInt<value_size> & p2)
3782
+ {
3783
+ Add(p2);
3784
+
3785
+ return *this;
3786
+ }
3787
+
3788
+
3789
+ UInt<value_size> operator*(const UInt<value_size> & p2) const
3790
+ {
3791
+ UInt<value_size> temp(*this);
3792
+
3793
+ temp.Mul(p2);
3794
+
3795
+ return temp;
3796
+ }
3797
+
3798
+
3799
+ UInt<value_size> & operator*=(const UInt<value_size> & p2)
3800
+ {
3801
+ Mul(p2);
3802
+
3803
+ return *this;
3804
+ }
3805
+
3806
+
3807
+ UInt<value_size> operator/(const UInt<value_size> & p2) const
3808
+ {
3809
+ UInt<value_size> temp(*this);
3810
+
3811
+ temp.Div(p2);
3812
+
3813
+ return temp;
3814
+ }
3815
+
3816
+
3817
+ UInt<value_size> & operator/=(const UInt<value_size> & p2)
3818
+ {
3819
+ Div(p2);
3820
+
3821
+ return *this;
3822
+ }
3823
+
3824
+
3825
+ UInt<value_size> operator%(const UInt<value_size> & p2) const
3826
+ {
3827
+ UInt<value_size> temp(*this);
3828
+ UInt<value_size> remainder;
3829
+
3830
+ temp.Div( p2, remainder );
3831
+
3832
+ return remainder;
3833
+ }
3834
+
3835
+
3836
+ UInt<value_size> & operator%=(const UInt<value_size> & p2)
3837
+ {
3838
+ UInt<value_size> remainder;
3839
+
3840
+ Div( p2, remainder );
3841
+ operator=(remainder);
3842
+
3843
+ return *this;
3844
+ }
3845
+
3846
+
3847
+ /*!
3848
+ Prefix operator e.g ++variable
3849
+ */
3850
+ UInt<value_size> & operator++()
3851
+ {
3852
+ AddOne();
3853
+
3854
+ return *this;
3855
+ }
3856
+
3857
+
3858
+ /*!
3859
+ Postfix operator e.g variable++
3860
+ */
3861
+ UInt<value_size> operator++(int)
3862
+ {
3863
+ UInt<value_size> temp( *this );
3864
+
3865
+ AddOne();
3866
+
3867
+ return temp;
3868
+ }
3869
+
3870
+
3871
+ UInt<value_size> & operator--()
3872
+ {
3873
+ SubOne();
3874
+
3875
+ return *this;
3876
+ }
3877
+
3878
+
3879
+ UInt<value_size> operator--(int)
3880
+ {
3881
+ UInt<value_size> temp( *this );
3882
+
3883
+ SubOne();
3884
+
3885
+ return temp;
3886
+ }
3887
+
3888
+
3889
+
3890
+ /*!
3891
+ *
3892
+ * bitwise operators
3893
+ *
3894
+ */
3895
+
3896
+ UInt<value_size> operator~() const
3897
+ {
3898
+ UInt<value_size> temp( *this );
3899
+
3900
+ temp.BitNot();
3901
+
3902
+ return temp;
3903
+ }
3904
+
3905
+
3906
+ UInt<value_size> operator&(const UInt<value_size> & p2) const
3907
+ {
3908
+ UInt<value_size> temp( *this );
3909
+
3910
+ temp.BitAnd(p2);
3911
+
3912
+ return temp;
3913
+ }
3914
+
3915
+
3916
+ UInt<value_size> & operator&=(const UInt<value_size> & p2)
3917
+ {
3918
+ BitAnd(p2);
3919
+
3920
+ return *this;
3921
+ }
3922
+
3923
+
3924
+ UInt<value_size> operator|(const UInt<value_size> & p2) const
3925
+ {
3926
+ UInt<value_size> temp( *this );
3927
+
3928
+ temp.BitOr(p2);
3929
+
3930
+ return temp;
3931
+ }
3932
+
3933
+
3934
+ UInt<value_size> & operator|=(const UInt<value_size> & p2)
3935
+ {
3936
+ BitOr(p2);
3937
+
3938
+ return *this;
3939
+ }
3940
+
3941
+
3942
+ UInt<value_size> operator^(const UInt<value_size> & p2) const
3943
+ {
3944
+ UInt<value_size> temp( *this );
3945
+
3946
+ temp.BitXor(p2);
3947
+
3948
+ return temp;
3949
+ }
3950
+
3951
+
3952
+ UInt<value_size> & operator^=(const UInt<value_size> & p2)
3953
+ {
3954
+ BitXor(p2);
3955
+
3956
+ return *this;
3957
+ }
3958
+
3959
+
3960
+ UInt<value_size> operator>>(int move) const
3961
+ {
3962
+ UInt<value_size> temp( *this );
3963
+
3964
+ temp.Rcr(move);
3965
+
3966
+ return temp;
3967
+ }
3968
+
3969
+
3970
+ UInt<value_size> & operator>>=(int move)
3971
+ {
3972
+ Rcr(move);
3973
+
3974
+ return *this;
3975
+ }
3976
+
3977
+
3978
+ UInt<value_size> operator<<(int move) const
3979
+ {
3980
+ UInt<value_size> temp( *this );
3981
+
3982
+ temp.Rcl(move);
3983
+
3984
+ return temp;
3985
+ }
3986
+
3987
+
3988
+ UInt<value_size> & operator<<=(int move)
3989
+ {
3990
+ Rcl(move);
3991
+
3992
+ return *this;
3993
+ }
3994
+
3995
+
3996
+ /*!
3997
+ *
3998
+ * input/output operators for standard streams
3999
+ *
4000
+ * (they are very simple, in the future they should be changed)
4001
+ *
4002
+ */
4003
+
4004
+
4005
+ private:
4006
+
4007
+
4008
+ /*!
4009
+ an auxiliary method for outputing to standard streams
4010
+ */
4011
+ template<class ostream_type, class string_type>
4012
+ static ostream_type & OutputToStream(ostream_type & s, const UInt<value_size> & l)
4013
+ {
4014
+ string_type ss;
4015
+
4016
+ l.ToString(ss);
4017
+ s << ss;
4018
+
4019
+ return s;
4020
+ }
4021
+
4022
+
4023
+ public:
4024
+
4025
+
4026
+ /*!
4027
+ output to standard streams
4028
+ */
4029
+ friend std::ostream & operator<<(std::ostream & s, const UInt<value_size> & l)
4030
+ {
4031
+ return OutputToStream<std::ostream, std::string>(s, l);
4032
+ }
4033
+
4034
+
4035
+ #ifndef TTMATH_DONT_USE_WCHAR
4036
+
4037
+ /*!
4038
+ output to standard streams
4039
+ */
4040
+ friend std::wostream & operator<<(std::wostream & s, const UInt<value_size> & l)
4041
+ {
4042
+ return OutputToStream<std::wostream, std::wstring>(s, l);
4043
+ }
4044
+
4045
+ #endif
4046
+
4047
+
4048
+
4049
+ private:
4050
+
4051
+ /*!
4052
+ an auxiliary method for reading from standard streams
4053
+ */
4054
+ template<class istream_type, class string_type, class char_type>
4055
+ static istream_type & InputFromStream(istream_type & s, UInt<value_size> & l)
4056
+ {
4057
+ string_type ss;
4058
+
4059
+ // char or wchar_t for operator>>
4060
+ char_type z;
4061
+
4062
+ // operator>> omits white characters if they're set for ommiting
4063
+ s >> z;
4064
+
4065
+ // we're reading only digits (base=10)
4066
+ while( s.good() && Misc::CharToDigit(z, 10)>=0 )
4067
+ {
4068
+ ss += z;
4069
+ z = static_cast<char_type>(s.get());
4070
+ }
4071
+
4072
+ // we're leaving the last read character
4073
+ // (it's not belonging to the value)
4074
+ s.unget();
4075
+
4076
+ l.FromString(ss);
4077
+
4078
+ return s;
4079
+ }
4080
+
4081
+ public:
4082
+
4083
+
4084
+ /*!
4085
+ input from standard streams
4086
+ */
4087
+ friend std::istream & operator>>(std::istream & s, UInt<value_size> & l)
4088
+ {
4089
+ return InputFromStream<std::istream, std::string, char>(s, l);
4090
+ }
4091
+
4092
+
4093
+ #ifndef TTMATH_DONT_USE_WCHAR
4094
+
4095
+ /*!
4096
+ input from standard streams
4097
+ */
4098
+ friend std::wistream & operator>>(std::wistream & s, UInt<value_size> & l)
4099
+ {
4100
+ return InputFromStream<std::wistream, std::wstring, wchar_t>(s, l);
4101
+ }
4102
+
4103
+ #endif
4104
+
4105
+
4106
+ /*
4107
+ Following methods are defined in:
4108
+ ttmathuint_x86.h
4109
+ ttmathuint_x86_64.h
4110
+ ttmathuint_noasm.h
4111
+ */
4112
+
4113
+ #ifdef TTMATH_NOASM
4114
+ static uint AddTwoWords(uint a, uint b, uint carry, uint * result);
4115
+ static uint SubTwoWords(uint a, uint b, uint carry, uint * result);
4116
+
4117
+ #ifdef TTMATH_PLATFORM64
4118
+
4119
+ union uint_
4120
+ {
4121
+ struct
4122
+ {
4123
+ unsigned int low; // 32 bit
4124
+ unsigned int high; // 32 bit
4125
+ } u_;
4126
+
4127
+ uint u; // 64 bit
4128
+ };
4129
+
4130
+
4131
+ static void DivTwoWords2(uint a,uint b, uint c, uint * r, uint * rest);
4132
+ static uint DivTwoWordsNormalize(uint_ & a_, uint_ & b_, uint_ & c_);
4133
+ static uint DivTwoWordsUnnormalize(uint u, uint d);
4134
+ static unsigned int DivTwoWordsCalculate(uint_ u_, unsigned int u3, uint_ v_);
4135
+ static void MultiplySubtract(uint_ & u_, unsigned int & u3, unsigned int & q, uint_ v_);
4136
+
4137
+ #endif // TTMATH_PLATFORM64
4138
+ #endif // TTMATH_NOASM
4139
+
4140
+
4141
+ private:
4142
+ uint Rcl2_one(uint c);
4143
+ uint Rcr2_one(uint c);
4144
+ uint Rcl2(uint bits, uint c);
4145
+ uint Rcr2(uint bits, uint c);
4146
+
4147
+ public:
4148
+ static const char * LibTypeStr();
4149
+ static LibTypeCode LibType();
4150
+ uint Add(const UInt<value_size> & ss2, uint c=0);
4151
+ uint AddInt(uint value, uint index = 0);
4152
+ uint AddTwoInts(uint x2, uint x1, uint index);
4153
+ static uint AddVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result);
4154
+ uint Sub(const UInt<value_size> & ss2, uint c=0);
4155
+ uint SubInt(uint value, uint index = 0);
4156
+ static uint SubVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result);
4157
+ static sint FindLeadingBitInWord(uint x);
4158
+ static sint FindLowestBitInWord(uint x);
4159
+ static uint SetBitInWord(uint & value, uint bit);
4160
+ static void MulTwoWords(uint a, uint b, uint * result_high, uint * result_low);
4161
+ static void DivTwoWords(uint a,uint b, uint c, uint * r, uint * rest);
4162
+
4163
+ };
4164
+
4165
+
4166
+
4167
+ /*!
4168
+ this specialization is needed in order to not confuse the compiler "error: ISO C++ forbids zero-size array"
4169
+ when compiling Mul3Big2() method
4170
+ */
4171
+ template<>
4172
+ class UInt<0>
4173
+ {
4174
+ public:
4175
+ uint table[1];
4176
+
4177
+ void Mul2Big(const UInt<0> &, UInt<0> &) { TTMATH_ASSERT(false) };
4178
+ void SetZero() { TTMATH_ASSERT(false) };
4179
+ uint AddTwoInts(uint, uint, uint) { TTMATH_ASSERT(false) return 0; };
4180
+ };
4181
+
4182
+
4183
+ } //namespace
4184
+
4185
+
4186
+ #include "ttmathuint_x86.h"
4187
+ #include "ttmathuint_x86_64.h"
4188
+ #include "ttmathuint_noasm.h"
4189
+
4190
+ #endif