Request processing method, electronic device and program product
By obtaining the short-circuit characteristics of the expression and the target evaluation order, and calculating the Boolean value of the main Boolean factor in combination with the short-circuit characteristics, the problem of resource waste and calculation speed reduction caused by ignoring the short-circuit characteristics in the prior art is solved, and more efficient expression calculation is achieved.
Patent Information
- Application Number
- CN202411686949.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-11-22
AI Technical Summary
The prior art ignores short-circuit characteristics when processing expressions, resulting in unnecessary calculations, resulting in waste of resources and reduced calculation speed.
By obtaining the short-circuit characteristics of the to-process expression and the target evaluation order of multiple main Boolean factors, the Boolean value of the main Boolean factor is obtained in combination with the short-circuit characteristics, and the value of the expression is calculated.
It improves the efficiency of expression calculation, reduces the number of exception retry times, saves resources, and solves the problem of resource waste caused by ignoring the short circuit characteristics in a fixed calculation order.
Smart Images

Figure CN119557557A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of computers and the like, and in particular to a request processing method, an electronic device, and a program product. Background Art
[0002] When processing some call requests, it is necessary to calculate the expressions associated with the call requests. Expressions are a basic concept in computer science, covering programming, algorithm design, data processing, and many other aspects. Expressions are usually composed of variables, operators, etc., and are used to describe the relationship between data and the calculation process. In application scenarios such as conditional judgment and loop control, in order to ensure the logical correctness and functional integrity of the program, the value of the expression needs to be calculated.
[0003] In the prior art, the calculation order of the variables in the expression is generally fixed, and when calculating the final value of the expression, the calculation values of the variables are obtained in sequence based on the fixed calculation order and then calculated.
[0004] However, a fixed calculation order generally ignores the short-circuit characteristics, leading to unnecessary calculations, wasting computing resources, and reducing computing speed. Summary of the invention
[0005] The present disclosure provides a request processing method, an electronic device, and a program product.
[0006] According to one aspect of the present disclosure, a request processing method is provided, including: Receive a call request for an expression to be processed; In response to the call request, the short-circuit characteristic of the expression to be processed and the target evaluation order of multiple main Boolean factors of the expression to be processed are obtained, wherein the target evaluation order is determined from different evaluation orders of the multiple main Boolean factors according to the magnitude of normal termination probabilities of multiple expressions corresponding to the different evaluation orders; Obtaining Boolean values of the plurality of main Boolean factors according to the target evaluation order in combination with the short-circuit characteristic; Perform expression calculation according to the Boolean values of the plurality of main Boolean factors to obtain the value of the expression to be processed; The value of the expression to be processed is processed according to the processing method corresponding to the calling request.
[0007] According to the request processing method of at least one embodiment of the present disclosure, the step of obtaining the short-circuit characteristic of the expression to be processed and the target evaluation order of multiple main Boolean factors of the expression to be processed includes: Obtaining the target evaluation order of the plurality of main Boolean factors from the expression-evaluation order mapping; or, The target evaluation order of the plurality of main Boolean factors is obtained from the different evaluation orders of the plurality of main Boolean factors according to the magnitudes of normal termination probabilities of the plurality of expressions corresponding to the different evaluation orders.
[0008] According to the request processing method of at least one embodiment of the present disclosure, the step of obtaining the target evaluation order of the multiple main Boolean factors from the different evaluation orders of the multiple main Boolean factors according to the magnitudes of the normal termination probabilities of the multiple expressions corresponding to the different evaluation orders includes: Obtaining different evaluation orders of the plurality of main Boolean factors; Obtain normal termination probabilities of multiple expressions corresponding to the different evaluation orders; The target evaluation order is obtained from the different evaluation orders according to the magnitudes of the normal termination probabilities of the multiple expressions.
[0009] According to the request processing method of at least one embodiment of the present disclosure, for any evaluation order, obtaining normal termination probabilities of multiple expressions corresponding to the different evaluation orders includes: The main Boolean factors are repeatedly calculated in sequence according to the evaluation order and the number of calculations, so as to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time; Performing statistical operations based on the calculation success rate of each main Boolean factor and the Boolean value obtained when each calculation is successful, to obtain a result probability distribution of each main Boolean factor; Get the termination probability calculation method corresponding to the evaluation order and operator; Substituting the result probability distribution of each main Boolean factor into the termination probability calculation method to obtain the normal termination probability of the expression corresponding to the evaluation order; The operator is an operator between the multiple main Boolean factors in the expression to be processed.
[0010] According to the request processing method of at least one embodiment of the present disclosure, for any main Boolean factor, performing statistical operations based on the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time, includes: According to the Boolean value obtained when the main Boolean factor is successfully calculated each time, the number of occurrences of different Boolean values is counted to obtain the true value count and the false value count; Multiplying the calculation success rate of the main Boolean factor by the true value count and the false value count respectively to obtain the true value expectation and the false value expectation; Dividing the true value expectation and the false value expectation by the number of iterations of the main Boolean factor respectively; The number of iterations is the sum of the number of calculations and the number of retries when the calculations fail.
[0011] According to the request processing method of at least one embodiment of the present disclosure, for the first main Boolean factor corresponding to the evaluation order, the main Boolean factors are repeatedly calculated in sequence according to the evaluation order and the number of calculations to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when each calculation is successful, including: Repeat the calculation of the first main Boolean factor according to the number of calculations to obtain a first execution state of each calculation; When the first execution state of any calculation is calculation failure, retries are performed until the deadline condition is reached, and the first number of retries is obtained; Obtaining the first iteration number of the first main Boolean factor according to the sum of the number of calculations and the total number of first retries when the calculation fails; The calculation success rate of the first main Boolean factor is obtained according to the quotient of the number of states in which calculation is successfully performed in the first execution state and the first number of iterations.
[0012] According to the request processing method of at least one embodiment of the present disclosure, for any second main Boolean factor other than the first main Boolean factor corresponding to the evaluation order, the main Boolean factors are repeatedly calculated in sequence according to the evaluation order and the number of calculations to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when each calculation is successful, including: Obtaining the number of short-circuit triggering times of the second main Boolean factor being short-circuited according to the calculation status of the main Boolean factor before the second main Boolean factor in the evaluation order; Obtaining the execution times of the second main Boolean factor according to the difference between the calculation times and the short circuit triggering times; Repeatedly calculate the second main Boolean factor according to the execution number to obtain a second execution state of each calculation; When the second execution state of any calculation is calculation failure, retry until the end condition is reached, and obtain the second retry number; Obtaining the second iteration number of the second main Boolean factor according to the sum of the calculation number and the total number of second retries when the calculation fails; The calculation success rate of the second main Boolean factor is obtained according to the quotient of the number of states in which calculation is successfully performed in the second execution state and the second number of iterations.
[0013] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, so that the processor executes the request processing method of any embodiment of the present disclosure.
[0014] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the request processing method of any embodiment of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings illustrate exemplary embodiments of the present disclosure and together with the description serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.
[0016] Figure 1 It is a flowchart of a request processing method according to an embodiment of the present disclosure.
[0017] Figure 2 yes Figure 1 A flowchart of a method for obtaining target evaluation order in a request processing method is shown.
[0018] Figure 3 yes Figure 2 The flowchart of the normal probability acquisition method in the target evaluation order acquisition method is shown.
[0019] Figure 4 yes Figure 3 The flowchart of the probability distribution acquisition method in the normal probability acquisition method is shown.
[0020] Figure 5 yes Figure 3 The process of calculating the success rate acquisition method in the normal probability acquisition method shown Figure 1 .
[0021] Figure 6 yes Figure 3 The process of calculating the success rate acquisition method in the normal probability acquisition method shown Figure 2 .
[0022] Figure 7 yes Figure 1 The flowchart of the expression evaluation method in the request processing method is shown.
[0023] Figure 8 It is a schematic flowchart of a request processing method according to an embodiment of the present disclosure.
[0024] Fig. 9 It is a schematic block diagram of the structure of a request processing device according to another embodiment of the present disclosure.
[0025] Fig.10 It is a schematic block diagram of the structure of an electronic device equipped with a request processing device according to another embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] The present disclosure is further described in detail below in conjunction with the accompanying drawings and examples. It is understood that the specific examples described herein are only used to explain the relevant content, rather than to limit the present disclosure. It should also be noted that, for ease of description, only the parts related to the present disclosure are shown in the accompanying drawings.
[0027] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The technical solution of the present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0028] Boolean expressions are expressions composed of Boolean values (true and false) and are used to express logical relationships and conditional judgments. Taking "a || b" as an example, a fixed calculation order generally requires that the Boolean value of one Boolean factor be calculated first, then the Boolean value of another Boolean factor, and finally the Boolean value of the two Boolean factors be used to calculate the final value of the Boolean expression; however, since "||" means that as long as the Boolean value of one Boolean factor is "true", the final value of the expression can be determined to be "true", so when the Boolean value of the first Boolean factor is "true", calculating the Boolean value of another Boolean factor will cause a waste of resources.
[0029] To this end, the present disclosure proposes a request processing method, an electronic device, and a program product. In response to a call request, the Boolean value of each main Boolean variable is obtained in turn according to the target evaluation order combined with the short-circuit characteristic, and then the value of the expression to be processed is calculated and processed to realize request processing. The present disclosure can be used in electronic devices such as mobile phones, tablet computers, computers, and servers.
[0030] For the convenience of description and to make the technical solutions of the specific implementation methods of the present disclosure easier to understand, before describing the request processing method implemented by the present disclosure, the technical terms involved in the specific implementation methods of the present disclosure are explained as follows: The short-circuit feature means that during the evaluation of a logical expression, if the final value of the entire expression can be determined based on the currently calculated Boolean value, the evaluation of subsequent Boolean factors will be skipped.
[0031] The main Boolean factors are the factors that directly participate in the highest-level logical operations.
[0032] The normal termination probability of an expression refers to the possibility that the expression successfully calculates the final result during the evaluation process.
[0033] Figure 1 FIG. 1 is a schematic diagram showing the overall process of a request processing method M100 according to an embodiment of the present disclosure. Figure 1 The method shown includes steps S110 to S150. The method can be executed by electronic devices such as mobile phones, tablet computers, computers, and servers.
[0034] Specifically, Figure 1 The methods shown include: Step S110, receiving a call request for an expression to be processed.
[0035] In some embodiments of the present disclosure, the triggering subject of the call request in step S110 may be a database or a Web service, etc., and the triggering condition of the call request may be a specific keyword, phrase, intention or user behavior pattern, etc.
[0036] Step S120, in response to the call request, obtaining the short-circuit characteristic of the expression to be processed and the target evaluation order of multiple main Boolean factors of the expression to be processed.
[0037] In some embodiments of the present disclosure, the process of obtaining the short-circuit characteristic through step S120 may include: first obtaining the operator of the highest-level logical operation in the expression to be processed; then determining the short-circuit characteristic according to the operator of the highest-level logical operation. If the expression to be processed contains && (logical AND), when the Boolean value of the main Boolean factor calculated first is "false", the final result of the entire expression to be processed must be "false", and there is no need to continue calculating the subsequent main Boolean factors; if the expression to be processed contains || (logical OR), when the Boolean value of the main Boolean factor calculated first is "true", the final result of the entire expression to be processed must be "true", and there is no need to continue calculating the subsequent main Boolean factors.
[0038] The operators of the highest-level logical operations in the expression to be processed can be obtained by analyzing the elements of the expression to be processed; the elements of the expression to be processed refer to the basic components of the expression to be processed. The elements of the expression to be processed may include main Boolean factors and logical operators of the highest-level logical operations (such as &&, ||, etc.); in addition to the above, the elements of the expression to be processed may also include: sub-Boolean factors, logical operators of low-level logical operations or non-logical operators (such as addition (+), subtraction (-), multiplication (*), division ( / )), etc. One or more.
[0039] The target evaluation order obtained by step S120 is determined according to the magnitude of the normal termination probabilities of the multiple expressions corresponding to the different evaluation orders of the multiple main Boolean factors. For example, the evaluation order corresponding to the larger normal termination probability of the multiple expressions is used as the target evaluation order, or the evaluation order corresponding to the largest normal termination probability of the multiple expressions is used as the target evaluation order, etc.
[0040] The main Boolean factor in step S120 can be in various forms, including but not limited to a simple Boolean variable (a variable that can only take two possible values, which usually represent true or false), a Boolean expression (an expression consisting of a Boolean variable, a Boolean constant (such as a constant that can only take one of two fixed values, which are one of true and false), a logical operator (such as &&, ||, NOT!), and possible parentheses; the final result of the expression is always a Boolean value), a function call (referring to the process of executing a function by specifying the function name and providing the required parameters (if any) during the execution of the program, and the function returns a Boolean value), etc.
[0041] Step S130 , obtaining Boolean values of a plurality of main Boolean factors according to the target evaluation order and the short-circuit characteristic.
[0042] In some embodiments of the present disclosure, the process of obtaining the Boolean values of multiple main Boolean factors according to the target evaluation order combined with the short-circuit characteristic through step S130 may include: first obtaining the Boolean value of the first main Boolean factor in the target evaluation order; judging whether the final value of the entire expression to be processed can be determined based on the Boolean value of the first main Boolean factor; if the final value of the entire expression to be processed can be determined based on the Boolean value of the first main Boolean factor, the Boolean values of other main Boolean factors other than the first main Boolean factor in the target evaluation order are no longer calculated; if the final value of the entire expression to be processed cannot be determined based on the Boolean value of the first main Boolean factor, obtaining the target Boolean value of the first main Boolean factor is a process of obtaining the Boolean value of the first main Boolean factor. The Boolean value of the next main Boolean factor in the target evaluation order is determined; it is determined whether the final value of the entire expression to be processed can be determined based on all the Boolean values currently obtained; if the final value of the entire expression to be processed can be determined based on all the Boolean values currently obtained, the Boolean values of other main Boolean factors other than the main Boolean factors that have obtained Boolean values in the target evaluation order are no longer calculated; if the final value of the entire expression to be processed cannot be determined based on all the Boolean values currently obtained, the above-mentioned process of obtaining the Boolean value of the next main Boolean factor is repeated until the final value of the entire expression to be processed can be determined based on all the Boolean values currently obtained or the Boolean values of all main Boolean factors are obtained.
[0043] When a main Boolean factor is in the form of a simple Boolean variable, its Boolean value can be obtained locally or from an external device through a Remote Procedure Call (RPC) interface. When a main Boolean factor is in the form of a complex Boolean expression, each Boolean variable in the Boolean expression can be obtained separately and then operated; the Boolean expression can be a simple Boolean expression (i.e., an expression containing only basic Boolean factors (such as Boolean variables or Boolean constants) and logical operators (such as &&, ||, or !)) or a nested Boolean expression (i.e., a Boolean expression containing other Boolean expressions as its components).
[0044] Step S140, performing expression calculation according to the Boolean values of the plurality of main Boolean factors to obtain the value of the expression to be processed.
[0045] In some embodiments of the present disclosure, step S140 may substitute the Boolean values of the plurality of main Boolean factors into the corresponding operators of the highest-level logical operation to obtain the value of the expression to be processed.
[0046] Step S150, processing the value of the expression to be processed according to the processing method corresponding to the calling request.
[0047] In some embodiments of the present disclosure, the processing method corresponding to the call request in step S150 can be determined according to the specific requirements of the call request. The processing method determines how to effectively apply the value to the logic flow of the program after calculating the value of the expression to be processed, which can include directly returning the result, executing conditional branches, loop control, exception handling, caching, asynchronous processing or event triggering, etc.
[0048] The request processing method provided by the present disclosure, since the target evaluation order is determined from the different evaluation orders of multiple main Boolean factors according to the size of the normal termination probability of multiple expressions corresponding to different evaluation orders, when calculating based on the target evaluation order, it can improve the probability of completing the calculation of the expression to be processed, reduce the number of abnormal retries and improve the calculation efficiency, thereby improving the request processing efficiency; and when calculating the Boolean values of multiple main Boolean factors, the short-circuit characteristics of the expression to be processed are combined, and the evaluation operation of the subsequent main Boolean factors can be skipped when the short-circuit characteristics are met, saving resources. This method solves the problem in the prior art that the fixed calculation order generally ignores the short-circuit characteristics, resulting in unnecessary calculations and waste of resources.
[0049] In some embodiments of the present disclosure, taking the expression to be processed as A&&(B||C) as an example, the main Boolean factors may include: the main Boolean factor "A" and the main Boolean factor "(B||C)"; the short-circuit characteristic obtained by step S120 may be "when the Boolean value of the main Boolean factor "A" is calculated first, if the Boolean value of the main Boolean factor "A" is "true", then there is no need to calculate the Boolean value of the main Boolean factor "(B||C)"; when the Boolean value of the main Boolean factor "(B||C)" is calculated first, if the Boolean value of the main Boolean factor "(B||C)" is "true", then there is no need to calculate the Boolean value of the main Boolean factor "A"".
[0050] Assuming that the target evaluation order obtained through step S120 is to first calculate the Boolean value of the main Boolean factor "(B||C)" and then calculate the Boolean value of the main Boolean factor "A", the method of obtaining the Boolean value through step S130 may include: first obtain the Boolean value of the main Boolean factor "(B||C)"; then determine whether the Boolean value of the main Boolean factor "(B||C)" is "true"; if the Boolean value of the main Boolean factor "(B||C)" is "true", the Boolean value of the main Boolean factor "A" is no longer calculated; if the Boolean value of the main Boolean factor "(B||C)" is "false", the Boolean value of the main Boolean factor "A" needs to be calculated.
[0051] Assuming that the Boolean value of the main Boolean factor "(B||C)" is "false" and the Boolean value of the main Boolean factor "A" is "true", step S140 substitutes these two Boolean values into both sides of the "&&" operator to obtain the value of the expression to be processed "false".
[0052] In some embodiments of the present disclosure, the process of obtaining the target evaluation order of multiple main Boolean factors in step S120 can be specifically as follows: obtaining the target evaluation order of multiple main Boolean factors from different evaluation orders of multiple main Boolean factors according to the magnitude of the normal termination probabilities of multiple expressions corresponding to different evaluation orders; in particular, in order to reduce computing overhead, improve request processing efficiency and improve maintainability, the process can also be specifically as follows: obtaining the target evaluation order of multiple main Boolean factors from the expression-evaluation order mapping. The expression-evaluation order mapping can significantly improve system performance and user experience by calculating and storing the mapping relationship in advance; the mapping relationship stored in the expression-evaluation order mapping can be fixed, or it can be updated periodically, and it can also be updated when related content (such as the expression to be processed, the operating environment, etc.) changes, etc.
[0053] Regarding step S120, the process of obtaining the target evaluation order of the plurality of main Boolean factors is specifically to obtain the target evaluation order of the plurality of main Boolean factors from the different evaluation orders of the plurality of main Boolean factors according to the magnitude of the normal termination probabilities of the plurality of expressions corresponding to the different evaluation orders. In some embodiments of the present disclosure, it may include the following: Figure 2 Steps S121 to S123 are shown.
[0054] Step S121, obtaining different evaluation orders of multiple main Boolean factors.
[0055] In some embodiments of the present disclosure, step S121 can use a recursive method to obtain different evaluation orders of multiple main Boolean factors. The specific process is: fix one of the multiple main Boolean factors, recursively generate the permutations of the remaining main Boolean factors except the fixed main Boolean factor in the multiple main Boolean factors, and insert the fixed main Boolean factor into each position of the permutation in these permutations; then fix the next main Boolean factor, repeat the recursive generation of the permutation and the insertion operation, and so on until the generation of the permutation and the insertion operation of the last main Boolean factor in the multiple main Boolean factors are completed.
[0056] Alternatively, a full permutation method is used to obtain different evaluation orders of multiple principal Boolean factors. The specific process is: select one principal Boolean factor from the multiple principal Boolean factors and fix it at the first position of the permutation, and perform full permutation on the remaining principal Boolean factors except the selected principal Boolean factor from the multiple principal Boolean factors; select the next principal Boolean factor from the multiple principal Boolean factors and fix it at the first position of the permutation, repeat the full permutation operation, and so on until the last principal Boolean factor among the multiple principal Boolean factors is fixed at the first position of the permutation and the full permutation operation is completed.
[0057] Alternatively, a dynamic programming method is used to obtain different evaluation orders of multiple main Boolean factors. The specific process is as follows: initially, an empty permutation is used, and one of the main Boolean factors among the multiple main Boolean factors is inserted into the empty permutation to obtain 1! full permutation; based on the 1! full permutation, the next main Boolean factor among the multiple main Boolean factors is inserted into each position in the full permutation to obtain 2! full permutations; for any subsequent main Boolean factor, this main Boolean factor is inserted into each position of the permutation of the previous n-1 main Boolean factors to obtain n! full permutations, where n-1 is the number of main Boolean factors currently inserted.
[0058] Step S122, obtaining normal termination probabilities of multiple expressions corresponding to different evaluation orders.
[0059] In some implementations of the present disclosure, the normal termination probability of the expression corresponding to each evaluation order in different evaluation orders can be obtained respectively through step S122.
[0060] Step S123, obtaining a target evaluation order from different evaluation orders according to the probabilities of normal termination of multiple expressions.
[0061] In some embodiments of the present disclosure, step S123 may select the evaluation order corresponding to the largest expression termination probability from multiple expression termination probabilities corresponding to different evaluation orders as the target evaluation order, so that the expression to be processed can reach its maximum degree of completion.
[0062] By determining the target evaluation order based on the probabilities of normal termination of multiple expressions in different evaluation orders through steps S121 to S123, the calculation flexibility of the expression to be processed and the probability of normal completion of the calculation can be improved, thereby improving the performance and reliability of the calculation of the expression to be processed.
[0063] For any evaluation order in different evaluation orders, regarding step S122, in some embodiments of the present disclosure, it may include the following: Figure 3 Steps S1221 to S1224 are shown.
[0064] Step S1221, repeatedly calculating the main Boolean factors in sequence according to the evaluation order and the number of calculations, to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time.
[0065] In some embodiments of the present disclosure, the number of calculations in step S1221 is the initial number of times each variable is repeatedly calculated, and the number of calculations can be preset and adjusted according to actual needs. The calculation success rate of a main Boolean factor in step 1221 is the probability of successful calculation of the main Boolean factor when the main Boolean factor is repeatedly calculated according to the number of calculations. When a main Boolean factor is successfully calculated, its Boolean value can be either "true" or "false".
[0066] Step S1222 , performing statistical operations based on the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time, to obtain the result probability distribution of each main Boolean factor.
[0067] In some embodiments of the present disclosure, for any main Boolean factor, the result probability distribution in step S1222 is the Boolean value obtained each time the main Boolean factor is successfully calculated, the probability of the true value corresponding to the Boolean value "true" and the probability of the false value corresponding to the Boolean value "false".
[0068] Step S1223, obtaining the termination probability calculation method corresponding to the evaluation order and the operator.
[0069] In some embodiments of the present disclosure, the operator may cause the result probability distribution of multiple main Boolean factors to have different effects on the normal termination probability of the expression, that is, the termination probability calculation method for the normal termination of the expression is different. Therefore, before calculating the normal termination probability of the expression, the termination probability calculation method may be obtained through step S1223. The termination probability calculation method corresponding to different expressions may be preset, or the termination probability calculation method may be obtained according to the evaluation order and the operator. The operator in step S1223 may be an operator of the highest level logical operation between multiple main Boolean factors in the expression to be processed. When one or several main Boolean factors are in the form of expressions, the operator may also include operators of low-level logical operations within the main Boolean factors.
[0070] Step S1224, substitute the result probability distribution of each main Boolean factor into the termination probability calculation method to obtain the normal termination probability of the expression corresponding to the evaluation order.
[0071] With two main Boolean factors and For example, the main Boolean factor The calculation success rate is recorded as , the main Boolean factor The calculation success rate is recorded as , the main Boolean factor The true value probability of , the main Boolean factor The true value probability of .
[0072] Two main Boolean factors and When the operator between is "and (&& or and)", the main Boolean factor is calculated first Then calculate the main Boolean factor The expression of normal termination probability is ; Calculate the main Boolean factors first Then calculate the main Boolean factor The expression of normal termination probability is .
[0073] Two main Boolean factors and When the operator between is "or (|| or or)", the main Boolean factor is calculated first Then calculate the main Boolean factor The expression of normal termination probability is ; Calculate the main Boolean factors first Then calculate the main Boolean factor The expression of normal termination probability is .
[0074] When not is used in conjunction with other logical operators, such as , will calculate The expression of the normal termination probability formula is and exchange; The calculation method is similar.
[0075] NAND negates the result of AND operation, or NOR negates the result of OR operation.
[0076] When the expression to be processed contains a combination of multiple operators, the termination probability calculation method can be a combination of the above calculation methods; when a main Boolean factor includes multiple sub-Boolean factors, the calculation success rate and truth value probability of the sub-Boolean factors can be calculated first, and then the normal termination probability of the sub-expression composed of these sub-Boolean factors can be used as the calculation success rate of the main Boolean factor, and the truth value probability of the sub-expression calculated by the truth value probability of the sub-Boolean factors can be used as the truth value probability of the main Boolean factor.
[0077] By calculating the normal termination probability of the expression corresponding to the evaluation order through steps S1221 to S1224, it is possible to determine in which evaluation order the expression to be processed has the highest probability of successfully calculating the final result.
[0078] For any main Boolean factor, regarding step S1222, in some embodiments of the present disclosure, if Figure 4 As shown, it can be replaced by the following steps: According to the Boolean value obtained when the main Boolean factor is successfully calculated each time, the number of occurrences of different Boolean values is counted to obtain the true value count and the false value count; The calculation success rate of the main Boolean factor is multiplied by the true value count and the false value count to obtain the true value expectation and the false value expectation; Divide the expected true value and the expected false value by the number of iterations of the main Boolean factor respectively; The number of iterations is the sum of the number of calculations and the number of retries when the calculation fails.
[0079] In some embodiments of the present disclosure, two counters can be set for the main Boolean factor, one for recording the number of times the Boolean value is "true" and the other for recording the number of times the Boolean value is "false"; each time a calculation is successful, the result of the Boolean value is checked, if it is "true", the "true" counter is incremented by 1; if it is "false", the "false" counter is incremented by 1; after the statistics of all successful calculations are completed, the count value of the "true" counter is the true value count, and the count value of the "false" counter is the false value count.
[0080] The true value expectation can be obtained by multiplying the calculation success rate of the main Boolean factor by the true value count; the false value expectation can be obtained by multiplying the calculation success rate of the main Boolean factor by the false value count. The true value expectation divided by the number of iterations of the main Boolean factor can be obtained to obtain the true value probability in the result probability distribution; the false value expectation divided by the number of iterations of the main Boolean factor can be obtained to obtain the false value probability in the result probability distribution.
[0081] For the first main Boolean factor corresponding to the evaluation order, regarding step S1221, in some embodiments of the present disclosure, Figure 5 As shown, it can be replaced by the following steps: Repeat the calculation of the first main Boolean factor according to the number of calculations to obtain the first execution state of each calculation; When the first execution state of any calculation is calculation failure, retries are performed until the deadline condition is reached, and the first number of retries is obtained; Obtain the first iteration number of the first main Boolean factor according to the sum of the number of calculations and the total number of first retries when the calculation fails; The calculation success rate of the first main Boolean factor is obtained according to the quotient of the number of states with successful calculation in the first execution state and the first number of iterations.
[0082] In some embodiments of the present disclosure, after calculating the first main Boolean factor any time and obtaining the first execution state, it can be determined whether the first execution state is a calculation failure; if the first execution state is a calculation failure, retry until the cutoff condition is met; if the first execution state is a calculation success, repeat the next calculation of the first main Boolean factor until the number of repetitions reaches the number of calculations.
[0083] The first execution state of each calculation may include calculation failure and calculation success. The retry process of any calculation failure is to calculate the first main Boolean factor again when the calculation fails. The total number of first retries when the calculation fails is the total number of first retries when each calculation fails. The cutoff condition may be that the number of retries is greater than the retry threshold or the calculation is successful.
[0084] For any second main Boolean factor other than the first main Boolean factor corresponding to the evaluation order, regarding step S1221, in some embodiments of the present disclosure, Figure 6 As shown, it can be replaced by the following steps: Obtaining the number of short-circuit triggering times of the second main Boolean factor being short-circuited according to the calculation status of the main Boolean factor before the second main Boolean factor in the evaluation order; Obtaining the execution times of the second main Boolean factor according to the difference between the calculation times and the short-circuit trigger times; Repeatedly calculate the second main Boolean factor according to the number of executions to obtain a second execution state of each calculation; When the second execution state of any calculation is calculation failure, retry until the end condition is reached, and obtain the second retry number; Obtain the second iteration number of the second main Boolean factor according to the sum of the number of calculations and the total number of second retries when the calculation fails; The calculation success rate of the second main Boolean factor is obtained according to the quotient of the number of states in which calculations are successfully performed in the second execution state and the second number of iterations.
[0085] In some embodiments of the present disclosure, the method for obtaining the number of short circuit triggering times can be first to determine whether the main Boolean factors that can trigger a short circuit among the main Boolean factors calculated before the second main Boolean factor are one (group) or multiple (groups); if it is one (group), the number of times the main Boolean factor triggers a short circuit can be directly used as the number of short circuit triggering times; if it is multiple (groups), the number of times each (group) of main Boolean factors triggers a short circuit can be obtained separately; then the number of times multiple (groups) of short circuits are triggered is comprehensively processed to obtain the number of short circuit triggering times (such as taking the maximum, minimum or average of the number of times multiple (groups) of short circuits are triggered as the number of short circuit triggering times).
[0086] The second execution state of each calculation may include calculation failure and calculation success. The retry process of any calculation failure is to calculate the second main Boolean factor again when the calculation fails. The total number of second retries when the calculation fails is the total number of second retries when each calculation fails. The cutoff condition may be that the number of retries is greater than the retry threshold or the calculation is successful.
[0087] Regarding step S140, in some embodiments of the present disclosure, it may include: Figure 7 Steps S141 to S142 are shown.
[0088] Step S141, obtaining operators between multiple main Boolean factors in the expression to be processed.
[0089] In some embodiments of the present disclosure, the operator obtained in step S141 may include one or more of AND &&, OR ||, NOT!, XOR ^, etc.
[0090] Step S142, operating the Boolean values of the plurality of main Boolean factors according to the operator.
[0091] Taking A&&B as an example, assuming that the calculation success rate of the main Boolean factor A is , the calculation success rate of the main Boolean factor B is , the false value probability of the main Boolean factor A is , the false value probability of the main Boolean factor B A&&B corresponds to two evaluation orders. Evaluation order 1 is to calculate the main Boolean factor A first and then the main Boolean factor B. The probability of normal termination of the expression corresponding to this evaluation order is ; Evaluation order 2 is to calculate the main Boolean factor B first and then the main Boolean factor A. The probability of normal termination of the expression corresponding to this evaluation order is Since the probability of normal termination of expressions in evaluation order 1 is greater than the probability of normal termination of expressions in evaluation order 2, evaluation order 1 can be used as the target evaluation order.
[0092] Figure 8 A schematic flow chart of the request processing method of the present disclosure is shown.
[0093] exist Figure 8 In the request processing method shown, the request processing process may include: 1. Receive a call request for an expression to be processed.
[0094] 2. In response to a call request, obtain the short-circuit characteristics of the expression to be processed and different evaluation orders of multiple main Boolean factors.
[0095] 3. Obtain the normal termination probability of the expression corresponding to each evaluation order.
[0096] 4. Obtain the target evaluation order with the highest probability of normal termination of the expression from different evaluation orders.
[0097] 5. Obtain the Boolean values of multiple main Boolean factors according to the target evaluation order combined with the short-circuit characteristic.
[0098] 6. Calculate the expression based on the Boolean values of multiple main Boolean factors to obtain the value of the expression to be processed.
[0099] 7. Process the value of the expression to be processed according to the processing method corresponding to the call request.
[0100] In some embodiments of the present disclosure, this step can store the value in a variable for subsequent use, or use the value for conditional judgment to determine the next operation of the program, or use the value as input for further calculation or processing, etc.
[0101] Based on any of the above implementations, the present disclosure also provides a request processing device.
[0102] Fig. 9 It is a schematic block diagram of the structure of a request processing device according to an embodiment of the present disclosure.
[0103] like Fig. 9 As shown, the request processing device includes: The request receiving module 110 is used to receive a call request for an expression to be processed.
[0104] The sequence acquisition module 120 is used to obtain the short-circuit characteristics of the expression to be processed and the target evaluation order of multiple main Boolean factors of the expression to be processed in response to a call request. The target evaluation order is determined from the different evaluation orders of the multiple main Boolean factors according to the size of the normal termination probability of multiple expressions corresponding to different evaluation orders.
[0105] The Boolean value calculation module 130 is used to obtain the Boolean values of multiple main Boolean factors according to the target evaluation order combined with the short-circuit characteristic.
[0106] The final value calculation module 140 is used to calculate an expression according to the Boolean values of the plurality of main Boolean factors to obtain the value of the expression to be processed.
[0107] The expression processing module 150 is used to process the value of the expression to be processed according to the processing method corresponding to the call request.
[0108] Each of the above modules can be implemented by a computer program module. Fig. 9 The request processing device shown can be implemented based on a computer program module architecture.
[0109] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.
[0110] The execution subject of the request processing method in the specific implementation manner of the present disclosure may be an electronic device such as a mobile phone, a tablet computer, or a server.
[0111] Therefore, based on any of the above embodiments, the present disclosure further provides an electronic device, which can execute the request processing method of any of the embodiments described above in the present disclosure, and the request processing device of any of the embodiments described above can be configured on the electronic device.
[0112] Fig.10 It is a schematic block diagram of the structure of an electronic device 1000 equipped with a request processing device according to an embodiment of the present disclosure.
[0113] The hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnected buses and bridges, depending on the specific application and overall design constraints of the hardware. The bus 1100 connects various circuits including one or more processors 1200, memory 1300 and / or hardware modules together. The bus 1100 can also connect various other circuits 1400 such as peripherals, voltage regulators, power management circuits, external antennas, etc.
[0114] The bus 1100 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the figure only uses one connecting line, but does not mean that there is only one bus or one type of bus.
[0115] The present disclosure also provides a readable storage medium, in which a computer program is stored, and the computer program is used to implement the above method when executed by a processor. "Readable storage medium" can be any device that can contain, store, communicate, propagate or transmit a program for use in an instruction execution system, device or equipment or in combination with these instruction execution systems, devices or equipment. More specific examples of readable storage media include the following: an electrical connection portion (electronic device) with one or more wirings, a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.
[0116] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed, the process or function of the present disclosure is executed in whole or in part.
[0117] The computer program or instructions may be stored in a readable storage medium or transmitted from one readable storage medium to another readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The readable storage medium may be any available medium that can be accessed or a data storage device such as a server, data center, etc. that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid state drive. The computer readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.
[0118] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0119] The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0120] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0122] In the description of this specification, the description with reference to the terms "one embodiment / method", "some embodiments / methods", "example", "specific example", or "some examples" etc. means that the specific features, structures, or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, or characteristics described may be combined in any one or more embodiments / methods or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments / methods or examples described in this specification and features of different embodiments / methods or examples, unless they are contradictory.
[0123] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0124] Those skilled in the art should understand that the above embodiments are only for the purpose of clearly illustrating the present disclosure, and are not intended to limit the scope of the present disclosure. For those skilled in the art, other changes or modifications may be made based on the above disclosure, and these changes or modifications are still within the scope of the present disclosure.
Claims
1. A request processing method, characterized in that: include: Receive a call request for an expression to be processed; In response to the call request, the short-circuit characteristic of the expression to be processed and the target evaluation order of multiple main Boolean factors of the expression to be processed are obtained, wherein the target evaluation order is determined from different evaluation orders of the multiple main Boolean factors according to the magnitude of normal termination probabilities of multiple expressions corresponding to the different evaluation orders; Obtaining Boolean values of the plurality of main Boolean factors according to the target evaluation order in combination with the short-circuit characteristic; Perform expression calculation according to the Boolean values of the plurality of main Boolean factors to obtain the value of the expression to be processed; as well as The value of the expression to be processed is processed according to the processing method corresponding to the calling request.
2. The request processing method according to claim 1, characterized in that: The obtaining of the short-circuit characteristic of the expression to be processed and the target evaluation order of the plurality of main Boolean factors of the expression to be processed comprises: Obtaining the target evaluation order of the plurality of main Boolean factors from the expression-evaluation order mapping; or, The target evaluation order of the plurality of main Boolean factors is obtained from the different evaluation orders of the plurality of main Boolean factors according to the magnitudes of normal termination probabilities of the plurality of expressions corresponding to the different evaluation orders.
3. The request processing method according to claim 2, characterized in that: The step of obtaining the target evaluation order of the plurality of main Boolean factors from the different evaluation orders of the plurality of main Boolean factors according to the magnitudes of normal termination probabilities of the plurality of expressions corresponding to the different evaluation orders comprises: Obtaining different evaluation orders of the plurality of main Boolean factors; Obtaining normal termination probabilities of multiple expressions corresponding to the different evaluation orders; and The target evaluation order is obtained from the different evaluation orders according to the magnitudes of the normal termination probabilities of the multiple expressions.
4. The request processing method according to claim 3, characterized in that: The obtaining of different evaluation orders of the plurality of main Boolean factors comprises: Using a recursive method to obtain different evaluation orders of the plurality of main Boolean factors; or, Use a full permutation method to obtain different evaluation orders of the plurality of principal Boolean factors; or, A dynamic programming method is used to obtain different evaluation orders of the plurality of main Boolean factors.
5. The request processing method according to claim 3 or 4, characterized in that: For any evaluation order, obtaining normal termination probabilities of multiple expressions corresponding to the different evaluation orders includes: The main Boolean factors are repeatedly calculated in sequence according to the evaluation order and the number of calculations, so as to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time; Performing statistical operations based on the calculation success rate of each main Boolean factor and the Boolean value obtained when each calculation is successful, to obtain a result probability distribution of each main Boolean factor; Obtain the termination probability calculation method corresponding to the evaluation order and operator; and Substituting the result probability distribution of each main Boolean factor into the termination probability calculation method to obtain the normal termination probability of the expression corresponding to the evaluation order; The operator is an operator between the multiple main Boolean factors in the expression to be processed.
6. The request processing method according to claim 5, characterized in that: For any main Boolean factor, the statistical operation is performed according to the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time, including: According to the Boolean value obtained when the main Boolean factor is successfully calculated each time, the number of occurrences of different Boolean values is counted to obtain the true value count and the false value count; Multiplying the calculation success rate of the main Boolean factor by the true value count and the false value count respectively to obtain the true value expectation and the false value expectation; and Dividing the true value expectation and the false value expectation by the number of iterations of the main Boolean factor respectively; The number of iterations is the sum of the number of calculations and the number of retries when the calculations fail.
7. The request processing method according to claim 5, characterized in that: For the first main Boolean factor corresponding to the evaluation order, the main Boolean factors are repeatedly calculated in sequence according to the evaluation order and the number of calculations to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when the calculation is successful each time, including: Repeat the calculation of the first main Boolean factor according to the number of calculations to obtain a first execution state of each calculation; When the first execution state of any calculation is calculation failure, retries are performed until the deadline condition is reached, and the first number of retries is obtained; Obtaining the first iteration number of the first main Boolean factor according to the sum of the number of calculations and the total number of first retries when the calculation fails; and The calculation success rate of the first main Boolean factor is obtained according to the quotient of the number of states in which calculation is successfully performed in the first execution state and the first number of iterations.
8. The request processing method according to claim 5, characterized in that: For any second main Boolean factor other than the first main Boolean factor corresponding to the evaluation order, the main Boolean factors are repeatedly calculated in sequence according to the evaluation order and the number of calculations to obtain the calculation success rate of each main Boolean factor and the Boolean value obtained when each calculation is successful, including: Obtaining the number of short-circuit triggering times of the second main Boolean factor being short-circuited according to the calculation status of the main Boolean factor before the second main Boolean factor in the evaluation order; Obtaining the execution times of the second main Boolean factor according to the difference between the calculation times and the short circuit triggering times; Repeatedly calculate the second main Boolean factor according to the execution number to obtain a second execution state of each calculation; When the second execution state of any calculation is calculation failure, retries are performed until the deadline condition is reached, and the second retry number is obtained; Obtaining the second iteration number of the second main Boolean factor according to the sum of the calculation number and the total second retry number when the calculation fails; and The calculation success rate of the second main Boolean factor is obtained according to the quotient of the number of states in which calculation is successfully performed in the second execution state and the second number of iterations.
9. The request processing method according to claim 8, characterized in that: The cut-off conditions include: The number of retries is greater than the retry threshold or the calculation succeeds.
10. The request processing method according to any one of claims 1 to 4, characterized in that: The performing expression calculation according to the Boolean values of the plurality of main Boolean factors comprises: Obtaining an operator between a plurality of main Boolean factors in the expression to be processed; and The Boolean values of the plurality of main Boolean factors are operated according to the operator.
11. An electronic device, characterized in that: include: A memory storing execution instructions; as well as A processor, wherein the processor executes the execution instruction stored in the memory, so that the processor executes the request processing method according to any one of claims 1 to 10.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the request processing method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Data processing method, electronic device, storage medium and program product
CN118051650A
Method and apparatus for optimizing boolean expression evaluation
US20070174830A1
Obfuscating Computer Program Code
US20100199354A1