CN113760220A - Method, device, equipment and computer readable medium for processing array - Google Patents

Method, device, equipment and computer readable medium for processing array Download PDF

Info

Publication number
CN113760220A
CN113760220A CN202011053926.9A CN202011053926A CN113760220A CN 113760220 A CN113760220 A CN 113760220A CN 202011053926 A CN202011053926 A CN 202011053926A CN 113760220 A CN113760220 A CN 113760220A
Authority
CN
China
Prior art keywords
array
pointer
existing
elements
pointers
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011053926.9A
Other languages
Chinese (zh)
Inventor
姜振飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202011053926.9A priority Critical patent/CN113760220A/en
Publication of CN113760220A publication Critical patent/CN113760220A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/22Arrangements for sorting or merging computer data on continuous record carriers, e.g. tape, drum, disc
    • G06F7/24Sorting, i.e. extracting data from one or more carriers, rearranging the data in numerical or other ordered sequence, and rerecording the sorted data on the original carrier or on a different carrier or set of carriers sorting methods in general

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method, a device, equipment and a computer readable medium for processing an array, and relates to the technical field of computers. One embodiment of the method comprises: determining the position of a first element in an 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 an existing element after the first element or a tail node of the array; and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointer of the existing element before the first element or the head node of the array points to the first element. This embodiment can increase the speed of insertion of elements in the array.

Description

Method, device, equipment and computer readable medium for processing array
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a computer-readable medium for processing an array.
Background
The elements in the array are unordered, if the elements in the array are guaranteed to be ordered, the elements in the array are generally ordered and then displayed by an ordering method, and the ordering method mainly comprises bubble ordering, insertion ordering and quick ordering.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: by adopting the three sorting methods, the complexity of inserting elements in the array is high, so that the element inserting speed is low.
Disclosure of Invention
In view of the above, embodiments of the present invention provide a method, an apparatus, a device, and a computer-readable medium for processing an array, which can improve the speed of inserting elements in the array.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of processing an array, including:
determining the position of a first element in an array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or a tail node of the array;
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 a tail node of the array;
and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointer of the existing element before the first element or the head node of the array points to the first element.
The 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:
and determining the position of the first element in the array according to the sequence from large to small or from small to large of the parameter values of the existing elements of the array and the parameter values of the first element to be inserted into the array.
The array has a head node, 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 pointer number of the element in the array.
The method further comprises the following steps:
receiving a query request for elements in the array;
determining parameter values of the elements according to the query request;
and searching the elements with the parameter values according to the order of the pointer number of the elements of the array from large to small.
And responding to the query request according to the position sequence of the queried elements in the array under the condition that the query request indicates to query a plurality of elements in the array, so that the information related to the queried elements is displayed according to the position sequence of the queried elements in the array.
The number of pointers to the elements of the array is between 1 and 32.
The element is an object related to commodity information or an object related to user information.
According to a second aspect of the embodiments of the present invention, there is provided an apparatus for processing an array, including:
the determining module is used for determining the position of a first element in an array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or a tail node of the array;
a first modification module, 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 a tail node of the array;
a second modification module, configured to modify an existing element in the array before the first element or a pointer of a head node of the array, so that at least one of the existing element before the first element or the pointer of the head node of the array points to the first element.
According to a third aspect of embodiments of the present invention, there is provided an electronic device for processing an array, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method as described above.
According to a fourth aspect of embodiments of the present invention, there is provided a computer readable medium, on which a computer program is stored, which when executed by a processor, implements the method as described above.
One embodiment of the above invention has the following advantages or benefits: determining the position of a first element in an array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or a tail node of the array; 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 a tail node of the array; and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointers of the existing element before the first element or the head node of the array points to the first element. Since the elements can be inserted according to their pointers, the speed of insertion of the elements in the array can be increased.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of a main flow of a method of processing an array according to an embodiment of the invention;
FIG. 2 is a schematic diagram of an array structure according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a Date structure according to an embodiment of the invention;
FIG. 4 is a diagram illustrating an array structure according to an embodiment of the present invention;
FIG. 5 is a diagram illustrating an array structure of elements to be inserted according to an embodiment of the present invention;
FIG. 6 is a flow diagram of searching for parameter values according to an embodiment of the invention;
FIG. 7 is a schematic diagram of the main structure of an apparatus for processing arrays according to an embodiment of the present invention;
FIG. 8 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 9 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
At present, the elements in the array may be sorted according to the following methods, specifically including bubble sorting, insertion sorting, and quick sorting, which are briefly described below.
The method comprises the following steps: bubble ordering
(1) Adjacent elements are compared and if the first element is larger than the second element, the positions of the two elements are swapped.
(2) The same is done for each pair of adjacent elements, starting with the first pair and ending with the last pair, so that the element at the end should be the largest element.
(3) The above steps are repeated for all elements except the last element.
(4) And repeating the steps until the sorting is completed.
The second method comprises the following steps: insertion ordering
(1) Starting with the first element, the element may be considered to have been sorted.
(2) The next element is fetched and scanned from back to front in the sequence of elements that have been sorted.
(3) If the already sorted element is larger than the new element, the already sorted element is moved to the next position.
(4) And (4) repeating the step (3) until a position is found where the sorted element is smaller than or equal to the new element.
(5) After inserting the new element into the position;
(6) and (5) repeating the steps (2) to (5).
The third method comprises the following steps: fast sequencing
Fast sorting uses a divide and conquer approach to divide a string (list) into two sub-strings. The specific description is as follows:
(1) an element is picked from the sequence, called the reference value.
(2) And rearranging the sequence, wherein all elements smaller than the reference value are arranged in front of the reference value, and all elements larger than the reference value are arranged behind the reference value. After this partition exits, the reference is in the middle of the array. This is called a partition operation.
(3) The sequence of sub-numbers smaller than the reference value element and the sequence of sub-numbers larger than the reference value element are recursively sorted.
The three sorting methods described above have a high complexity of inserting elements in the array, and therefore the element insertion speed is slow.
In order to solve the technical problem of slow insertion speed of elements in the array, the following technical scheme in the embodiment of the invention can be adopted.
Referring to fig. 1, fig. 1 is a schematic diagram of a main flow of a method for processing an array according to an embodiment of the present invention, and a position of a first element in the array is determined 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, where at least one of the existing element and the first element has a plurality of pointers. As shown in fig. 1, the method specifically comprises the following steps:
s101, determining the position of the first element in the array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or the tail node of the array.
In embodiments of the present invention, elements that have been stored in an array are referred to as existing elements. The element to be inserted into the array may be referred to as the first element. There is a parameter value for each element.
Referring to fig. 2, fig. 2 is a schematic diagram of an array structure according to an embodiment of the present invention. The head node and tail node are included in fig. 2, and each node in the array store is an element Date.
The number of elements in the array and the maximum number of pointers to elements in the array are recorded in the head node. As an example, the number of elements is 2, the maximum number of pointers for the elements in the array is 4.
It will be appreciated that the head node includes the following attributes:
level: the maximum number of pointers to elements in the array is recorded.
Length: the array length, which is equal to the number of elements in the array plus two.
Next: pointer to the first node of Data
Referring to fig. 3, fig. 3 is a schematic diagram of a Date structure according to an embodiment of the present invention, and fig. 3 includes a pointer number, a Date object, a Next pointer, and a Score.
The number of pointers is: a value is randomly generated.
Data object: the stored object, i.e. the parameter value of the element.
A Next pointer: pointing to the next node.
Score: the ordering of the objects depends on the value.
Note that, as the pointer number, a random number generated by random number generation software may be used. In practice, it is found that the effect of the solution in the embodiment of the present invention is better in the case that the number of pointers is between 1 and 32, and therefore, the number of pointers is a random number from 1 to 32.
It will be appreciated that the pointer of the head node points to the element in the array having the largest or smallest parameter value, and the head node records the largest number of pointers for the elements in the array. That is, when the elements in the array are arranged according to the order of the parameter values from large to small, 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 according to the sequence of the parameter values from small to large, the pointer of the first node points to the element with the minimum parameter value in the array.
After the array is built, the head node of the array is head and the tail node is null. In the case of an array empty, the Next pointer in the Date attribute structure points to null.
Then, in the case where the array is empty, an element is inserted and the pointer to that element is modified. As an example, an a-element is inserted, which randomly generates the pointer number 3. In the case of an array being empty, i.e. there are no other elements in the array, then the a element is inserted directly into the array. While the maximum number of pointers in the modified head is 3. Modifying the pointer of the a element to point to null; modifying the pointer of the head executes the a element.
The specific process of inserting the element when the array is empty is described above, and the specific process of inserting the first element into the array when the array is not empty, that is, when there is an existing element in the array is described below.
In one embodiment of the invention, the position of the first element in the array is determined according to the descending or ascending order of the parameter value of the existing element of the array and the parameter value of the first element to be inserted into the array. It will be appreciated that the elements in the array may be arranged from large to small or from small to large according to the parameter values.
In the following embodiments of the present invention, the elements in the array are arranged in the order of the parameter values from small to large. It will be appreciated that the parameter value for the first existing element in the array is the smallest and the parameter value for the last existing element in the array is the largest.
Referring to fig. 4, fig. 4 is a schematic diagram of an array structure according to an embodiment of the present invention. Fig. 4 includes a schematic diagram of the structure of 5 arrays.
In fig. 4, if the first array does not include an existing element, the head node is head and the tail node is null. In the case of an empty array, the head pointer points directly to null.
In the second array of fig. 4, the first element with the parameter value of 22 is inserted into the first array, the pointer number of the first element is 1, and the maximum pointer number of the existing elements in the array is 1.
In the embodiment of the invention, under the condition that the array comprises the existing elements, 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 element and the first element has a plurality of pointers, the pointers pointing to the existing element of the array or to a tail node of the array.
With continued reference to FIG. 4, in the third array of FIG. 4, an element with a parameter value of 19 is inserted in the second array, the number of pointers to this element being 2.
In the embodiment of the present invention, the lowermost pointer is referred to as a first pointer, and the pointer above the first pointer is referred to as a second pointer. By analogy, the pointer corresponding to the maximum pointer number N is referred to as the nth pointer.
Illustratively, the parameter value for the existing element in the array is 22, the parameter value for the first element to be inserted into the array is 19, and the first element is determined to precede the existing element. Where the first element has 2 pointers.
S102, modifying the pointer of the first element to enable one or more pointers of the first element to point to tail nodes of existing elements or arrays behind the first element.
After the location of the first element in the array is determined, the pointer needs to be modified. In embodiments of the present invention, modifying the pointer includes modifying the pointer of the first element and modifying the pointers of the other elements to the first element.
In particular, there is an existing element after the first element, the pointers to the first element are modified such that one or more of the pointers to the first element point to the existing element in the array that is after the first element; the existing element does not exist after the first element, and the pointers of the first element are modified so that at least one of the pointers of the first element points to the tail node of the array.
With continued reference to FIG. 4, in the third array of FIG. 4, an element with a parameter value of 19 is inserted in the second array, the number of pointers to this element being 2.
Illustratively, the parameter value of the first element is 19, which is determined to precede 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 an existing element whose parameter value is 22.
S103, modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointer of the existing element before the first element or the head node of the array points to the first element.
After the first element is located in the array, the pointer to the first element from the other elements or the first node needs to be modified.
Specifically, existing elements exist before the first element, and pointers of the existing elements in the array before the first element are modified, so that at least one of the pointers of the existing elements before the first element points to the first element; the pointers to the head node of the array are modified such that at least one of the pointers to the head node of the array points to the first element.
With continued reference to FIG. 4, in the third array of FIG. 4, an element with a parameter value of 19 is inserted in the second array, the number of pointers to this element being 2.
Illustratively, the parameter value for the first element is 19, determining 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 such that the first pointer and the second pointer of the first node of the array all point to the first element.
It is understood that S102 and S103 may be performed in any order, i.e., S102 is performed first and S103 is performed, S103 is performed first and S102 is performed second, or S102 and S103 are performed simultaneously.
With continued reference to fig. 4, in the fourth array of fig. 4, an element having a parameter value of 7 is inserted in the third array, the number of pointers of the element is 4, and the first pointer to the fourth pointer are respectively. I.e. the parameter value of the first element is 7, it is determined that the first element precedes the existing element.
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 an existing element whose parameter value is 19, and the first pointer of the first element points to an existing element whose parameter value is 19.
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.
It should be noted that, in the process of inserting the first element with the parameter value of 7 in the array, only the existing element with the parameter value of 19 needs to be compared, and the existing element with the parameter value of 22 is not involved. The elements in the array are arranged in the order of the parameter values from small to large, and when the parameter value of the first element is known to be smaller than 19, the element does not need to be compared with the existing element with the parameter value of 22, so that the insertion time is saved, and the insertion speed is increased.
With continued reference to fig. 4, in the fifth array of fig. 4, an element having a parameter value of 11 is inserted in the fourth array, and the number of pointers of the element is 1. That is, the parameter value of the first element is 11. Firstly, the relation between the existing element of the parameter value 7 and the parameter value of the first element is compared according to the fourth pointer of the array, and the first element is known to be behind the existing element of the parameter value 7.
The third pointer of the array then points from the existing element of parameter value 7 to the tail node, thus learning that the first element is behind the existing element of parameter value 7.
The second pointer of the array points to the existing element with the parameter value 19 from the existing element with the parameter value 7, and the relation between the parameter values 11 and 19 of the first element is compared to know that the first element is before the existing element with the parameter value 19.
The first pointer of the array points from an existing element of parameter value 7 to an existing element of parameter value 19, knowing that the first element precedes the existing element of parameter value 19.
The first element has a first pointer, the first pointer of the first element pointing to an existing element whose parameter value is 19. The first element is preceded by an existing element having a parameter value of 7, and a first pointer to the first element is modified to modify the existing element having a parameter value of 7.
It should be noted that, in the process of inserting the first element with the parameter value of 11 in the array, only the existing element with the parameter value of 7 and the existing element with the parameter value of 19 need to be compared, and the existing element with the parameter value of 22 is not involved. This is because the elements in the array are arranged in the order of the parameter values from small to large, and when knowing that the parameter value of the first element is larger than 7 and smaller than 19, it is not necessary to compare with the existing element with the parameter value of 22, thereby saving the insertion time and increasing the insertion speed.
Referring to fig. 5, fig. 5 is a schematic diagram of an array structure according to an embodiment of the present invention, and fig. 5 is a diagram illustrating a first element with a parameter value of 11 inserted in the fifth array of fig. 4.
Wherein the number of pointers of the first element is 2, i.e. the first pointer and the second pointer. Firstly, the relation between the existing element of the parameter value 7 and the parameter value of the first element is compared according to the fourth pointer of the array, and the first element is known to be behind the existing element of the parameter value 7.
The third pointer of the array then points from the existing element of parameter value 7 to the tail node, thus learning that the first element is behind the existing element of parameter value 7.
The second pointer of the array points to the existing element with the parameter value 19 from the existing element with the parameter value 7, and the relation between the parameter values 13 and 19 of the first element is compared to know that the first element is before the existing element with the parameter value 19.
The first pointer of the array points from the existing element of parameter value 7 to the existing element of parameter value 11, knowing that the first element is behind the existing element of parameter value 11.
The first element has 2 pointers, the first and second pointers of the first element both pointing to an existing element whose parameter value is 19. The first element is preceded by an existing element having a parameter value of 11, and the first element is pointed to by a first pointer that modifies the existing element having a parameter value of 11.
It should be noted that, in the process of inserting the first element with the parameter value of 13 in the array, only the existing element with the parameter value of 7, the existing element with the parameter value of 11, and the existing element with the parameter value of 19 need to be compared, and the existing element with the parameter value of 22 is not involved. This is because the elements in the array are arranged in the order of the parameter values from small to large, and when knowing that the parameter value of the first element is larger than 11 and smaller than 19, it is not necessary to compare with the existing element with the parameter value of 22, thereby saving the insertion time and increasing the insertion speed.
In one embodiment of the present invention, the element including the parameter value may be searched based on the scheme in the above embodiment of the present invention.
Referring to fig. 6, fig. 6 is a schematic flowchart of a process of searching for parameter values according to an embodiment of the present invention, which specifically includes the following steps:
s601, receiving a query request for the elements in the array.
The technical scheme in the embodiment of the invention can be applied to searching information. Specifically, during settlement of a purchase, a coupon may be selected. If the coupons have different denominations, the coupons need to be arranged in the descending order of the denomination for the user to select. The coupon can be used as an element in an array, and the denomination of the coupon is the parameter value of the element.
It can be understood that the technical solution in the embodiment of the present invention may be executed in a server. And the interaction with the user is realized through the Application (APP) of the mobile terminal. That is, a query request for an element in an array is received through an APP.
In one embodiment of the present invention, the element is an object related to commodity information or an object related to user information. As one example, the element may be a price of the item. As another example, the element may be a user age. It is to be understood that the elements may be arranged according to an actual application scenario.
S602, determining parameter values of the elements according to the query request.
And according to the query request, searching in the database. And then retrieve the parameter values for the elements that meet the query request. As an example, in the case where the element is a coupon, the denomination of the coupon can be known from the query request.
S603, searching the elements with parameter values according to the order of the pointer number of the elements of the array from big to small.
After determining the parameter values of the plurality of elements, the elements having the parameter values may be searched in order of the number of pointers of the elements of the array from large to small. Where an element includes multiple pointers, the pointers are identified by numbers.
With continued reference to FIG. 5, the lowermost pointer is referred to as the first pointer, the next lower pointer is referred to as the second pointer, the pointer above the second pointer is referred to as the third pointer, and the pointer above the third pointer is referred to as the fourth pointer. The pointer numbers of the elements of the array are in the order from large to small, namely in the order of the fourth pointer, the third pointer, the second pointer and the first pointer.
The technical solution of inserting the first element using the technical solutions of S101 to S103 may be applied to search for elements having parameter values. That is, the elements having parameter values are searched for in order of the number of pointers of the elements of the array from large to small.
With continued reference to FIG. 5, in searching for an element having a parameter value of 11, a search may be conducted first according to the fourth pointer, then according to the third pointer, then continuing with the second pointer, and finally according to the first pointer. In the above search process, the existing element having the parameter value of 22 is not involved, and thus the search speed can be increased.
In the embodiment of FIG. 5 described above, elements having parameter values may be searched for in a timely manner in response to a query request. And all elements in the array do not need to be searched, so that the searching speed is improved.
In practical application, the sorting method suitable for the arrangement elements is not suitable for the sorting of the array storage objects. The object is stored in the array, and no matter the objects are sorted by the method I, the method II and the method III, the objects need to be analyzed in each comparison, namely, the parameter values in the objects are obtained, and then the objects are sorted by the above method. If there are more objects, there will be performance problem in the parsing process, and the sorting speed will be seriously affected.
In an embodiment of the present invention, in the case that the query request indicates that a query is performed on a plurality of elements in the array, the elements may be displayed according to the position order of the elements in the array.
That is, in the query request, the query request is responded according to the position sequence of the queried element in the array, so that the information related to the queried element is displayed according to the position sequence of the queried element in the array.
As one example, the inquiry request includes inquiring about coupons having coupon denominations above 20 dollars, and arranging the coupons in order of decreasing coupon denominations. The coupon is taken as an element, and the coupon denomination is taken as a parameter value. The coupons in the array are arranged according to the position sequence of the coupon denomination from big to small. By adopting the technical scheme in the embodiment, the coupons with the coupon denominations of more than 20 yuan can be displayed according to the sequence of coupon denominations from large to small.
The time complexity of using the above scheme is specifically described below.
First, there are 1 pointer per node in the array. If a node has the ith pointer, i ≧ 1, i.e., the node is already in the 1 st to ith linked lists. Then the probability that the node has the (i +1) th pointer is set to p.
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 equal to or greater than 4 is p, the probability that the number of pointers is exactly equal to 4 is p × 3 × (1-p), and so on to obtain formula (1).
Figure BDA0002710360320000131
And the corresponding value of p can be configured according to different scenes, and if p is 1/2, the average pointer number of each node is 2.
When the array has n nodes, the random algorithm is easily obtained according to the pointer number of the nodes:
n nodes are fixed on the 1 st linked list;
the 2 nd linked list has n multiplied by p nodes on average;
the 3 rd linked list has n x p on average2A node;
it can be seen that from the 1 st to the maximum number of pointers, the average number of nodes in each linked list is an exponential decreasing geometric sequence.
The array has n nodes with a probability p of having a pointer0,p0Equal to 100%; probability of having two pointers is p1(ii) a Probability of having L pointers is pL-1
The expectation of having L pointers is 1/p, and the probability of having L pointers per element is pL-1. Then the expectation of having L pointers is nxpL-1
Thus: 1/p ═ n × pL-1
The reasoning process is as follows:
1/p=n×pL-1
n=(1/p)L
l log1/p × n formula (2)
The mean of the number of learned pointers is log1/p n, while the average number of nodes with L pointers is 1/p.
The expected length of the path from level 1 to level l (n)/p in the list of n elements (l (n) -1).
Bringing equation (2) into the desired path, one can obtain:
(log1/p × n-1)/p formula (3)
Assuming that p is 1/2, the substitution into equation (3) can result: 2 log2 n-2. I.e. average temporal complexity of o (logn).
Therefore, the time complexity can meet the requirement by sequencing through different pointer numbers.
In the above 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, at least one of the existing element and the first element has a plurality of pointers, and the pointers point to the existing element of the array or the tail node of the array; 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 a tail node of the array; and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointers of the existing element before the first element or the head node of the array points to the first element. Since the elements can be inserted in accordance with their pointers, the speed of inserting the elements can be increased.
In addition, elements may also be searched according to a query request. And in the case that the query request comprises a plurality of elements, displaying the information related to the elements according to the position sequence of the elements in the array. That is, ordering of multiple elements is achieved. As the sorting is performed according to the order of the pointer number from large to small, the comparison times of the parameter values are reduced, and the speed of sorting the elements is further improved.
Referring to fig. 7, fig. 7 is a schematic diagram of a main structure of an apparatus for processing an array according to an embodiment of the present invention, where the apparatus for processing an array may implement a method for processing an array, and as shown in fig. 7, the apparatus for processing an array specifically includes:
a determining module 701, configured to determine, 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, a position of the first element in the array, where at least one of the existing element and the first element has multiple pointers, and the pointers point to the existing element of the array or a tail node of the array;
a first modifying 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 a tail node of the array;
a second modifying module 703, configured to 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.
In an embodiment of the present invention, the determining module 701 is specifically configured to determine, according to a descending order or descending order of the parameter value of the existing element of the array and the parameter value of the first element to be inserted into the array, a position of the first element in the array.
In one embodiment of the invention, the pointer of the head node points to the element in the array having the largest or smallest parameter value, and the head node records the largest number of pointers of the elements in the array.
In an embodiment of the present invention, the determining module 701 is further configured to receive a query request for an element in the array;
determining parameter values of the elements according to the query request;
and searching the elements with the parameter values according to the order of the pointer number of the elements of the array from large to small.
In an embodiment of the present invention, the determining module 701 is specifically configured to, when the query request indicates to query the multiple elements in the array, respond to the query request according to a position order of the queried 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.
In one embodiment of the invention, the number of pointers to the elements of the array is between 1 and 32.
In one embodiment of the present invention, the element is an object related to commodity information or an object related to user information.
Fig. 8 illustrates an exemplary system architecture 800 to which the method of processing an array or the apparatus for processing an array of the embodiments of the present invention may be applied.
As shown in fig. 8, the system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. The network 804 serves to provide a medium for communication links between the terminal devices 801, 802, 803 and the server 805. Network 804 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 801, 802, 803 to interact with a server 805 over a network 804 to receive or send messages or the like. The terminal devices 801, 802, 803 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 801, 802, 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 805 may be a server that provides various services, such as a back-office management server (for example only) that supports shopping-like websites browsed by users using the terminal devices 801, 802, 803. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, a target processing array and product information — just an example) to the terminal device.
It should be noted that the method for processing an array provided by the embodiment of the present invention is generally executed by the server 805, and accordingly, the apparatus for processing an array is generally disposed in the server 805.
It should be understood that the number of terminal devices, networks, and servers in fig. 8 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 9, shown is a block diagram of a computer system 900 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 9 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 9, the computer system 900 includes a Central Processing Unit (CPU)901 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)902 or a program loaded from a storage section 908 into a Random Access Memory (RAM) 903. In the RAM 903, various programs and data necessary for the operation of the system 900 are also stored. The CPU 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input/output (I/O) interface 905 is also connected to bus 904.
The following components are connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output section 907 including components such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 908 including a hard disk and the like; and a communication section 909 including a network interface card such as a LAN card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The drive 910 is also connected to the I/O interface 905 as necessary. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The above-described functions defined in the system of the present invention are executed when the computer program is executed by a Central Processing Unit (CPU) 901.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a receiving module, a retrieving module, a sorting module, and a pushing module, where names of the modules do not in some cases constitute a limitation on the unit itself, e.g., the receiving module is configured to receive an information query request, the information query request including a query condition.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
determining the position of a first element in an array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or a tail node of the array;
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 a tail node of the array;
and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointer of the existing element before the first element or the head node of the array points to the first element.
According to the technical scheme of the embodiment of the invention, the position of a first element in an 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 is provided with a plurality of pointers, and the pointers point to the existing element of the array or the tail node of the array; 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 a tail node of the array; and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointers of the existing element before the first element or the head node of the array points to the first element. Since the elements can be inserted according to their pointers, the speed of insertion of the elements in the array can be increased.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of processing an array, comprising:
determining the position of a first element in an array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or a tail node of the array;
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 a tail node of the array;
and modifying the pointer of the existing element before the first element or the head node of the array in the array, so that at least one of the pointer of the existing element before the first element or the head node of the array points to the first element.
2. The method for processing an array as claimed in claim 1, wherein the determining the position of the first element in the array 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 comprises:
and determining the position of the first element in the array according to the sequence from large to small or from small to large of the parameter values of the existing elements of the array and the parameter values of the first element to be inserted into the array.
3. The method of claim 1, wherein the pointer of the head node points to the element of the array having the largest or smallest parameter value, and wherein the head node records the largest number of pointers for the elements of the array.
4. The method of processing an array of claim 1, further comprising:
receiving a query request for elements in the array;
determining parameter values of the elements according to the query request;
and searching the elements with the parameter values according to the order of the pointer number of the elements of the array from large to small.
5. The method for processing an array according to claim 4, wherein in a case where the query request indicates to query a plurality of elements in the array, 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.
6. The method of claim 1, wherein the number of pointers to elements of the array is between 1 and 32.
7. The method for processing arrays according to any one of claims 1 to 6, wherein the element is an object related to commodity information or an object related to user information.
8. An apparatus for processing an array, comprising:
the determining module is used for determining the position of a first element in an array 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, wherein at least one of the existing element and the first element is provided with a plurality of pointers, and the pointers point to the existing element of the array or a tail node of the array;
a first modification module, 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 a tail node of the array;
a second modification module, configured to modify an existing element in the array before the first element or a pointer of a head node of the array, so that at least one of the existing element before the first element or the pointer of the head node of the array points to the first element.
9. An electronic device for processing an array, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202011053926.9A 2020-09-29 2020-09-29 Method, device, equipment and computer readable medium for processing array Pending CN113760220A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011053926.9A CN113760220A (en) 2020-09-29 2020-09-29 Method, device, equipment and computer readable medium for processing array

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011053926.9A CN113760220A (en) 2020-09-29 2020-09-29 Method, device, equipment and computer readable medium for processing array

Publications (1)

Publication Number Publication Date
CN113760220A true CN113760220A (en) 2021-12-07

Family

ID=78785825

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011053926.9A Pending CN113760220A (en) 2020-09-29 2020-09-29 Method, device, equipment and computer readable medium for processing array

Country Status (1)

Country Link
CN (1) CN113760220A (en)

Similar Documents

Publication Publication Date Title
CN110019211A (en) The methods, devices and systems of association index
CN110019080B (en) Data access method and device
CN107704202B (en) Method and device for quickly reading and writing data
CN107480205B (en) Method and device for partitioning data
CN108256070A (en) For generating the method and apparatus of information
CN108540508B (en) Method, device and equipment for pushing information
CN107609192A (en) The supplement searching method and device of a kind of search engine
CN111400304A (en) Method and device for acquiring total data of section dates, electronic equipment and storage medium
CN110909022A (en) Data query method and device
CN111401684A (en) Task processing method and device
CN110110184B (en) Information inquiry method, system, computer system and storage medium
CN113761565B (en) Data desensitization method and device
CN110109912A (en) A kind of identifier generation method and device
CN113760220A (en) Method, device, equipment and computer readable medium for processing array
CN107977381B (en) Data configuration method, index management method, related device and computing equipment
JP6859407B2 (en) Methods and equipment for data processing
CN113780827A (en) Article screening method and device, electronic equipment and computer readable medium
CN113704242A (en) Data processing method and device
CN108733668B (en) Method and device for querying data
CN112016017A (en) Method and device for determining characteristic data
CN114449031B (en) Information acquisition method, device, equipment and storage medium
CN113360765B (en) Event information processing method and device, electronic equipment and medium
CN111651475B (en) Information generation method and device, electronic equipment and computer readable medium
CN110084710A (en) Determine the method and device of message subject
CN112667627B (en) Data processing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination