Method, device, apparatus and computer readable medium for processing array

By determining the insertion position according to the element parameter value in the array and modifying the pointer, the problem of slow insertion speed of array elements in the prior art is solved, and a more efficient element insertion operation is achieved.

CN113760220BActive Publication Date: 2025-02-21BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011053926.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-29
Publication Date
2025-02-21
Estimated Expiration
2040-09-29

AI Technical Summary

Technical Problem

In the prior art, the complexity of element insertion in an array is high, resulting in slower element insertion speed.

Method used

By determining the position of the element to be inserted in the array based on the parameter values ​​of the existing elements in the array and the parameter values ​​of the element to be inserted, and modifying its pointer to point to the subsequent existing elements or the tail node of the array, and modifying the predecessor at the same time A pointer to the element or first node, pointing to the element to be inserted.

Benefits of technology

Increases the speed of inserting elements in the array and reduces the complexity of insertion operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760220B_ABST
    Figure CN113760220B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, equipment and computer-readable medium for processing an array, and relates to the field of computer technology. A specific implementation of the method includes: determining the position of the first element in the array according to the parameter values ​​of the existing elements in the array and the parameter value of the first element to be inserted into the array; modifying the pointer of the first element so that one or more pointers of the first element point to the existing element after the first element or the tail node of the array; modifying the pointer of the existing element before the first element in the array or the first node of the array so that at least one of the pointers of the existing element before the first element or the first node of the array points to the first element. This implementation can improve the speed of inserting elements in the array.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and computer-readable medium for processing an array. Background Art

[0002] There is no order in the elements in the array. If you want to ensure that the elements in the array are ordered, you usually sort them and display them. The sorting methods are mainly divided into bubble sort, insertion sort and quick sort.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: using the above three sorting methods, the complexity of inserting elements into the array is relatively large, so the element insertion speed is relatively slow. Summary of the invention

[0004] In view of this, embodiments of the present invention provide a method, apparatus, device and computer-readable medium for processing an array, which can increase the speed of inserting elements into an array.

[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for processing an array is provided, comprising:

[0006] Determine the position of a first element in the array according to a parameter value of an existing element in the array and a parameter value of a first element to be inserted into the array, wherein at least one of the existing element and the first element has a plurality of pointers, and the pointers point to the existing elements of the array or the tail node of the array;

[0007] Modify the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array;

[0008] Modify the pointer of the existing element before the first element in the array or the first node of the array so that at least one of the pointer of the existing element before the first element or the first node of the array points to the first element.

[0009] Determining the position of the first element in the array according to the parameter values ​​of the existing elements in the array and the parameter value of the first element to be inserted into the array comprises:

[0010] The position of the first element in the array is determined according to the parameter values ​​of the existing elements of the array and the parameter value of the first element to be inserted into the array in a descending order or a descending order.

[0011] The array has a head node, a pointer of the head node points to an element with a maximum or minimum parameter value in the array, and the head node records the maximum number of pointers to the elements in the array.

[0012] The method further comprises:

[0013] Receiving a query request for elements in the array;

[0014] Determining a parameter value of the element according to the query request;

[0015] The element having the parameter value is searched in descending order of the pointer numbers of the elements of the array.

[0016] In the case where the query request indicates a query for multiple elements in the array, the query request is responded to in the order of the positions of the queried elements in the array, so that information related to the queried elements is displayed in the order of the positions of the queried elements in the array.

[0017] The number of pointers of the elements of the array is between 1 and 32.

[0018] The element is an object related to product information or an object related to user information.

[0019] According to a second aspect of an embodiment of the present invention, there is provided a device for processing an array, comprising:

[0020] a determination module, configured to determine a position of a first element to be inserted into the array according to a parameter value of an existing element in the array and a parameter value of the first element to be inserted into the array, wherein at least one of the existing element and the first element has a plurality of pointers, and the pointers point to the existing elements of the array or the tail node of the array;

[0021] A first modification module, used for modifying the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array;

[0022] The second modification module is used to modify the existing element in the array before the first element or the pointer of the first node of the array, so that at least one of the existing element before the first element or the pointer of the first node of the array points to the first element.

[0023] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for processing an array, comprising:

[0024] one or more processors;

[0025] a storage device for storing one or more programs,

[0026] When the one or more programs are executed by the one or more processors, the one or more processors implement the above method.

[0027] According to a fourth aspect of an embodiment of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method as described above is implemented.

[0028] An embodiment of the above invention has the following advantages or beneficial effects: according to the parameter value of the existing element in the array and the parameter value of the first element to be inserted into the array, the position of the first element in the array is determined, and at least one of the existing element and the first element has multiple pointers, and the pointers point to the existing elements of the array or the tail node of the array; the pointer of the first element is modified so that one or more pointers of the first element point to the existing element after the first element or the tail node of the array; the pointer of the existing element before the first element in the array or the first node of the array is modified so that at least one of the pointers of the existing element before the first element or the first node of the array points to the first element. Since the element can be inserted according to the pointer of the element, the speed of inserting the element in the array can be improved.

[0029] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0031] Figure 1 is a schematic diagram of the main flow of a method for processing an array according to an embodiment of the present invention;

[0032] Figure 2 is a schematic diagram of the structure of an array according to an embodiment of the present invention;

[0033] Figure 3 is a schematic diagram of the structure of Date according to an embodiment of the present invention;

[0034] Figure 4 is a schematic diagram of an array structure according to an embodiment of the present invention;

[0035] Figure 5 is a schematic diagram of an array structure of elements to be inserted according to an embodiment of the present invention;

[0036] Figure 6 is a schematic diagram of a process of searching parameter values ​​according to an embodiment of the present invention;

[0037] Figure 7 is a schematic diagram of the main structure of a device for processing an array according to an embodiment of the present invention;

[0038] Figure 8is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0039] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0040] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0041] Currently, the elements in an array can be sorted in the following ways, including bubble sort, insertion sort, and quick sort, which are briefly described below.

[0042] Method 1: Bubble sort

[0043] (1) Compare adjacent elements. If the first element is larger than the second element, swap the positions of the two elements.

[0044] (2) Do the same thing for each pair of adjacent elements, starting from the first pair at the beginning and ending with the last pair at the end, so that the last element should be the maximum element.

[0045] (3) Repeat the above steps for all elements except the last one.

[0046] (4) Repeat the above steps until the sorting is completed.

[0047] Method 2: Insertion sort

[0048] (1) Starting from the first element, the elements can be considered sorted.

[0049] (2) Take out the next element and scan from the back to the front in the sorted element sequence.

[0050] (3) If the already sorted element is larger than the new element, move the already sorted element to the next position.

[0051] (4) Repeat step (3) until a position is found where the sorted element is less than or equal to the new element.

[0052] (5) After inserting the new element into this position;

[0053] (6) Repeat steps (2) to (5).

[0054] Method 3: Quick sort

[0055] Quick sort uses the divide-and-conquer algorithm to divide a list into two substrings. The specific description is as follows:

[0056] (1) Pick an element from the sequence, called the base value.

[0057] (2) Rearrange the sequence so that all elements smaller than the base value are placed before the base value, and all elements larger than the base value are placed after the base value. After this partition is exited, the base value is in the middle of the sequence. This is called a partition operation.

[0058] (3) Recursively sort the subsequences of elements less than the reference value and the subsequences of elements greater than the reference value.

[0059] The above three sorting methods have greater complexity in inserting elements into the array, so the element insertion speed is slower.

[0060] In order to solve the technical problem of slow insertion speed of elements in an array, the following technical solution in the embodiment of the present invention can be adopted.

[0061] See also Figure 1 , Figure 1 1 is a schematic diagram of the main flow of a method for processing an array according to an embodiment of the present invention, wherein the position of the first element in the array is determined according to the parameter values ​​of the existing elements in the array and the parameter value of the first element to be inserted into the array, wherein at least one of the existing elements and the first element has multiple pointers. Figure 1 As shown, the specific steps include:

[0062] S101. Determine the position of the first element in the array according to the parameter value of the existing elements in the array and the parameter value of the first element to be inserted into the array, wherein at least one of the existing elements and the first element has multiple pointers, and the pointers point to the existing elements of the array or the tail node of the array.

[0063] In the embodiment of the present invention, the elements stored in the array are referred to as existing elements. The elements to be inserted into the array can be referred to as first elements. There are parameter values ​​for each element.

[0064] See also Figure 2 , Figure 2 is a schematic diagram of the structure of an array according to an embodiment of the present invention. Figure 2 It includes the first node head and the last node tail, and each node stored in the array is an element Date.

[0065] The first node records the number of elements in the array and the maximum number of pointers to the elements in the array. As an example, the number of elements is 2 and the maximum number of pointers to the elements in the array is 4.

[0066] It is understandable that the first node includes the following attributes:

[0067] Level: records the maximum number of pointers to elements in the array.

[0068] Length: The length of the array. The length of the array is equal to the number of elements in the array plus two.

[0069] Next: pointer, pointing to the first node of Data

[0070] See also Figure 3 , Figure 3 is a schematic diagram of the structure of Date according to an embodiment of the present invention, Figure 3 It includes pointer number, Date object, Next pointer and Score.

[0071] Pointer number: Randomly generate a value.

[0072] Data object: the stored object, that is, the parameter value of the element.

[0073] Next pointer: points to the next node.

[0074] Score: The sorting dependency value of the object.

[0075] It should be noted that a random number generated by a random number generation software can be used as the pointer number. In practice, it is found that when the pointer number is between 1 and 32, the effect of implementing the solution in the embodiment of the present invention is better, so the pointer number is a random number between 1 and 32.

[0076] It can be understood that the pointer of the first node points to the element with the largest or smallest parameter value in the array, and the first node records the maximum number of pointers to the elements in the array. That is, when the elements in the array are arranged in descending order according to the parameter value, the pointer of the first node points to the element with the largest parameter value in the array; when the elements in the array are arranged in descending order according to the parameter value, the pointer of the first node points to the element with the smallest parameter value in the array.

[0077] After the array is created, the first node of the array is head and the last node is null. When the array is empty, the Next pointer in the Date attribute structure points to null.

[0078] Then, if the array is empty, insert an element and modify the pointer of the element. As an example, insert element a, and randomly generate a pointer number 3 for element a. If the array is empty, that is, there are no other elements in the array, element a is directly inserted into the array. At the same time, modify the maximum number of pointers in head to 3. Modify the pointer of element a to point to null; modify the pointer of head to execute element a.

[0079] The above is a specific process of inserting an element when the array is empty. The following describes a specific process of inserting the first element into the array when the array is not empty, that is, when there are existing elements in the array.

[0080] In one embodiment of the present invention, the position of the first element in the array is determined according to the parameter values ​​of the existing elements of the array and the parameter value of the first element to be inserted into the array in a descending order or a descending order. It is understandable that the elements in the array can be arranged in a descending order or a descending order according to the parameter value.

[0081] In the following embodiments of the present invention, the elements in the array are arranged in ascending order according to the parameter value. It can be understood that the parameter value of the first existing element in the array is the smallest, and the parameter value of the last existing element in the array is the largest.

[0082] See also Figure 4 , Figure 4 is a schematic diagram of an array structure according to an embodiment of the present invention. Figure 4 The diagram includes the structure of 5 arrays.

[0083] exist Figure 4 If the first array does not contain any existing elements, the first node is head and the last node is null. If the array is empty, the pointer in head directly points to null.

[0084] exist Figure 4 In the second array, the first element with parameter value 22 is inserted into the first array. The pointer number of the first element is 1, so the maximum pointer number of the existing elements in the array is 1.

[0085] In an embodiment of the present invention, when an array includes existing elements, the position of the first element in the array is determined according to the parameter value of the existing element in the array and the parameter value of the first element to be inserted into the array. At least one of the existing element and the first element has multiple pointers, and the pointers point to the existing elements of the array or the tail node of the array.

[0086] Continue to see Figure 4 ,exist Figure 4 In the third array, insert the element with parameter value 19 in the second array, and the pointer number of this element is 2.

[0087] In the embodiment of the present invention, the bottom pointer is called the first pointer, and the pointer above the first pointer is called the second pointer. Similarly, the pointer corresponding to the maximum pointer number N is called the Nth pointer.

[0088] Exemplarily, the parameter value of the existing element in the array is 22, and the parameter value of the first element to be inserted into the array is 19, and it is determined that the first element is before the existing element. The first element has 2 pointers.

[0089] S102. Modify the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array.

[0090] After determining the position of the first element in the array, the pointer needs to be modified. In the embodiment of the present invention, modifying the pointer includes modifying the pointer of the first element and modifying the pointers of other elements pointing to the first element.

[0091] Specifically, if there is an existing element after the first element, modify the pointer of the first element so that one or more of the pointers of the first element point to the existing element after the first element in the array; if there is no existing element after the first element, modify the pointer of the first element so that at least one of the pointers of the first element points to the end node of the array.

[0092] Continue to see Figure 4 ,exist Figure 4 In the third array, insert the element with parameter value 19 in the second array, and the pointer number of this element is 2.

[0093] Exemplarily, the parameter value of the first element is 19, and it is determined that the first element is before the existing element. The first element has 2 pointers, the second pointer of the first element points to the end node of the array, and the first pointer of the first element points to the existing element with a parameter value of 22.

[0094] S103: Modify the pointer of the existing element before the first element in the array or the first node of the array so that at least one of the pointers of the existing element before the first element or the first node of the array points to the first element.

[0095] After determining the position of the first element in the array, it is necessary to modify the pointers of other elements or the first node pointing to the first element.

[0096] Specifically, if there is an existing element before the first element, modify the pointers of the existing elements before the first element in the array so that at least one of the pointers of the existing elements before the first element points to the first element; if there is no existing element before the first element, modify the pointer of the first node of the array so that at least one of the pointers of the first node of the array points to the first element.

[0097] Continue to see Figure 4 ,exist Figure 4 In the third array, insert the element with parameter value 19 in the second array, and the pointer number of this element is 2.

[0098] Exemplarily, the parameter value of the first element is 19, and it is determined that there is no existing element before the first element. The first element has 2 pointers, and the pointer of the first node of the array is modified so that the first pointer and the second pointer of the first node of the array all point to the first element.

[0099] It is understandable that S102 and S103 may be executed in any order, that is, S102 may be executed first and then S103, S103 may be executed first and then S102, or S102 and S103 may be executed simultaneously.

[0100] Continue to see Figure 4 ,exist Figure 4 In the fourth array, an element with a parameter value of 7 is inserted into the third array, and the pointer number of the element is 4, which are the first pointer to the fourth pointer. That is, the parameter value of the first element is 7, and it is determined that the first element is before the existing element.

[0101] The first element has 4 pointers, the fourth pointer of the first element points to the end node of the array, the third pointer of the first element points to the end node of the array, the second pointer of the first element points to the existing element whose parameter value is 19, and the first pointer of the first element points to the existing element whose parameter value is 19.

[0102] There is no existing element before the first element. The first element has 4 pointers, and the pointer of the first node of the array is modified so that all four pointers of the first node of the array point to the first element.

[0103] It should be noted that in the process of inserting the first element with a parameter value of 7 into the array, it only needs to be compared with the existing element with a parameter value of 19, and does not involve the existing element with a parameter value of 22. This is because the elements in the array are arranged in order from small to large parameter values. When it is known that the parameter value of the first element is smaller than 19, it does not need to be compared with the existing element with a parameter value of 22, thereby saving insertion time and improving insertion speed.

[0104] Continue to see Figure 4 ,exist Figure 4 In the fifth array, an element with a parameter value of 11 is inserted in the fourth array, and the pointer number of the element is 1. That is, the parameter value of the first element is 11. First, the parameter value relationship between the existing element with parameter value 7 and the first element is compared according to the fourth pointer of the array, and it is known that the first element is after the existing element with parameter value 7.

[0105] Then, the third pointer of the array points to the tail node from the existing element of parameter value 7, so it is known that the first element is after the existing element of parameter value 7.

[0106] The second pointer of the array points from the existing element with parameter value 7 to the existing element with parameter value 19. By comparing the relationship between the parameter values ​​11 and 19 of the first element, it is found that the first element is before the existing element with parameter value 19.

[0107] The first pointer of the array points from the existing element with parameter value 7 to the existing element with parameter value 19, and it is known that the first element is before the existing element with parameter value 19.

[0108] The first element has a first pointer, and the first pointer of the first element points to an existing element whose parameter value is 19. The first element is preceded by an existing element whose parameter value is 7, and the first pointer of the existing element whose parameter value is 7 is modified to point to the first element.

[0109] It should be noted that in the process of inserting the first element with a parameter value of 11 into the array, it only needs to be compared with the existing elements with a parameter value of 7 and the existing elements with a parameter value of 19, and does not involve the existing element with a parameter value of 22. This is because the elements in the array are arranged in order from small to large according to the parameter value. When it is known that the parameter value of the first element is greater than 7 and less than 19, it does not need to be compared with the existing element with a parameter value of 22, thereby saving insertion time and improving insertion speed.

[0110] See also Figure 5 , Figure 5 is a schematic diagram of an array structure according to an embodiment of the present invention, Figure 5 is Figure 4 In the fifth array, insert the first element with parameter value 11.

[0111] The pointer number of the first element is 2, namely the first pointer and the second pointer. First, the parameter value relationship between the existing element of parameter value 7 and the first element is compared according to the fourth pointer of the array, and it is known that the first element is after the existing element of parameter value 7.

[0112] Then, the third pointer of the array points to the tail node from the existing element of parameter value 7, so it is known that the first element is after the existing element of parameter value 7.

[0113] The second pointer of the array points from the existing element with parameter value 7 to the existing element with parameter value 19. By comparing the relationship between the parameter values ​​13 and 19 of the first element, it is found that the first element is before the existing element with parameter value 19.

[0114] The first pointer of the array points from the existing element with parameter value 7 to the existing element with parameter value 11, and it is known that the first element is after the existing element with parameter value 11.

[0115] The first element has two pointers, and the first pointer and the second pointer of the first element both point to an existing element whose parameter value is 19. The first element is preceded by an existing element whose parameter value is 11, and the first pointer of the existing element whose parameter value is 11 is modified to point to the first element.

[0116] It should be noted that in the process of inserting the first element with a parameter value of 13 into the array, it is only necessary to compare with the existing elements with a parameter value of 7, the existing elements with a parameter value of 11, and the existing elements with a parameter value of 19, and it does not involve the existing element with a parameter value of 22. This is because the elements in the array are arranged in order from small to large according to the parameter value. When it is known that the parameter value of the first element is greater than 11 and less than 19, it is not necessary to compare with the existing element with a parameter value of 22, thereby saving insertion time and improving insertion speed.

[0117] In one embodiment of the present invention, elements including parameter values ​​may be searched based on the solution in the above-mentioned embodiment of the present invention.

[0118] See also Figure 6 , Figure 6 1 is a schematic diagram of a process for searching parameter values ​​according to an embodiment of the present invention, which specifically includes the following steps:

[0119] S601: Receive a query request for an element in an array.

[0120] The technical solution in the embodiment of the present invention can be applied to search information. Specifically, during the shopping settlement process, a coupon can be selected. The coupons have different denominations, and they need to be arranged in descending order according to the denominations for the user to select. Among them, the coupon can be used as an element in the array, and the denomination of the coupon is the parameter value of the element.

[0121] It is understandable that the technical solution in the embodiment of the present invention can be executed in the server, and the interaction with the user is realized through the application (APP) of the mobile terminal, that is, the query request for the elements in the array is received through the APP.

[0122] In one embodiment of the present invention, an element is an object related to product information or an object related to user information. As an example, an element may be a product price. As another example, an element may be a user age. It is understood that the element may be set according to the actual application scenario.

[0123] S602: Determine a parameter value of an element according to the query request.

[0124] According to the query request, a search is performed in the database, and then the parameter value of the element that meets the query request is retrieved. As an example, when the element is a coupon, the face value of the coupon can be obtained according to the query request.

[0125] S603. Search for elements with parameter values ​​in descending order of the pointer numbers of the elements of the array.

[0126] After determining the parameter values ​​of multiple elements, the elements with the parameter values ​​can be searched in descending order of the pointer numbers of the elements of the array. Wherein, when an element includes multiple pointers, the pointers are identified by numbers.

[0127] Continue to see Figure 5 , the bottom pointer is called the first pointer, the second bottom pointer is called the second pointer, the pointer above the second pointer is called the third pointer, and the pointer above the third pointer is called the fourth pointer. In the order of the pointer number of the elements of the array from large to small, that is, in the order of the fourth pointer, the third pointer, the second pointer and the first pointer.

[0128] The technical solution of inserting the first element using the technical solutions of S101 to S103 can be applied to searching for elements with parameter values, that is, searching for elements with parameter values ​​in the order of the pointer numbers of the elements of the array from large to small.

[0129] Continue to see Figure 5 , when searching for an element with a parameter value of 11, you can first search according to the fourth pointer, then search according to the third pointer, continue to search according to the second pointer, and finally search according to the first pointer. In the above search process, the existing element with a parameter value of 22 is not involved, so the search speed can be improved.

[0130] In the above Figure 5 In the embodiment, in response to the query request, the element with the parameter value can be searched in time. Since it is not necessary to search all the elements in the array, the search speed is improved.

[0131] In practical applications, the sorting method that is suitable for arranging elements is no longer applicable to sorting objects stored in arrays. This is because arrays store objects. Regardless of whether method 1, method 2 or method 3 is used for sorting, each comparison must parse the object, that is, obtain the parameter value in the object, and then sort it in the above way. If there are many objects, there will be performance problems in the parsing process, which will seriously affect the sorting speed.

[0132] In one embodiment of the present invention, when the query request indicates to query multiple elements in an array, the elements may be displayed in the order of their positions in the array.

[0133] That is, the query request is responded to according to the position order of the queried elements in the array, so that the information related to the queried elements is displayed according to the position order of the queried elements in the array.

[0134] As an example, the query request includes querying coupons with a denomination of more than 20 yuan, and arranging them in order from large to small according to the denomination of the coupons. The coupons are used as elements and the denomination of the coupons are used as parameter values. The coupons in the array are arranged in order from large to small according to the position of the denomination of the coupons. After adopting the technical solution in the above embodiment, the coupons with a denomination of more than 20 yuan can be displayed in order from large to small according to the denomination of the coupons.

[0135] The time complexity of adopting the above solution is described in detail below.

[0136] First, each node in the array has 1 pointer. If a node has the i-th pointer, i ≥ 1, that is, the node is already in the 1st to i-th linked list. Then set the probability that the node has the (i+1)th pointer to p.

[0137] The probability that the number of pointers is exactly equal to 1 is 1-p; the probability that the number of pointers is greater than or equal to 2 is p, and the probability that the number of pointers is exactly equal to 2 is p×(1-p); the probability that the number of pointers is greater than or equal to 3 is p, and the probability that the number of pointers is exactly equal to 3 is p×2×(1-p); the probability that the number of pointers is greater than or equal to 4 is p, and the probability that the number of pointers is exactly equal to 4 is p×3×(1-p), and so on, and so on, we get formula (1).

[0138]

[0139] The corresponding value of p can be set and configured according to different scenarios. If p=1 / 2, then the average number of pointers per node is 2.

[0140] When the array has n nodes, according to the random algorithm of the number of pointers of the nodes, it is easy to get:

[0141] The first linked list is fixed with n nodes;

[0142] The second linked list has an average of n×p nodes;

[0143] The third linked list has an average of n×p 2 nodes;

[0144] It can be seen that from the first to the maximum number of pointers, the average number of nodes in each linked list is an exponentially decreasing geometric progression.

[0145] The above array has n nodes, and the probability p that n nodes have a pointer is 0 , p 0 is equal to 100%; the probability of having two pointers is p 1 ; The probability of having L pointers is p L-1 .

[0146] The expectation of having L pointers is 1 / p, and the probability of each element having L pointers is p L-1 . Then the expectation of having L pointers is n×p L-1 .

[0147] Therefore: 1 / p = n × p L-1 .

[0148] The reasoning process is as follows:

[0149] 1 / p=n×p L-1

[0150] n=(1 / p) L

[0151] L = log1 / p×n Formula (2)

[0152] It is known that the mean value of the number of pointers is log1 / p×n, and the average number of nodes with L pointers is 1 / p.

[0153] The expected length of a path climbing from level 1 to level L(n) in a list of n elements is (L(n)-1) / p.

[0154] Substituting formula (2) into the expected path, we can get:

[0155] (log1 / p×n-1) / p Formula (3)

[0156] Assuming p = 1 / 2, substituting into formula (3) we get: 2*log2n-2, which means the average time complexity is o(logn).

[0157] It can be seen that by sorting with different numbers of pointers, the time complexity can meet the requirements.

[0158] In the above-mentioned embodiment of the present invention, according to the parameter value of the existing element in the array and the parameter value of the first element to be inserted into the array, the position of the first element in the array is determined, at least one of the existing element and the first element has multiple pointers, and the pointers point to the existing elements of the array or the tail node of the array; the pointer of the first element is modified so that one or more pointers of the first element point to the existing element after the first element or the tail node of the array; the pointer of the existing element before the first element in the array or the first node of the array is modified so that at least one of the pointers of the existing element before the first element or the first node of the array points to the first element. Since the element can be inserted according to the pointer of the element, the speed of inserting the element can be improved.

[0159] In addition, elements can also be searched according to a query request. When the query request includes multiple elements, the information related to the elements is displayed according to the position order of the multiple elements in the array. That is, the multiple elements are sorted. Since the sorting is performed in descending order according to the pointer number, the number of comparisons of parameter values ​​is reduced, thereby improving the speed of element sorting.

[0160] See also Figure 7 , Figure 7 is a schematic diagram of the main structure of an array processing device according to an embodiment of the present invention. The array processing device can implement an array processing method, such as Figure 7 As shown, the device for processing an array specifically includes:

[0161] A determination module 701 is used to determine the position of a first element in an array according to a parameter value of an existing element in an array and a parameter value of a first element to be inserted into the array, wherein at least one of the existing element and the first element has a plurality of pointers, and the pointers point to the existing elements of the array or the tail node of the array;

[0162] A first modification module 702, configured to modify the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array;

[0163] The second modification module 703 is used to modify the existing element before the first element in the array or the pointer of the first node of the array, so that at least one of the existing element before the first element or the pointer of the first node of the array points to the first element.

[0164] In one embodiment of the present invention, the determination module 701 is specifically used to determine the position of the first element in the array according to the parameter values ​​of the existing elements of the array and the parameter values ​​of the first element to be inserted into the array in a descending order or a descending order.

[0165] In one embodiment of the present invention, the pointer of the head node points to the element with the maximum or minimum parameter value in the array, and the head node records the maximum number of pointers to the elements in the array.

[0166] In one embodiment of the present invention, the determination module 701 is further configured to receive a query request for elements in the array;

[0167] Determining a parameter value of the element according to the query request;

[0168] The element having the parameter value is searched in descending order of the pointer numbers of the elements of the array.

[0169] In one embodiment of the present invention, the determination module 701 is specifically used to respond to the query request according to the position order of the queried elements in the array when the query request indicates a query on multiple elements in the array, so that information related to the queried elements is displayed according to the position order of the queried elements in the array.

[0170] In one embodiment of the present invention, the number of pointers of the elements of the array is between 1 and 32.

[0171] In one embodiment of the present invention, the element is an object related to product information or an object related to user information.

[0172] Figure 8 An exemplary system architecture 800 is shown to which the method for processing an array or the apparatus for processing an array according to the embodiments of the present invention can be applied.

[0173] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.

[0174] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0175] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0176] The server 805 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 801, 802, and 803. The backend management server may analyze and process the received product information query request and other data, and feed back the processing results (such as target processing array, product information - only an example) to the terminal device.

[0177] It should be noted that the method for processing an array provided in the embodiment of the present invention is generally executed by the server 805 , and accordingly, the device for processing an array is generally disposed in the server 805 .

[0178] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0179] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0180] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0181] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.

[0182] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.

[0183] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0184] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0185] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a receiving module, a retrieval module, a sorting module and a push module, wherein the names of these modules do not constitute a limitation on the unit itself under certain circumstances, for example, the receiving module is used to receive an information query request, and the information query request includes a query condition.

[0186] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:

[0187] Determine the position of a first element in the array according to a parameter value of an existing element in the array and a parameter value of a first element to be inserted into the array, wherein at least one of the existing element and the first element has a plurality of pointers, and the pointers point to the existing elements of the array or the tail node of the array;

[0188] Modify the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array;

[0189] Modify the pointer of the existing element before the first element in the array or the first node of the array so that at least one of the pointer of the existing element before the first element or the first node of the array points to the first element.

[0190] According to the technical solution of the embodiment of the present invention, the position of the first element in the array is determined according to the parameter value of the existing element in the array and the parameter value of the first element to be inserted into the array, and at least one of the existing element and the first element has multiple pointers, and the pointers point to the existing elements of the array or the tail node of the array; the pointer of the first element is modified so that one or more pointers of the first element point to the existing element after the first element or the tail node of the array; the pointer of the existing element before the first element in the array or the first node of the array is modified so that at least one of the pointers of the existing element before the first element or the first node of the array points to the first element. Since the element can be inserted according to the pointer of the element, the speed of inserting the element in the array can be improved.

[0191] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for processing an array, characterized in that: include: Determine the position of a first element in the array according to a parameter value of an existing element in the array and a parameter value of a first element to be inserted into the array, wherein at least one of the existing element and the first element has a plurality of pointers, and the pointers point to the existing elements of the array or the tail node of the array; Modify the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array; Modify the pointer of the existing element in the array before the first element or the first node of the array so that at least one of the pointer of the existing element before the first element or the first node of the array points to the first element; The method further comprises: During the shopping checkout process, a coupon is selected and a query request for an element in the array is received; Determining a parameter value of the element according to the query request; The element having the parameter value is searched in descending order of the pointer numbers of the elements of the array; the coupon is an element in the array, and the denomination of the coupon is the parameter value of the element.

2. The method for processing an array according to claim 1, characterized in that: Determining the position of the first element in the array according to the parameter values ​​of the existing elements in the array and the parameter value of the first element to be inserted into the array comprises: The position of the first element in the array is determined according to the parameter values ​​of the existing elements of the array and the parameter value of the first element to be inserted into the array in a descending order or a descending order.

3. The method for processing an array according to claim 1, characterized in that: The pointer of the first node points to the element with the maximum or minimum parameter value in the array, and the first node records the maximum number of pointers to the elements in the array.

4. The method for processing an array according to claim 1, characterized in that: In the case where the query request indicates a query for multiple elements in the array, the query request is responded to in the order of the positions of the queried elements in the array, so that information related to the queried elements is displayed in the order of the positions of the queried elements in the array.

5. The method for processing an array according to claim 1, characterized in that: The number of pointers to the elements of the array is between 1 and 32.

6. According to the method for processing an array according to any one of claims 1 to 5, the element is an object related to product information or an object related to user information.

7. A device for processing an array, characterized in that: include: A determination module, used to determine the position of the first element in the array according to the parameter value of the existing elements in the array and the parameter value of the first element to be inserted into the array, wherein at least one of the existing elements and the first element has multiple pointers, and the pointers point to the existing elements of the array or the tail node of the array; and is also used to select a coupon during the shopping settlement process, receive a query request for the elements in the array; determine the parameter value of the element according to the query request; search for the element with the parameter value in the order of the number of pointers of the elements of the array from large to small; the coupon is an element in the array, and the face value of the coupon is the parameter value of the element; A first modification module, used for modifying the pointer of the first element so that one or more pointers of the first element point to an existing element after the first element or the tail node of the array; The second modification module is used to modify the existing element in the array before the first element or the pointer of the first node of the array, so that at least one of the existing element before the first element or the pointer of the first node of the array points to the first element.

8. An electronic device for processing an array, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.

9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Wait-free stack operation method based on array structure under multinuclear environment

    CN106843806A

  • A storage and search method of multiple index hash table

    CN1952932A