Visual characterization method for hash mapping code peculiar smell to 3D space
By converting code quality metrics into hash values through a hash mapping algorithm, code elements are accurately, uniquely, and with quality correlation in 3D space. This solves the problems of information overload and real-time response in large-scale code repositories and improves the efficiency of code quality analysis and maintenance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING UNIV OF TECH
- Filing Date
- 2026-01-12
- Publication Date
- 2026-05-01
AI Technical Summary
Existing two-dimensional and three-dimensional code visualization technologies cannot effectively address the needs for information overload, multi-dimensional quality indicator display, and real-time response in large-scale code repositories, resulting in low efficiency in code quality analysis and maintenance.
The code quality metrics are converted into hash values through a hash mapping algorithm, and then accurately represented using 3D space. Combined with visual attribute mapping, this achieves a unique and quality-correlated distribution of code elements in three-dimensional space, and adjusts the model in real time to eliminate overlaps. It supports multiple programming languages and static analysis tools.
It enables precise code quality analysis and efficient maintenance, provides interactive navigation and an immersive experience, supports real-time dynamic adjustments, and improves the accuracy of code quality analysis and maintenance efficiency.
Smart Images

Figure CN121957579A_ABST
Abstract
Description
A Visual Representation Method for Hash Map Code Odors in 3D Space Technical Field
[0001] This invention relates to the field of software engineering, and in particular to a visualization representation method that uses hash mapping technology to accurately map code structure to 3D space, thereby enhancing the efficiency of code quality analysis and maintenance. Background Technology
[0002] In the field of software engineering, the increasing complexity and dependencies in the code structure of large-scale software systems present developers with key pain points in code quality analysis and subsequent maintenance: First, there is the problem of information overload in large-scale codebases, where the surge in the number of code elements can easily lead to overlapping visualization elements and obscuring key information; second, there is the challenge of integrating and displaying multi-dimensional quality indicators, making it impossible to simultaneously present core quality dimensions such as code smell density, line count, and cyclomatic complexity in a single view; and third, real-time response requirements are difficult to meet, as the visualization layout needs to be recalculated when code changes occur, making it impossible to support efficient dynamic analysis. These pain points directly restrict the accuracy and maintenance efficiency of code quality analysis, becoming a key bottleneck in improving the overall efficiency of the software development process. Currently, code visualization technologies developed to address the above needs can be broadly categorized into two types, but both have significant limitations and cannot completely solve the core pain points: The first type is traditional visualization technology based on two-dimensional (2D) planes: This type of technology is represented by class diagrams, dependency diagrams, and scatter plot matrices (such as the 2D quality dashboard of the static analysis tool SonarQube). Although it has low implementation costs and can provide an overview of the basic structure, it cannot solve the core problems of element overlap and information overload when dealing with large-scale codebases; and it is limited by the 2D plane dimension, so it cannot display multi-dimensional quality indicators at the same time. Developers need to frequently switch between multiple views to obtain complete information, which further exacerbates the pain point of low analysis efficiency. The second category is visualization tools based on three-dimensional (3D) space. These tools are typically represented by CodeCity (mapping code packages to blocks and files to buildings). While they improve the intuitiveness of element distribution through 3D space, they still fail to address the core pain points and instead have new shortcomings: First, they fail to connect with the core requirements of code quality, focusing only on structural information such as file hierarchy and call relationships. They cannot directly identify quality issues such as code smells and high complexity through 3D models, thus becoming disconnected from core analysis needs. Second, they lack real-time response capabilities. They generally use topology layout algorithms such as force-directed layout and hierarchical nesting, which have a time complexity of O(n²) (where n is the number of code elements). When the codebase expands or the code changes, the entire layout needs to be recalculated, which is completely unable to meet the needs of real-time analysis.
[0003] While the two existing technologies have some application value in specific scenarios, neither fully covers large-scale code adaptation and quality indicator correlation. Because the core pain points of code visualization have not been effectively addressed, developers still face problems of low efficiency and insufficient accuracy in code quality analysis and maintenance. There is an urgent need for a technical solution that can overcome these limitations to improve the accuracy of code quality analysis and maintenance efficiency. Summary of the Invention
[0004] This invention discloses a 3D spatial visualization representation algorithm for code smells based on hash mapping. The core of the algorithm is to achieve accurate, unique, and quality-correlated representation of code elements in 3D space by linking code quality indicators through an algorithmic chain. This solves the problems of information overload in traditional 2D visualization and the lack of quality correlation and computational complexity in 3D visualization. The algorithm takes code quality indicators as input and outputs 3D spatial location and visual attributes through calculation and processing, adapting to the real-time representation needs of large-scale code repositories. This invention is achieved through the following technical solutions: Step S1: Calculate and process various code quality indicators, converting them into unique corresponding hash values to ensure that different combinations of quality features can obtain clearly distinguishable identification results; Step S2: Based on the hash values obtained in Step 1, establish a correspondence between hash values and quality level regions, and divide the three-dimensional space into different regions according to the code quality level to achieve accurate matching of hash values to corresponding quality level regions; Step S3: Combine the hash values generated in Step 1 with the original code quality indicator data, and use algorithms to calculate and determine the unique coordinates of each code element in the three-dimensional space to ensure that the coordinate allocation is both related to quality features and unique; Step S4: After the coordinate allocation is completed, detect the overlapping of code element positions in the three-dimensional space. Once an overlap problem is found, dynamically adjust the coordinate positions of the relevant elements to eliminate overlap conflicts and ensure the clarity of the visualization; Step S5: Establish a corresponding mapping relationship between code quality indicators and intuitive visual attributes, converting quality indicators of different dimensions into easily identifiable visual features.
[0005] Furthermore, the 3D spatial visualization representation algorithm for code odors based on hash mapping described in this invention includes the following steps: In step S1, by fusing code quality indicators and element uniqueness information, a hash value that can be directly used for 3D positioning is generated, ensuring that code elements with different quality characteristics are evenly distributed in space and their positions are repeatable.
[0006] The hash value will be calculated according to formula (1):
[0007] in (File Odor Score) ranges from [0,1] and represents the overall severity of bad smells in the code file. It is detected by the static analysis tool (SonarQube). The closer the value is to 1, the more serious the code odor. (File complexity score) ranges from [0,1], and is determined by a static analysis tool (SonarQube). Multiply In practice, this value is placed in the highest bit of the numerical value; therefore, the high bits of the hash value are mainly determined by the anomaly score. Calculations are made by analyzing the nesting levels of the code and method call relationships; a larger value indicates a more complex structure. (Number of bad smells) is a non-negative integer representing the total number of bad smells in the code, as scanned and counted by static analysis tools. The operation mixes the quantified values of different indicators by bitwise XOR (⊕) to avoid hash value aggregation and ensure that the hash value of each code element is unique and strongly correlated with the quality characteristics.
[0008] In step S2: based on the above hash value The system automatically divides the 3D space, assigning code elements of different quality levels to corresponding areas, allowing developers to quickly identify problematic code through these areas.
[0009] When generating the hash value in step S1, by extracting... The high-order values can be used to divide the region into zones. X-axis values between 0 and 250 correspond to a slight odor zone (Zone=0); X-axis values between 251 and 500 correspond to a mild odor zone (Zone=1); X-axis values between 501 and 750 correspond to a moderate odor zone (Zone=2); and X-axis values between 751 and 1000 correspond to a severe odor zone (Zone=3).
[0010] Step S3: Combining the hash value generated in Step 1 with the original code quality index data, the algorithm calculates and determines the unique coordinates of each code element in three-dimensional space, ensuring that the coordinate assignment is both related to quality characteristics and unique. The specific implementation process is as follows: Step S3-1: From the hash value... Different bit segments are extracted. The calculation rules for the initial coordinates in three-dimensional space are as follows: the initial coordinate of the X-axis is calculated by first shifting the hash value to the right, and then performing a bitwise AND operation with the hexadecimal number; the initial coordinate of the Y-axis is calculated by first shifting the hash value to the right, and then performing a bitwise AND operation with the hexadecimal number; the initial coordinate of the Z-axis is calculated by directly performing a bitwise AND operation with the hexadecimal number.
[0011] Step S3-2: Fine-tune the initial position based on code quality indicators to naturally separate high-quality code from problematic code in space: When calculating the X-axis offset, take the spacing adjustment amount and the file odor score. Multiplying the difference after subtracting 0.5 means that the stronger the odor, the greater the positive offset on the X-axis; when calculating the offset on the Y-axis, the spacing adjustment amount and the file complexity score are taken. Multiplying the difference after subtracting 0.5 means that the higher the complexity, the more the Y-axis shifts in the positive direction; the Z-axis offset is set to 0, that is, the Z-axis level remains unchanged, avoiding the destruction of the code structure association, as shown in formula (3).
[0012]
[0013]
[0014] 'a' is the offset amplitude control coefficient, 'g' represents the mesh size, and 'a×g' is the offset of the element due to quality indicators.
[0015] Step S3-3: Superimpose the initial position and the adjustment vector to obtain the unique coordinates: The final unique coordinate position is obtained by adding the initial coordinates and the fine-tuning offset. That is, the final X coordinate is the initial X-axis coordinate plus the X-axis offset, the final Y coordinate is the initial Y-axis coordinate plus the Y-axis offset, and the final Z coordinate is the initial Z-axis coordinate.
[0016] In step S4: When the 3D coordinate distance between two code elements is detected to be less than or equal to a certain interval, a random perturbation algorithm is used to avoid overlap without disrupting the quality correlation. The adjusted position calculation method is as follows: based on the original coordinates, a random value smaller than the grid spacing is added to both the X-axis and Y-axis, while the Z-axis coordinate remains unchanged. This random perturbation algorithm solves the overlap problem while ensuring that the code elements remain within the region corresponding to their quality level, without affecting the developer's judgment of the quality distribution.
[0017] Step S5: Establish a mapping relationship between code quality indicators and intuitive visual attributes, transforming quality indicators of different dimensions into easily identifiable visual features. The specific mapping rules are as follows: For healthy codes, the color is light yellow. For problematic codes, the color is represented by a gradient, with the red and green channels in the RGB values remaining at 255, and the value of the blue channel determined through calculation. This achieves the effect that the heavier the odor score, the smaller the blue channel value and the darker the color.
[0018] The height of a 3D model (tree model) is positively correlated with the number of lines of code; that is, the more lines of code, the taller the model. The number of model branches is positively correlated with cyclomatic complexity; the denser the branches, the more complex the method logic.
[0019] The beneficial effects of this invention are as follows: Compared with the prior art, this invention proposes a method for visually representing code smells in 3D space using hash mapping. It achieves a precise and unique mapping of code elements in 3D space through hash mapping, intuitively presents quality indicators using visual attributes such as color and height, provides interactive navigation and an immersive experience for efficient code maintenance and reduced cognitive burden, can dynamically adjust the 3D tree model in real time, supports multiple programming languages, and integrates static analysis tools for comprehensive problem detection, helping developers quickly locate and promptly fix problems. Attached Figure Description
[0020] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0021] Figure 1 is a flowchart of the method for visualizing hash mapping code in 3D space according to the present invention.
[0022] Figure 2 is a schematic diagram illustrating the effects of the specific invention.
[0023] Figure 3 shows the actual effect of 3D model generation according to an embodiment of the present invention. Detailed Implementation
[0024] To make the objectives and technical solutions of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of this invention. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0025] This invention discloses a method for visualizing code elements in 3D space using hash mapping, as shown in Figure 2. The method includes: Step S1: Implementing a hash mapping algorithm to accurately map code elements (such as classes, methods, and files) to specific locations in 3D space. This includes: Step S1-1: Obtaining input; concatenating the unique identifier of the code element, such as the fully qualified name of a Java class: com.tech.code.ASCIIPropertyListParser (hereinafter referred to as Parser), with the location information src / main / java / tech / code / ASCIIPropertyListParser.java using the separator "|", to obtain the string S="com.tech.code.User|src / main / java / com / tech / code / ASCIIPropertyListParser.java"; Step S1-2: Using a custom string hash algorithm; first concatenating the unique identifier of the code element with the file path to form the string S, then calculating the sum M of the ASCII codes of S, and finally M... The initial hash value is obtained by taking the modulo operation, and then summed with the line number of the code element in the codebase to obtain the final hash value. (The code element Parser hash value is 3,092,897,123).
[0026] Step S2: Distribute code elements into different regions according to their quality level to ensure developers can quickly identify problematic code. Specifically, this includes: Step S2-1: Region Division: The X-axis in 3D space is defined as the quality level axis, with the following division rules: X-axis values between 0 and 250 correspond to a slightly problematic zone (Zone=0); X-axis values between 251 and 500 correspond to a mildly problematic zone (Zone=1); X-axis values between 501 and 750 correspond to a moderately problematic zone (Zone=2); X-axis values between 751 and 1000 correspond to a severely problematic zone (Zone=3). The Y-axis is defined as the complexity axis (value range 0 to 2000); the Z-axis is defined as the hierarchy axis (value range 0 to 2000, corresponding to the package level of the codebase). Based on the above calculation method, the code element Parser is classified into the severely problematic zone.
[0027] Step S2-2, Mesh Size Determination: The mesh cell size g (i.e., the side length of each mesh on the X or Y axis) is determined based on the total number of files in the code repository: When the total number of files is less than or equal to N (N is 10000), g is set to 50 (spatial units); when the total number of files is greater than 0.1N but less than or equal to N, g is set to 20; when the total number of files N is greater than N, g is set to 10. This ensures that each mesh contains only one code element, avoiding initial overlap. Since the total number of files N in the code repository containing the code element Parser is 2437, the mesh cell size g is set to 20.
[0028] Step S3: Calculate the coordinates according to the coordinate extraction rules of the previous technical solution, where a is 0.25: Using the code element Parser (its hash value) Taking (3,092,897,123) as an example, the X-axis coordinate is calculated by shifting the hash value 22 bits to the right and then performing a bitwise AND operation with the hexadecimal number 3FF, resulting in 753; the Y-axis coordinate is calculated by shifting the hash value 11 bits to the right and then performing a bitwise AND operation with the hexadecimal number 7FF, resulting in 1502; the Z-axis coordinate is calculated by directly performing a bitwise AND operation with the hexadecimal number 7FF; the final initial coordinates are (753, 1502,867).
[0029] Step S4, Overlap Detection and Adjustment: When a new element is detected whose coordinates are less than or equal to 0.5 times the grid cell size g of an existing element, a random offset of ±0.1 times g is applied to the new element on the X and Y axes (e.g., when g is 20, the offset range is ±2), while the Z axis remains unchanged. For example, if the initial coordinates (753, 1502, 867) overlap with an existing element, the adjusted coordinates become (754.5, 1501.2, 867).
[0030] Step S5: Represent code quality indicators through visual attributes such as color, height, and branch density to help developers intuitively identify quality problems in the code: Step S5-1: Color mapping: The color mapping rules are shown in formula (3). For file odor scores less than or equal to health code, The value is set to 0.25, its color is light yellow, and the RGB values can be (255, 255, 150). For files with an odor score greater than... The problematic code uses gradient colors, with the red and green channels in the RGB values remaining at 255. The blue channel value is calculated as follows: take q, subtract p, multiply by the file odor score, and subtract... Divide by 1- The quotient is given by q, where q is 100 and p is 50. Since the file odor score of the code element Parser is 0.72, its RGB value is calculated as (255, 255, 68.67), and the color is dark yellow.
[0031]
[0032] Step S5-2, Height Mapping: The height (in spatial units) of the 3D tree model is positively correlated with the number of lines of code (LOC). The specific calculation method is: height equals the number of lines of code divided by 100 (if less than 100 lines, it is calculated as 100 lines, meaning the height is at least 1). In this case, the Parser element has 280 lines of code, resulting in a calculated height of 2.8. Therefore, the height of this 3D tree model is set to 2.8.
[0033] Step S5-3, Branch Density Mapping: The correspondence between the number of branches B and the cyclomatic complexity CC of the method is as follows: when the cyclomatic complexity is less than or equal to 3, the number of branches is 2; when the cyclomatic complexity is between 4 and 5, the number of branches is 3; when the cyclomatic complexity is between 6 and 7, the number of branches is 4; when the cyclomatic complexity is greater than or equal to 8, the number of branches is 5. The cyclomatic complexity of the code element Parser is 4, therefore the corresponding number of branches is 3, and the number of branches in its tree model is set to 3.
[0034] The code element Parser is located in the severely smelly area. Its RGB value is (255, 255, 68.67), its color is dark yellow, its height is 2.8, and its number of branches is 3. It corresponds to a unique tree model in 3D space. Developers can click on the tree model to view detailed quality metrics for the corresponding code element. For example, clicking on the tree model corresponding to the code element Parser will display detailed information such as the number of lines of code for that class being 280, its cyclomatic complexity being 4, its code smell density being 0.72, and its number of methods being 29.
Claims
1. A method for visualizing hash mapping code in 3D space, characterized in that... Includes the following steps: Step S1: Calculate and process each code quality indicator, converting it into a unique corresponding hash value to ensure that different combinations of quality features can produce clearly distinguishable identification results. Step S2: Based on the hash values obtained in Step 1, establish a correspondence between hash values and quality level regions. Divide the three-dimensional space into different regions according to code quality levels to achieve accurate matching of hash values to corresponding quality level regions. Step S3: Combining the hash values generated in Step 1 with the original code quality indicator data, use algorithms to calculate and determine the unique coordinates of each code element in the three-dimensional space, ensuring that the coordinate allocation is both related to quality features and unique. Step S4: After coordinate allocation, detect overlapping positions of code elements in the three-dimensional space. Once an overlap problem is detected, dynamically adjust the coordinate positions of the relevant elements to eliminate overlap conflicts and ensure the clarity of the visualization. Step S5: Establish a mapping relationship between code quality indicators and intuitive visual attributes, converting quality indicators of different dimensions into easily identifiable visual features.
2. The method according to claim 1, characterized in that, In step S1: By fusing code quality indicators and element uniqueness information, a hash value that can be directly used for 3D positioning is generated; the hash value is calculated according to formula (1): Among them, the document odor score The value ranges from [0,1], representing the overall severity of code smells in the file, detected by static analysis tools. A value closer to 1 indicates a more severe code smell; file complexity score. The value range is [0,1], detected by static analysis tools; the number of off-odors. It is a non-negative integer representing the total number of code smells scanned and counted by static analysis tools; the operation is performed by bitwise XOR ⊕ to mix the quantified values of different indicators.
3. The method according to claim 1, characterized in that, In step S2: based on the above hash value The system automatically divides the 3D space, assigning code elements of different quality levels to corresponding regions, allowing developers to quickly identify problematic code. During the hash value generation in step S1, the system extracts... The high-order value is used to divide the region into zones. X-axis values between 0 and 250 correspond to the zone of slight odor (Zone=0); X-axis values between 251 and 500 correspond to the zone of mild odor (Zone=1); X-axis values between 501 and 750 correspond to the zone of moderate odor (Zone=2); and X-axis values between 751 and 1000 correspond to the zone of severe odor (Zone=3).
4. The method according to claim 1, characterized in that, Step S3: Combining the hash value generated in Step 1 with the original code quality index data, the algorithm calculates and determines the unique coordinates of each code element in three-dimensional space, ensuring that the coordinate assignment is both related to quality characteristics and unique; the specific implementation process is as follows: Step S3-1: From the hash value Extract different bit segments; the initial coordinate calculation rules for the three-dimensional space are as follows: the initial coordinate of the X-axis is calculated by first shifting the hash value to the right, and then performing a bitwise AND operation with the hexadecimal number; the initial coordinate of the Y-axis is calculated by first shifting the hash value to the right, and then performing a bitwise AND operation with the hexadecimal number; the initial coordinate of the Z-axis is calculated by directly performing a bitwise AND operation with the hexadecimal number; step S3-2, fine-tune the initial position according to the code quality index to naturally separate high-quality code and problematic code in space: when calculating the offset of the X-axis, take the spacing adjustment amount and the file smell score. Multiplying the difference after subtracting 0.5 means that the stronger the odor, the greater the positive offset on the X-axis; when calculating the offset on the Y-axis, the spacing adjustment amount and the file complexity score are taken. Multiplying the difference after subtracting 0.5 means that the higher the complexity, the more the Y-axis shifts in the positive direction; the Z-axis offset is set to 0, that is, the Z-axis level remains unchanged, avoiding the destruction of the code structure association, as shown in formula (3); a is the offset amplitude control coefficient, g represents the grid size, and a×g is the offset of the element due to the quality index; Step S3-3: Superimpose the initial position and the adjustment vector to obtain the unique coordinates: The final unique coordinate position is obtained by adding the initial coordinates and the fine-tuning offset, that is, the final X coordinate is the initial X-axis coordinate plus the X-axis offset, the final Y coordinate is the initial Y-axis coordinate plus the Y-axis offset, and the final Z coordinate is the initial Z-axis coordinate.
5. The method according to claim 1, characterized in that, In step S4: When the 3D coordinate distance between two code elements is less than or equal to a certain spacing, a random perturbation algorithm is used to avoid overlap without destroying the quality association. The adjusted position is calculated as follows: based on the original coordinates, a random value less than the grid spacing is added to the X-axis and Y-axis respectively, while the Z-axis coordinate remains unchanged.
6. The method according to claim 1, characterized in that, Step S5: Establish a mapping relationship between code quality indicators and intuitive visual attributes, transforming quality indicators of different dimensions into easily identifiable visual features. The specific mapping rules are as follows: For healthy codes, the color is light yellow; for problematic codes, the color is represented by a gradient, with the red and green channels in the RGB values remaining at 255, and the value of the blue channel determined through calculation. This achieves the effect that the heavier the odor score, the smaller the blue channel value and the darker the color. The height of the 3D model is positively correlated with the number of lines of code, that is, the more lines of code, the taller the model. The number of model branches is positively correlated with cyclomatic complexity, and the denser the branches, the more complex the method logic.