Disposable electronic price computing scale and anti-counterfeiting and anti-cheating traceability system
By improving the data structure and storage method of hash tables, the data loss problem caused by hash collisions in the electronic scale anti-cheating system is solved, and efficient hash table generation and data traceability are realized, reducing security risks.
Patent Information
- Application Number
- CN202510147507.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-11
- Publication Date
- 2025-03-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing electronic scale anti-cheating system is prone to hash collisions when building hash tables, resulting in loss of verification data and posing a security risk.
The first hash function of the cuckoo hash algorithm is used to generate a hash table, and by analyzing the probability distribution of the linked list length of the stored address in the hash table, the average query length and predicted query time of the data to be stored are determined, and the storage method is selected based on this information to generate a hash table.
By improving the data structure and storage method of hash tables, data loss is avoided, the efficiency of hash table generation is improved, data traceability is ensured, and security risks are reduced.
Smart Images

Figure CN119599694A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electronic scale anti-cheating, and in particular to a disposable electronic pricing scale and an anti-counterfeiting and anti-cheating traceability system. Background Art
[0002] Disposable electronic scales are designed to prevent disassembly and tampering, and are non-detachable. Once disassembly or tampering is attempted, the electronic scale will be scrapped and the tampering record will be uploaded to the system, which can effectively prevent weighing cheating in market transactions. In the actual operation of disposable electronic scales, the electronic scale's anti-cheating traceability system will collect the electronic scale's operating data in real time, and cheating can be discovered through the operating data when the electronic scale is inspected.
[0003] In order to reduce the storage burden of the host computer, the host computer system stores the data in the local storage unit of the electronic scale, and after generating a hash table, uploads the hash table to the host computer system. By verifying the local storage data of the electronic scale with the hash table of the host computer system, the electronic scale storage data is traced, effectively preventing data tampering while reducing the burden of the host computer. However, when constructing a hash table in the local storage of the electronic scale, the problem of hash collision will occur. Among the existing methods for solving hash collision, the cuckoo hash algorithm is a high-efficiency algorithm that is suitable for electronic scale microprocessors with limited computing power. However, in order to ensure high efficiency, the cuckoo hash algorithm may discard part of the stored data when storing and generating a hash table for data, which will cause the loss of verification data, making it impossible to trace the data, and causing safety hazards. Summary of the invention
[0004] In order to solve the above technical problems, a disposable electronic pricing scale and an anti-counterfeiting and anti-cheating traceability system are provided to solve the existing problems.
[0005] The solution to the technical problem of the present application is to provide a disposable electronic price computing scale anti-counterfeiting and anti-cheating traceability system, the system comprising: The electronic scale data collection module is used to obtain the weighing time and weighing data of all collected electronic price computing scales in each time period as the data to be stored in each time period; The hash table generation module is used to generate a hash table, including: (1) Using the first hash function of the cuckoo hash algorithm, the length of the linked list of the storage address of the hash table corresponding to the data to be stored in each period is recorded as the critical length; according to the probability distribution of different linked list lengths of the storage address in the hash table and the probability distribution trend of all linked list lengths of the storage address greater than the critical length, the average query length of the data to be stored in each period is determined; (2) Analyze the time consumed for multiple operations on the data to be stored in each period, as well as the time consumed for querying the linked list in the hash table, and determine the query time function of the data to be stored in each period in combination with the average query length; (3) Analyze the probability that the length of a linked list of a storage address is less than the critical length to determine the query probability function, and combine it with the query time function to determine the predicted query time of the data to be stored in each time period; (4) Analyze the probability distribution of the length of the linked list of storage addresses in the hash table that is less than the critical length in each time period, and the length difference between the length of the linked list of the remaining storage addresses in the hash table and the critical length, and determine the verification time difference of the data to be stored in each time period; (5) determining a hash evaluation coefficient of the data to be stored in each time period according to the difference in computing speed between the built-in microprocessor in the electronic price computing scale and the host computer system, and the difference between the verification time difference and the predicted query time; selecting a storage method for the data to be stored based on the hash evaluation coefficient to obtain a hash table; The traceability verification module is used to compare the stored data in the stored hash table with the local stored data of the electronic pricing scale to perform traceability verification on the stored data.
[0006] Preferably, determining the average query length of the data to be stored in each time period includes: Counting the number of all storage addresses with the same linked list length in the hash table in each time period, and taking the ratio between the number and the number of all storage addresses in the hash table as the occurrence probability of each linked list length in each time period; The sum of the occurrence probabilities of all linked list lengths of storage addresses less than the critical length in the hash table of each time period is used as the short chain probability of the data to be stored in each time period; The sum of the occurrence probabilities of all chain list lengths of storage addresses greater than or equal to the critical length in the hash table of each time period is used as the long chain probability of the data to be stored in each time period; The ratio of the occurrence probability of each chain length greater than or equal to the critical length in the hash table of each time period to the long chain probability is recorded as the query occurrence probability of each chain length in each time period; The product of the query occurrence probability of each linked list length in each time period and the corresponding linked list length is recorded as the first product; the sum of the first products of all linked list lengths of the storage addresses in the hash table in each time period is taken as the average query length of the data to be stored in each time period.
[0007] Preferably, the step of determining the query time-consuming function of the data to be stored in each time period includes: ,in, is the query time function of the data to be stored in the tth period, E is the linked list query time, and the linked list query time is obtained by: constructing an initial linked list of a preset length, querying each data in the initial linked list, and taking the average of all query times of the initial linked list as the linked list query time. is the hash time of the data to be stored in the tth period. The hash time is the time consumed by the first hash function of the cuckoo hash algorithm to calculate the data to be stored. n is the number of queries. is the average query length of the data to be stored in the tth period.
[0008] Preferably, the query probability function is: ,in, is the short chain probability of the data to be stored in the tth period, n is the number of queries, is the data to be stored in the tth period.
[0009] Preferably, the predicted query time for the data to be stored in each time period is determined by the following calculation formula: ,in, is the predicted query time for the data to be stored in period t, R is the preset maximum query number, is the query probability function of the data to be stored in the tth period, It is the query time-consuming function of the data to be stored in the tth period.
[0010] Preferably, the step of determining the verification time difference of the data to be stored in each time period includes: ,in, is the verification time difference of the data to be stored in period t, The length of the linked list storing the address for the tth period is The verification occurrence probability is the ratio of the occurrence probability of each chain length less than the critical length in the hash table of each time period to the probability of the short chain; E is the chain query time, is the critical length of the tth period.
[0011] Preferably, the hash evaluation coefficient of the data to be stored in each time period is expressed as: ,in, is the hash evaluation coefficient of the data to be stored in the tth period, is the number of all electronic price-calculating scales managed by the host computer system in period t, is the verification time difference of the data to be stored in period t, is the predicted query time of the data to be stored in the tth period, LO is the operation speed of the built-in microprocessor in the electronic price computing scale, and SY is the operation speed of the host computer system.
[0012] Preferably, obtaining the hash table includes: When there is no hash collision in the data to be stored, the data to be stored is directly stored in the linked list of the storage address of the corresponding hash table; when there is a hash collision in the data to be stored, if the hash evaluation coefficient of the data to be stored in each time period is greater than the preset judgment threshold, the original storage data of the head node of the linked list in the storage address of the corresponding hash table is squeezed out; otherwise, the data to be stored is inserted into the linked list of the storage address to generate a hash table.
[0013] Preferably, the tracing and verifying the stored data includes: The locally stored data of the electronic pricing scale is obtained, recorded as the data to be traced, and the hash value of the data to be traced is calculated by using the first hash function in the cuckoo hash algorithm, recorded as the first hash value; Search the linked list of the storage address corresponding to the first hash value in the hash table for the data to be traced. If the data does not exist, use the second hash function in the cuckoo hash algorithm to calculate the hash value of the data to be traced, which is recorded as the second hash value; The data to be traced is searched in the linked list of the storage address corresponding to the second hash value in the hash table. If the data does not exist, it is determined that the traceability verification has failed; otherwise, it is determined that the traceability verification has succeeded.
[0014] In a second aspect, an embodiment of the present application further provides a disposable electronic price computing scale, wherein the anti-counterfeiting and anti-cheating traceability of the electronic price computing scale is implemented by using any one of the disposable electronic price computing scale anti-counterfeiting and anti-cheating traceability systems described above.
[0015] This application has at least the following beneficial effects: The present application improves the hash table by changing the data structure storage mode of the hash table into a linked list structure storage mode, so that each storage address in the hash table can store multiple data indexes; secondly, the probability distribution of different linked list lengths of storage addresses in the hash table, except for the storage address corresponding to the data to be stored, and the probability distribution trend of all linked list lengths of storage addresses greater than the critical length are analyzed to determine the average query length of the data to be stored in each time period; and the query time function of the data to be stored in each time period is determined based on the time consumed for multiple operations on the data to be stored in each time period and the time for querying the linked list in the hash table. The beneficial effect lies in analyzing the distribution of linked list lengths of different storage addresses in the hash table, reflecting the distribution of data storage in the hash table. Secondly, the time consumed for multiple searches in the hash table when a hash collision occurs is considered; the data to be stored in each time period is determined. The predicted query time has the beneficial effect of taking into account the computing resources consumed by the traditional cuckoo hash method to solve hash collisions; determining the verification time difference of the data to be stored in each time period, which has the beneficial effect of analyzing the degree of shortening of the subsequent traceability verification time when the hash collision is solved by the traditional cuckoo hash method, so as to reflect the computing burden of hash table traceability verification and the efficiency of hash table generation; determining the hash evaluation coefficient of the data to be stored in each time period; based on the hash evaluation coefficient, selecting the storage method of the data to be stored to obtain a hash table, which has the beneficial effect of evaluating the efficiency of hash table generation when different data storage methods are used to solve hash collisions when storing the data to be stored, and therefore selecting an efficient method for solving hash collisions, while ensuring that the data is not abandoned, improving the efficiency of hash table generation, ensuring that the data can be traced, and reducing the security risks caused by the abandonment of some data. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The following is a further detailed description of the anti-counterfeiting and anti-cheating traceability system for a disposable electronic pricing scale of the present application in conjunction with the accompanying drawings.
[0017] Figure 1 A block diagram of a disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system provided by one embodiment of the present application; Figure 2 A flowchart of the steps of a hash table generation module provided in one embodiment of the present application; Figure 3 A flowchart of the steps of an average query length of data to be stored in each time period provided by an embodiment of the present application; Figure 4 A flowchart of a data storage process provided for one embodiment of the present application. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the following is a further detailed description of a disposable electronic price computing scale and an anti-counterfeiting and anti-cheating traceability system proposed in the present application in combination with the accompanying drawings and implementation examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0019] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.
[0020] See also Figure 1 , which shows a block diagram of a disposable electronic price computing scale anti-counterfeiting and anti-cheating traceability system provided by an embodiment of the present application. The system includes: an electronic scale data acquisition module, a hash table generation module, and a traceability verification module.
[0021] The electronic scale data acquisition module is located in the electronic price computing scale and is used to obtain the weighing time and weighing data of all collected electronic price computing scales in each time period as the data to be stored in each time period.
[0022] During the operation of the disposable electronic scale, in order to prevent the weighing data from being tampered with or detect external program interference, the weighing data and other monitoring data of the electronic scale will be recorded, and the recorded data will be generated into a hash table for storage. When the disposable electronic scale is running, the data acquisition module on the electronic scale will collect the time and weighing data of each weighing, and the collection time is T. All the weighing time and weighing data collected within the T period are used as data to be stored.
[0023] Preferably, in this embodiment, the collection time is 1 minute. As other implementation modes, the implementer can set it according to the actual situation. All weighing times and weighing data collected by the disposable electronic scale from time t to time t+1 are used as the data to be stored in the tth time period. Therefore, when the disposable electronic scale is operating, a piece of data to be stored is obtained every T time, and the data to be stored in each time period is obtained.
[0024] At this point, the data to be stored in each time period is obtained.
[0025] The hash table generation module is located in the electronic price computing scale and is used to generate a hash table through the data to be stored in the electronic price computing scale and transmit the generated hash table to the upper computer system.
[0026] Further, the step flow chart of the hash table generation module provided in this embodiment is as follows: Figure 2 shown.
[0027] Step 1, using the first hash function of the cuckoo hash algorithm, record the linked list length of the storage address of the hash table corresponding to the data to be stored in each time period as the critical length; according to the probability distribution of different linked list lengths of the storage address in the hash table, and the probability distribution trend of all linked list lengths of the storage address greater than the critical length, determine the average query length of the data to be stored in each time period.
[0028] The cuckoo hash algorithm needs to use two hash functions. In this embodiment, the cuckoo hash algorithm uses two hash functions, SHA-2 and SHA-3, for analysis, where the SHA-2 hash function is the first hash function and the SHA-3 hash function is the second hash function.
[0029] It can be understood that in this embodiment, two hash functions, SHA-2 and SHA-3, are used for analysis, among which the cuckoo hash algorithm is a well-known technology and will not be described in detail here. As other implementation methods, implementers can adopt other methods of the existing technology, such as the SHA-1 hash function, etc. This embodiment does not impose any special restrictions on this.
[0030] In this embodiment, the SHA-2 hash function is denoted by , denote the SHA-3 hash function as , No. The data to be stored in the time period is recorded as When generating a hash table using the cuckoo hash algorithm, the SHA-2 hash function is used to calculate the data to be stored. Hash value ; Lookup in an existing hash table Check whether the data address is empty. Is there data stored at the location? If If the location is empty, the data to be stored will be If the hash table is not empty, it means a hash collision has occurred. The way to handle hash collision in the traditional cuckoo hash algorithm is as follows: The traditional cuckoo hash algorithm will store the data Placed at data address At the location of Original data of location squeeze out; squeeze out data Calculate the hash value using the SHA-3 hash function , and will be squeezed out of the data Store new data address In the position, if The position is empty, and the data is passed. The process of generating a hash table; if If the location is not empty and data is stored, it is judged that a chain collision has occurred. At this time, the new data address The original data at the location As the new squeezed out data, it will occupy other data positions, and so on. When the chain collision reaches a certain number of times, Cuckoo Hash will directly delete the last squeezed out data.
[0031] Therefore, the traditional algorithm will cause data loss and make the data untraceable. Therefore, this embodiment adopts a chained hash table method to introduce a chained list into the hash table. Then, each storage address in the hash table is a chained list, and the data to be discarded is stored in the data address in the form of a chained list to avoid data loss.
[0032] In the hash table, each storage address is a linked list. Therefore, when a hash collision occurs, this embodiment performs a chaining operation on the data to be stored. There are two processing methods, specifically: Method 1: Data to be stored Remove the head node of the linked list that occupies the hash collision position, and process the squeezed data of the head node of the linked list according to the method of traditional cuckoo hash algorithm to process hash collision; Method 2: Data to be stored The new head of the linked list, which is the location of the hash collision, is inserted into the linked list; Based on the above analysis, in method 2, a new node of the linked list is constructed to store the data in the hash table, thereby solving the data loss problem of the traditional cuckoo hash algorithm. However, when a chain collision occurs at a storage address in the hash table, the length of the linked list of the storage address is too long, which will cause the subsequent traceability verification through the hash table to be more complicated and computationally burdensome. Therefore, when the length of the linked list of a storage address is too long, the data to be stored will be The first method is adopted to avoid the problem that the linked list of a certain storage address is too long. Therefore, it is determined whether the linked list of each storage address is too long by the data storage distribution in the hash table.
[0033] Secondly, since the hash table stores data in the form of a linked list, the shortest linked list should be selected for storage when storing data. However, due to limited computing resources, when querying the shortest linked list, if multiple hash functions are used for the stored data, all possible storage linked lists will be found, which will bring a large computing burden when generating the hash table. Therefore, when a hash collision occurs, the data storage situation of the hash table is used to determine what method to use to handle the hash collision.
[0034] First, analyze the distribution of linked lists of the same length in the hash table and determine the probability of occurrence of each length to reflect the distribution of data storage in the hash table, specifically: Counting the number of all storage addresses with the same linked list length in the hash table in each time period, and taking the ratio between the number and the number of all storage addresses in the hash table as the occurrence probability of each linked list length in the hash table in each time period; It should be noted that the number of storage addresses is related to the setting parameters of the hash function. In this embodiment, the setting parameters of the hash function are 32 bits. Therefore, the number of all storage addresses in the hash table is As other implementation methods, implementers can set them according to actual conditions.
[0035] In this embodiment, it is assumed that the number of all storage addresses in the hash table is recorded as A. The length of the linked list in the time period hash table is The number of storage addresses is denoted as , then The length of the time period list is The probability of occurrence of the linked list is: .
[0036] It should be noted that, in the data storage distribution of the hash table, the greater the probability of the appearance of a linked list with a short length, the more method 1 should be used to deal with the hash collision problem.
[0037] Further, the length of the linked list of the remaining storage addresses in the hash table, except for the storage address corresponding to the data to be stored, is analyzed. The comparison of the length of the linked lists corresponding to the storage addresses is used to reflect the probability of occurrence of long linked lists and short linked lists in the hash table, specifically: Use the SHA-2 hash function of the Cuckoo Hash algorithm to obtain the data to be stored The length of the linked list corresponding to the storage address is recorded as the critical length; The sum of the occurrence probabilities of all linked list lengths of storage addresses less than the critical length in the hash table of each time period is used as the short chain probability of the data to be stored in each time period; The sum of the occurrence probabilities of all chain list lengths of storage addresses greater than or equal to the critical length in the hash table of each time period is used as the long chain probability of the data to be stored in each time period; In this embodiment, the data to be stored The length of the linked list corresponding to the storage address, that is, the critical length, is recorded as ;No. The probability of a short chain of data to be stored in a period is: ,in, is the short chain probability of the data to be stored in the tth period, expressed as The number of timeslots in the hash table is less than The sum of the occurrence probabilities of all linked list lengths of the storage address, Data to be stored The length of the linked list corresponding to the storage address, that is, the critical length, For the The length of the linked list in the time period hash table is The probability of occurrence of the linked list; Accordingly, The probability of a long chain of data to be stored in a period is: ,in, For the The probability of a long chain of data to be stored in the time period, indicating the In the time period hash table, the value is greater than or equal to The sum of the occurrence probabilities of all linked list lengths of the storage address, Data to be stored The length of the linked list corresponding to the storage address, For the The length of the longest linked list in the time period hash table, For the The length of the linked list storing addresses in the time period hash table is The probability of occurrence.
[0038] Further, based on the long chain probability, the query time is determined to reflect the time consumption of searching for a linked list with a length greater than or equal to the critical length when searching for a linked list with a length less than the critical length in the hash table, specifically: The length of the hash table in each time period is greater than or equal to the critical length. The ratio of the occurrence probability of each chain length to the long chain probability is recorded as the query occurrence probability of each chain length in each time period; The product of the query occurrence probability of each linked list length in each time period and the corresponding linked list length is recorded as the first product; The sum of the first products of the lengths of all linked lists of storage addresses in the hash table in each time period is used as the average query length of the data to be stored in each time period; In this embodiment, the average query length of the data to be stored in each period is: ,in, For the The average query length of the data to be stored in the period, For the The length of the linked list of time period storage addresses is The probability of occurrence, For the The probability of a long chain of data to be stored in the time period is In the time period hash table, the value is greater than or equal to The sum of the occurrence probabilities of all linked list lengths of the storage address, For the The length of the longest linked list in the time period hash table, To query the probability of occurrence, is the first product, To preset a value greater than 0, the value is 0.001 in this embodiment to avoid the denominator being 0.
[0039] It should be noted that the query occurrence probability reflects the search ratio in the t period. In the process of increasing the length of the linked list of the shortest storage address, the probability of the storage address corresponding to the linked list length k; the average query length of the data to be stored in each period is reflected in the search ratio in the hash table in the tth period. When the length of the linked list of storage addresses is short, it is possible to search for a linked list of storage addresses whose length is greater than or equal to The average search length when What is solved is the mathematical expectation value, so as to analyze and find the time consumed later.
[0040] Further, the flowchart of the steps of the average query length of the data to be stored in each time period provided by this embodiment is as follows: Figure 3 shown.
[0041] At this point, the average query length of the data to be stored in each time period is obtained.
[0042] Step 2: Analyze the time consumed for multiple operations on the data to be stored in each time period and the time for querying the linked list in the hash table, and determine the query time function of the data to be stored in each time period in combination with the average query length.
[0043] Further, based on the average query length, all the search time consumed each time a linked list length shorter than the critical length is searched is analyzed, and a query time-consuming function is constructed, specifically: Treat the stored data as the SHA-2 hash function of the Cuckoo Hash algorithm The time consumed for one calculation is recorded as the hash time of the data to be stored in each period; It should be noted that the method of calculating the hash time using a hash function is a well-known technology and will not be described in detail here.
[0044] Construct an initial linked list of preset length, query each data in the initial linked list, and record the average of all query times of the initial linked list as the linked list query time; It should be noted that, assuming that an initial linked list with a length of 20 is constructed, the 20 data in the linked list are queried respectively, and the average of the query time of all data is recorded as the linked list query time. Assuming that the linked list query time is recorded as E, a stored data is at the Mth position of the linked list, then the computing time consumed to obtain the stored data is .
[0045] The query time-consuming function of the data to be stored in each period is: ,in, is the query time-consuming function of the data to be stored in the tth period, indicating the query time of n queries in the tth period, E is the linked list query time, is the hash time of the data to be stored in period t, n is the number of queries, is the average query length of the data to be stored in the tth period.
[0046] It should be noted that the larger the average query length, the longer it takes to query data with a longer linked list length of the hash table storage address. Secondly, the longer the storage data length, the longer the resulting hash time, and the more queries, the longer the resulting query time, which reflects that the longer the time consumed after performing n queries.
[0047] At this point, the query time-consuming function of the data to be stored in each time period is obtained.
[0048] Step 3, analyzing the probability of finding a linked list of a storage address with a length less than the critical length to determine the query probability function, and combining the query time function to determine the predicted query time of the data to be stored in each time period.
[0049] Furthermore, when dealing with hash collisions, the first method is to find a linked list of storage addresses that is shorter than the linked list length of the current storage address. However, querying a shorter linked list will consume the computing resources of the electronic price scale. Therefore, by constructing a predicted query time to reflect the consumed computing resources, if the predicted query time is smaller, it means that it is easier to find a shorter linked list, and the first method should be used for processing at this time; therefore, when the hash table is queried multiple times, the linked list length of the storage address in the hash table is analyzed to be less than The probability of finding the storage address in the hash table is less than The query time is: In this embodiment, the probability mass function of the binomial distribution is used. Therefore, the n queries are independent, since A is is a very large number, then the linked list that has been queried The effect of is small or even no effect, that is, the probability It will not be affected by the number of linked list queries n, thus determining the query probability function .
[0050] The probability mass function of the binomial distribution is: , when r=1, it means that we only need to find a linked list with a storage address less than That's it, let , which means less than The probability of occurrence of the linked list length of the storage address, and the final query probability function is a function of the independent variable n, and the specific formula is: ,in, is the query probability function of the data to be stored in the tth period, indicating that when querying n times in the tth period, the length of the linked list of a storage address is less than The probability of is the short chain probability of the data to be stored in the tth period.
[0051] It should be noted that the probability mass function of the binomial distribution is a well-known technology and will not be described in detail here.
[0052] Further, the prediction query time is calculated as: ,in, is the predicted query time of the data to be stored in the tth period, indicating that the length of the linked list for searching a storage address in the tth period is less than The predicted query time, R is the preset maximum query number, in this embodiment, the preset maximum query number R is 40, indicating that the storage data In the operation of inserting into the hash table, it takes R queries to find a storage address whose linked list length is less than , is the query probability function of the data to be stored in the tth period, indicating that when the nth query in the tth period finds a linked list with a storage address less than The probability of is the query time consumption function of the data to be stored in the tth period, indicating the query time consumption of n queries in the tth period.
[0053] It should be noted that the predicted query time , reflecting the predicted query time under the data storage distribution in the hash table in the tth period. The longer the predicted query time in the tth period, the more time it takes to use method 1 to handle hash collisions. At this time, method 1 should not be used to handle hash collisions.
[0054] At this point, the predicted query time for the data to be stored in each time period is obtained.
[0055] Step 4, analyzing the probability distribution of the linked list lengths of the storage addresses in the hash table in each time period that are less than the critical length, and the length difference between the linked list lengths of the remaining storage addresses in the hash table and the critical length, to determine the verification time difference of the data to be stored in each time period.
[0056] Based on the above analysis, the predicted query time reflects the time consumed when using method 1 to handle hash collisions, while method 2 directly handles hash collisions by storing the data to be stored. The linked list is added, so the time consumed by the second method to handle hash collisions is negligible, but since the second method increases the length of the linked list, increasing the length of the linked list will increase the time for subsequent traceability verification of the hash table. Therefore, the verification time difference is calculated to reflect the verification time saved by using the first method compared to the second method.
[0057] First, the data to be stored The length of the linked list corresponding to the storage address is If we use method 1 to find a linked list with a length greater than When the storage address is short, the traceability verification time will be shortened. At this time, the shortened time length is recorded as the verification time difference. For short storage addresses, the length k of each linked list is different, so the verification time difference is calculated as follows: The hash table of each time period contains the data smaller than the critical length. The ratio of the occurrence probability of each chain length to the short chain probability is used as the verification occurrence probability of each chain length in each time period; The verification time difference of the data to be stored in each period is: ,in, is the verification time difference of the data to be stored in period t, indicating the verification time difference of the data to be stored The length of the linked list corresponding to the storage address The linked list uses method 1 instead of method 2 to handle the verification time difference caused by hash collision. The length of the linked list storing the address for the tth period is The probability of verification, E is the linked list query time, is the critical length of the tth period.
[0058] It should be noted that the verification time difference When simulating the use of method 1 to handle hash collisions compared to method 2, the expected value of the verification time difference calculated by the data distribution in the hash table is used as the verification time difference. The larger the verification time difference, the more effective it is to use method 1 to handle hash collisions. It can save verification time and improve the efficiency of hash table generation. At this time, method 1 should be used to handle the data to be stored. .
[0059] At this point, the verification time difference of the data to be stored in each time period is obtained.
[0060] Step 5, according to the difference in computing speed between the built-in microprocessor in the electronic price calculating scale and the host computer system, and the difference between the verification time difference and the predicted query time, determine the hash evaluation coefficient of the data to be stored in each time period; based on the hash evaluation coefficient, select the storage method of the data to be stored to obtain a hash table.
[0061] The host computer system is usually used in conjunction with an electronic price computing scale. It is a software system for monitoring and management. It runs on a computer or server. The host computer system can remotely monitor the working status of the electronic price computing scale and is used to realize remote monitoring, data collection, management and analysis of the electronic price computing scale. Among them, the host computer system can manage and monitor multiple electronic price computing scales at the same time.
[0062] Based on the above analysis, the predicted query time explains the additional system calculation time of the hash table when the first method is used to handle hash collisions. This part of time is borne by the electronic price scale itself; and the verification time difference explains the additional system calculation time for subsequent queries to the hash table when the second method is used to handle hash collisions. This part of time is borne by the anti-cheating traceability system. Further, based on the predicted query time and the verification time difference, the hash evaluation coefficient is determined to determine which method to use to generate the hash table for the stored data in time period t, specifically: Considering the load balance between the electronic price computing scale and the host computer system, the operation speed of the built-in microprocessor in the electronic price computing scale is obtained, which is recorded as LO, and the operation speed of the host computer system is obtained, which is recorded as SY; It should be noted that the acquisition of the calculation speed of the built-in microprocessor in the electronic price computing scale and the calculation speed of the host computer system is a well-known technology and will not be described in detail here.
[0063] The hash evaluation coefficient of the data to be stored in each period is: ,in, is the hash evaluation coefficient of the data to be stored in period t, is the number of all electronic price-calculating scales managed by the host computer system during period t, is the verification time difference of the data to be stored in period t, is the predicted query time of the data to be stored in the tth period, LO is the operation speed of the built-in microprocessor in the electronic price computing scale, and SY is the operation speed of the host computer system.
[0064] It should be noted that the slower the computing speed of the host computer system, the faster the computing speed of the microprocessor in the electronic price calculating scale, the fewer electronic price calculating scales managed in the system, and the more the load of the electronic price calculating scale is compared with the computing resources of the host computer system, the more it should adopt method 1 to generate a hash table that is easy to verify; for a linked list length of The longer the verification time difference is, the shorter the prediction query time is. The more the method 1 for processing the hash table can reduce the overall calculation time of the system, the more it should be used to process the hash collision to generate the hash table.
[0065] If the data to be stored There is no hash collision, and the data to be stored is directly Store in the linked list of storage addresses; if the data to be stored When a hash collision occurs, the data to be stored in each period The hash evaluation coefficient is greater than the preset judgment threshold, and the data is stored in method 1, that is, the original data of the head node of the linked list at the hash collision position is squeezed out, and the squeezed data is used as the new data to be inserted into the hash table, and the storage address of the squeezed data is recalculated using the SHA-3 hash function. , thereby generating a hash table; the data to be stored in each period The hash evaluation coefficient is less than or equal to the preset judgment threshold, and the second method is used to store data to generate a hash table, that is, the data to be stored Insert into the linked list at the hash collision position to complete the generation of the hash table.
[0066] Preferably, in this embodiment, the preset judgment threshold value is 1, and the implementer can set it according to the actual situation.
[0067] It should be noted that if the hash evaluation coefficient is greater than the preset judgment threshold, it means that the computing resources consumed by searching for a linked list shorter than the linked list length of the storage address corresponding to the data to be stored are relatively small. In order to reduce the complexity of calculations during subsequent traceability verification, a linked list with a relatively short linked list length of the storage address should be selected for storage at this time; if the hash evaluation coefficient is less than or equal to the preset judgment threshold, it means that the computing resources consumed by searching for a linked list shorter than the linked list length of the storage address corresponding to the data to be stored are relatively large, and the linked list length of the storage location corresponding to the data to be stored is not very long. The computing resources consumed during subsequent traceability verification are relatively small compared to the computing resources consumed by re-searching the linked list. At this time, it should be directly inserted into the linked list at the hash collision position for storage.
[0068] Furthermore, the flowchart of the data storage process provided in this embodiment is as follows: Figure 4 shown.
[0069] The traceability verification module is located in the host computer system and is used to compare the storage data of the hash table stored in the host computer system with the local storage data of the electronic price computing scale to perform traceability verification on the storage data.
[0070] When the host computer system performs traceability verification, the local storage data of the electronic price computing scale is obtained as the data to be traced. , calculated using the SHA-2 hash function , at the storage address Search the linked list to see if there is data for period t If the SHA-3 hash function is not used, , then in the storage address Search the linked list to see if there is any data to be traced in period t If there is still no sign, it is judged that the traceability verification has failed and the traceability data is waiting has been tampered with; otherwise, the traceability verification is judged to be successful, and the traceability data Has not been tampered with.
[0071] Based on the same inventive concept as the above method, an embodiment of the present application also provides a disposable electronic pricing scale, and the anti-counterfeiting and anti-cheating traceability of the electronic pricing scale is implemented by using any one of the above-mentioned disposable electronic pricing scale anti-counterfeiting and anti-cheating traceability systems.
[0072] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0073] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0074] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the present application. It should be pointed out that, for those of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present application without departing from the content of the technical solution of the present application, shall fall within the protection scope of the technical solution of the present application.
Claims
1. A disposable electronic price-computing scale anti-counterfeiting and anti-cheating traceability system, characterized in that: The system comprises: The electronic scale data collection module is used to obtain the weighing time and weighing data of all collected electronic price computing scales in each time period as the data to be stored in each time period; The hash table generation module is used to generate a hash table, including: (1) Using the first hash function of the cuckoo hash algorithm, the length of the linked list of the storage address of the hash table corresponding to the data to be stored in each period is recorded as the critical length; according to the probability distribution of different linked list lengths of the storage address in the hash table and the probability distribution trend of all linked list lengths of the storage address greater than the critical length, the average query length of the data to be stored in each period is determined; (2) Analyze the time consumed for multiple operations on the data to be stored in each period, as well as the time consumed for querying the linked list in the hash table, and determine the query time function of the data to be stored in each period in combination with the average query length; (3) Analyze the probability that the length of a linked list of a storage address is less than the critical length to determine the query probability function, and combine it with the query time function to determine the predicted query time of the data to be stored in each time period; (4) Analyze the probability distribution of the length of the linked list of storage addresses in the hash table that is less than the critical length in each time period, and the length difference between the length of the linked list of the remaining storage addresses in the hash table and the critical length, and determine the verification time difference of the data to be stored in each time period; (5) determining a hash evaluation coefficient of the data to be stored in each time period according to the difference in computing speed between the built-in microprocessor in the electronic price computing scale and the host computer system, and the difference between the verification time difference and the predicted query time; selecting a storage method for the data to be stored based on the hash evaluation coefficient to obtain a hash table; The traceability verification module is used to compare the stored data in the stored hash table with the local stored data of the electronic pricing scale to perform traceability verification on the stored data.
2. The disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system according to claim 1, characterized in that: Determining the average query length of the data to be stored in each time period includes: Counting the number of all storage addresses with the same linked list length in the hash table in each time period, and taking the ratio between the number and the number of all storage addresses in the hash table as the occurrence probability of each linked list length in each time period; The sum of the occurrence probabilities of all linked list lengths of storage addresses less than the critical length in the hash table of each time period is used as the short chain probability of the data to be stored in each time period; The sum of the occurrence probabilities of all chain list lengths of storage addresses greater than or equal to the critical length in the hash table of each time period is used as the long chain probability of the data to be stored in each time period; The ratio of the occurrence probability of each chain length greater than or equal to the critical length in the hash table of each time period to the long chain probability is recorded as the query occurrence probability of each chain length in each time period; The product of the query occurrence probability of each linked list length in each time period and the corresponding linked list length is recorded as the first product; the sum of the first products of all linked list lengths of the storage addresses in the hash table in each time period is taken as the average query length of the data to be stored in each time period.
3. The anti-counterfeiting and anti-cheating tracing system for a disposable electronic price computing scale according to claim 1, characterized in that: The function for determining the query time consumption of the data to be stored in each time period includes: ,in, is the query time function of the data to be stored in the tth period, E is the linked list query time, and the linked list query time is obtained by: constructing an initial linked list of a preset length, querying each data in the initial linked list, and taking the average of all query times of the initial linked list as the linked list query time. is the hash time of the data to be stored in the tth period. The hash time is the time consumed by the first hash function of the cuckoo hash algorithm to calculate the data to be stored. n is the number of queries. is the average query length of the data to be stored in the tth period.
4. A disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system as claimed in claim 2, characterized in that: The query probability function is: ,in, is the short chain probability of the data to be stored in the tth period, n is the number of queries, is the data to be stored in the tth period.
5. The disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system according to claim 1, characterized in that: The calculation formula for determining the predicted query time of the data to be stored in each time period is: ,in, is the predicted query time for the data to be stored in period t, R is the preset maximum query number, is the query probability function of the data to be stored in the tth period, It is the query time-consuming function of the data to be stored in the tth period.
6. A disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system as claimed in claim 2, characterized in that: Determining the verification time difference of the data to be stored in each time period includes: ,in, is the verification time difference of the data to be stored in period t, The length of the linked list storing the address for the tth period is The verification occurrence probability is the ratio of the occurrence probability of each chain length less than the critical length in the hash table of each time period to the probability of the short chain; E is the chain query time, is the critical length of the tth period.
7. The disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system according to claim 1, characterized in that: The hash evaluation coefficient of the data to be stored in each time period is expressed as: ,in, is the hash evaluation coefficient of the data to be stored in the tth period, is the number of all electronic price-calculating scales managed by the host computer system in period t, is the verification time difference of the data to be stored in period t, is the predicted query time of the data to be stored in the tth period, LO is the operation speed of the built-in microprocessor in the electronic price computing scale, and SY is the operation speed of the host computer system.
8. The anti-counterfeiting and anti-cheating tracing system for a disposable electronic price computing scale according to claim 1, characterized in that: The obtaining of the hash table comprises: When there is no hash collision in the data to be stored, the data to be stored is directly stored in the linked list of the storage address of the corresponding hash table; when there is a hash collision in the data to be stored, if the hash evaluation coefficient of the data to be stored in each time period is greater than the preset judgment threshold, the original storage data of the head node of the linked list in the storage address of the corresponding hash table is squeezed out; otherwise, the data to be stored is inserted into the linked list of the storage address to generate a hash table.
9. The disposable electronic price computing scale anti-counterfeiting and anti-cheating tracing system according to claim 1, characterized in that: The traceability verification of the stored data includes: The locally stored data of the electronic pricing scale is obtained, recorded as the data to be traced, and the hash value of the data to be traced is calculated by using the first hash function in the cuckoo hash algorithm, recorded as the first hash value; Search the linked list of the storage address corresponding to the first hash value in the hash table for the data to be traced. If the data does not exist, use the second hash function in the cuckoo hash algorithm to calculate the hash value of the data to be traced, which is recorded as the second hash value; The data to be traced is searched in the linked list of the storage address corresponding to the second hash value in the hash table. If the data does not exist, it is determined that the traceability verification has failed; otherwise, it is determined that the traceability verification has succeeded.
10. A disposable electronic price-computing scale, characterized in that: The anti-counterfeiting and anti-cheating tracing system of the electronic price computing scale is implemented by using the disposable anti-counterfeiting and anti-cheating tracing system of the electronic price computing scale described in any one of claims 1 to 9.