Data sorting method, device, equipment, storage medium and program product

By introducing a circular doubly linked list structure into the binary heap and using the cursor node pointer to quickly locate the node to be updated, the problem of high time complexity in locating the tail node in the existing technology is solved, and the efficiency of data update and sorting operations is improved.

CN113204681BActive Publication Date: 2024-09-10MICROFUN INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110496458.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-07
Publication Date
2024-09-10
Estimated Expiration
2041-05-07

AI Technical Summary

Technical Problem

The existing binary heap data sorting method based on pointer chain has high time complexity when locating the tail node, resulting in high time complexity for adding or deleting data to be updated.

Method used

Using a circular doubly linked list structure, the current cursor node is located through the current cursor node pointer, and the node to be updated is determined according to the update type, and data update and sorting operations are performed to reduce time complexity.

Benefits of technology

Quickly locate the cursor node through a circular doubly linked list to quickly locate the node to be updated and reduce the time complexity of data update and sorting operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113204681B
    Figure CN113204681B
Patent Text Reader

Abstract

The embodiment of the present invention provides a data sorting method, device, equipment, storage medium and program product, the method comprising: obtaining a data sorting update request, the data sorting update request comprising: data to be updated and an update type; according to the data sorting update request, determining the current cursor node according to the pointing of the current cursor node pointer from a circular bidirectional linked list corresponding to a binary heap storing the original data; determining the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node; updating and sorting the original data according to the node to be updated and the data to be updated. The embodiment of the present invention can realize the rapid positioning of the cursor node through the circular bidirectional linked list, thereby realizing the rapid positioning of the node to be updated, and reducing the time complexity of updating and sorting the original data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data sorting technology, and in particular to a data sorting method, device, equipment, storage medium and program product. Background Art

[0002] A binary heap is a data structure based on a binary tree. It is widely used to select the largest or smallest N data from a large amount of data and a priority queue, that is, to sort data.

[0003] When the data sorting method of the binary heap based on the pointer chain in the prior art is applied to realize a priority queue such as a timer queue, the tail node needs to be located when adding or deleting the data to be updated in the original data. The process of locating the tail node needs to be located step by step from the root node to the tail node according to the child node pointers of each node in the binary heap.

[0004] However, the time complexity of locating the tail node in the above-mentioned existing method is high, which leads to high time complexity of adding or deleting the data to be updated, that is, high time complexity of updating and sorting the original data. Summary of the invention

[0005] Embodiments of the present invention provide a data sorting method, apparatus, device, storage medium and program product to solve the technical problem that in the existing data sorting method based on a pointer chain binary heap, the time complexity of locating the tail node is high, resulting in high time complexity for adding or deleting data to be updated.

[0006] In a first aspect, an embodiment of the present invention provides a data sorting method, the method comprising:

[0007] Obtaining a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type;

[0008] According to the data sorting update request, the current cursor node is determined from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the pointing of the current cursor node pointer, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layer, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node;

[0009] Determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node;

[0010] The original data is updated and sorted according to the nodes to be updated and the data to be updated.

[0011] In a possible implementation, determining the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node includes:

[0012] If it is determined that the update type is to add a data type, then the to-be-updated node corresponding to the to-be-updated data is determined to be a to-be-added child node of the current cursor node;

[0013] If it is determined that the update type is a deletion data type, the node to be updated corresponding to the data to be updated is determined to be the tail node, and the node to be deleted corresponding to the data to be updated is determined.

[0014] In a possible implementation, if it is determined that the node to be updated is a child node to be added by the cursor node, then updating and sorting the original data according to the node to be updated and the data to be updated includes:

[0015] Add a child node to the cursor node as a node to be updated, and add the data to be updated to the node to be updated to complete the update operation on the original data;

[0016] According to the data to be updated in the node to be updated and the data in the parent node corresponding to the node to be updated, determine whether the node to be updated and the parent node corresponding to the node to be updated need to be exchanged. If so, exchange the parent node corresponding to the node to be updated and the node to be updated to complete the sorting operation of the original data.

[0017] In a possible implementation, if it is determined that the node to be updated is the tail node, then updating and sorting the original data according to the node to be updated and the data to be updated includes:

[0018] Delete the tail node to complete the update operation on the original data;

[0019] The tail node is used to replace the node to be deleted as a new node;

[0020] Based on the data in the new node and the data in the child node corresponding to the node to be deleted, determine whether the new node and the child node corresponding to the node to be deleted need to be exchanged. If so, exchange the new node and the child node corresponding to the node to be deleted to complete the sorting operation of the original data.

[0021] In a possible implementation manner, the circular bidirectional linked list includes leaf nodes and cursor nodes of non-cursor nodes in the binary heap, and current pointing relationships corresponding to leaf nodes and cursor nodes of non-cursor nodes in the binary heap;

[0022] After the updating operation is performed on the original data according to the node to be updated and the data to be updated, the method further includes:

[0023] The current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node.

[0024] In a possible implementation, the nodes of the binary heap are arranged from left to right and from top to bottom to form a node sequence;

[0025] The current pointing relationship corresponding to the leaf nodes of the non-cursor nodes and the cursor nodes in the binary heap specifically includes:

[0026] The left node pointer of the leaf node that is not a cursor node and a tail node points to the previous node of the leaf node, the right node pointer of the leaf node points to the next node of the leaf node, the left node pointer of the cursor node points to the tail node, the right node pointer of the cursor node points to the next node of the cursor node, the left node pointer of the tail node points to the previous node of the tail node, and the right node pointer of the tail node points to the cursor node.

[0027] In a possible implementation, if the update type is to add a data type and the type of the current cursor node is the first leaf node, then updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node includes:

[0028] Update the left node pointer of the node to be updated to point to the previous node of the node to be updated, update the right node pointer of the node to be updated to point to the current cursor node, update the right node pointer of the previous node of the node to be updated to point to the node to be updated, update the left node pointer of the current cursor node to point to the node to be updated, and keep the pointing direction of the current cursor node pointer unchanged.

[0029] In a possible implementation, if the update type is to add a data type and the type of the current cursor node is a half node, updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node includes:

[0030] Update the left node pointer of the node to be updated to point to the previous node of the node to be updated, update the right node pointer of the node to be updated to point to the next node of the current cursor node, update the right node pointer of the previous node of the node to be updated to point to the node to be updated, update the right node pointer of the current cursor node to point to the node to be updated, update the current cursor node to be the next node of the current cursor node, and update the left node pointer of the updated current cursor node to point to the node to be updated.

[0031] In a possible implementation, if the update type is a delete data type and the type of the current cursor node is the first leaf node, the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node, including:

[0032] Update the right node pointer of the previous node of the current cursor node to point to the current cursor node, update the left node pointer of the current cursor node to point to the previous node of the current cursor node, update the current cursor node to be the previous node of the current cursor node, and update the right node pointer of the previous node of the node to be updated to point to the updated current cursor node.

[0033] In a possible implementation, if the update type is a delete data type and the type of the current cursor node is a half-node, updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node includes:

[0034] Update the left node pointer of the current cursor node to point to the previous node of the node to be updated, update the right node pointer of the previous node of the node to be updated to point to the current cursor node, and keep the pointing direction of the current cursor node pointer unchanged.

[0035] In a second aspect, an embodiment of the present invention provides a data sorting device, comprising:

[0036] An acquisition module, used for acquiring a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type;

[0037] A first determination module is used to determine the current cursor node according to the direction of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the data sorting update request, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layer, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node;

[0038] A second determination module, configured to determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node;

[0039] An execution module is used to update and sort the original data according to the nodes to be updated and the data to be updated.

[0040] In a third aspect, an embodiment of the present invention provides a data sorting device, including: a memory and at least one processor; the at least one processor includes: a first heterogeneous processing module and a second heterogeneous processing module;

[0041] The memory stores computer-executable instructions;

[0042] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the data sorting method as described in any one of the first aspects.

[0043] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in any one of the first aspects is implemented.

[0044] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program, and when the computer program is executed by a processor, the method described in any one of the first aspects is implemented.

[0045] The data sorting method, apparatus, device, storage medium and program product provided by the embodiments of the present invention obtain a data sorting update request including the data to be updated and the update type, and according to the data sorting update request, determine the current cursor node according to the pointing of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data, and determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node, and update and sort the original data according to the node to be updated and the data to be updated, so as to realize rapid positioning of the cursor node through the circular bidirectional linked list, thereby realizing rapid positioning of the node to be updated, and reducing the time complexity of updating and sorting the original data. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0047] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present invention;

[0048] Figure 2 A schematic diagram of a flow chart of a data sorting method provided by an embodiment of the present invention;

[0049] Figure 3 A schematic diagram of a flow chart of another data sorting method provided by an embodiment of the present invention;

[0050] Figure 4 A schematic diagram of a cursor node and a current pointing relationship update process provided by an embodiment of the present invention;

[0051] Figure 5 A schematic diagram of another updating process of a cursor node and a current pointing relationship provided by an embodiment of the present invention;

[0052] Figure 6 A schematic diagram of another updating process of a cursor node and a current pointing relationship provided by an embodiment of the present invention;

[0053] Figure 7 A schematic diagram of another updating process of a cursor node and a current pointing relationship provided by an embodiment of the present invention;

[0054] Figure 8 A schematic diagram of the structure of a data sorting device provided by an embodiment of the present invention;

[0055] Fig. 9 A schematic diagram of the structure of a data sorting device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0057] As a data structure based on binary tree, binary heap is a complete binary tree or an approximately complete binary tree. It is widely used to select the largest or smallest N data from a large amount of data and priority queues, that is, to sort data. The implementation of binary heap is usually based on pointer chain. In this method, the root node can usually be directly located according to the root node pointer, while the location of other nodes of the binary heap is based on the child node pointer of each node, step by step from the root node to each node.

[0058] The data sorting method of the binary heap based on the pointer chain is applied to realize the priority queue. For example, when realizing the timer queue, the tail node needs to be located when adding or deleting the data to be updated. The usual operation of locating the tail node is to locate the tail node step by step from the root node according to the child node pointer of each node in the binary heap. The time complexity of this process is O(log2N), where N is the number of nodes in the binary heap. However, in the above existing methods, the time complexity of locating the tail node is high, resulting in a high time complexity of adding or deleting the data to be updated, that is, it takes a long time.

[0059] In order to solve the above problem, an embodiment of the present invention sets a pointer to directly point to the current cursor node, defines the current cursor node as the first leaf node or half node in the binary heap, and forms a circular bidirectional linked list based on the leaf nodes and cursor nodes of all non-cursor nodes in the binary heap, and the circular bidirectional linked list also includes the current pointing relationship corresponding to the leaf nodes and cursor nodes of all the above non-cursor nodes, by obtaining a data sorting update request, the data sorting update request includes: data to be updated and an update type, and according to the data sorting update request, the current cursor node is determined according to the pointing of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data, and the node to be updated corresponding to the data to be updated in the binary heap is determined according to the update type and the current cursor node, and the original data is updated and sorted according to the node to be updated and the data to be updated, so that the current cursor node can be updated based on the current pointing relationship in the circular bidirectional linked list, and the cursor node can be quickly located, thereby realizing the fast positioning of the node to be updated, and reducing the time complexity of updating and sorting the original data.

[0060] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present invention. Figure 1 As shown, the solution provided by the embodiment of the present invention can be applied to a data sorting device, which obtains a data sorting update request and performs processing operations on a binary heap storing original data stored in the sorting device, thereby finally updating and sorting the original data.

[0061] Figure 2 The flowchart of a data sorting method provided by an embodiment of the present invention is shown in FIG. The execution subject of the method in the embodiment of the present invention may be a data sorting device. Figure 2 As shown, the method in this embodiment may include:

[0062] Step 201: Obtain a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type.

[0063] In this embodiment, the update type can be to add data type or to delete data type, and the data to be updated corresponds to the update type. If the update type is to add data type, the data to be updated is the data to be added. If the update type is to delete data type, the data to be updated is the data to be deleted. Correspondingly, the update of the add data type is to add the data to be added to the binary heap storing the original data, and the update of the delete data type is to delete the data to be deleted from the binary heap storing the original data.

[0064] Step 202: According to the data sorting update request, the current cursor node is determined from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the pointing of the current cursor node pointer, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layers, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node.

[0065] In this embodiment, the current cursor node is the first leaf node or half node in the above-mentioned binary heap, and the current cursor node pointer points to the current cursor node, and as the current cursor node is updated, it points to the updated current cursor node, so that the current cursor node can be located within a time complexity of O(1), thereby reducing the time complexity of locating the current cursor node.

[0066] Step 203: Determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node.

[0067] In this embodiment, based on whether the update type is to add data type or delete data type, it can be determined that the node to be updated is the next empty position of the tail node or the tail node. Based on whether the current cursor node is a leaf node or a half node, it can be determined that the node to be updated is the left child node to be added, the right child node to be added, the right child node of the previous node of the current cursor node, or the left child node of the current cursor node.

[0068] Step 204: update and sort the original data according to the nodes to be updated and the data to be updated.

[0069] In this embodiment, an update operation is performed on the original data, that is, the data to be added is added to the binary heap storing the original data, or the data to be deleted is deleted from the binary heap storing the original data. In order to maintain the properties of the binary heap itself, that is, to maintain the properties of the maximum heap or the minimum heap of the binary heap, after the update operation is performed on the original data, it is necessary to perform a sorting operation on the nodes in the binary heap, that is, to perform a sorting operation on the original data, especially to perform a sorting operation on the nodes to be updated and the child nodes or parent nodes of the nodes to be updated.

[0070] It should be noted that the above binary heap is "forward placed", that is, the root node of the binary heap is at the top layer and the leaf nodes are at the bottom layer. In addition, the binary heap can also be "sideways placed" and "reverse placed", etc. For example, when the binary heap is "sideways placed", the root node of the binary heap can be on the leftmost side and the leaf nodes can be on the right side. When the binary heap is "reverse placed", the root node of the binary heap can be on the bottom side and the leaf nodes can be on the top side. When the binary heap is "sideways placed" and "reverse placed", the processing method of the binary heap is similar to the processing method when the binary heap is "forward placed". The specific implementation process and principle can be referred to the embodiment of the binary heap "forward placed", which will not be repeated here.

[0071] The data sorting method provided in this embodiment obtains a data sorting update request including the data to be updated and the update type, and according to the data sorting update request, determines the current cursor node according to the pointing of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data, and determines the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node, updates and sorts the original data according to the node to be updated and the data to be updated, and can quickly locate the cursor node by constructing a circular bidirectional linked list, thereby realizing fast positioning of the node to be updated, and reducing the time complexity of updating and sorting the original data.

[0072] At the same time, the circular bidirectional linked list includes leaf nodes and cursor nodes of non-cursor nodes in the binary heap, as well as current pointing relationships corresponding to leaf nodes and cursor nodes of non-cursor nodes. In order to ensure that the cursor nodes can be updated in time to ensure rapid positioning of the cursor nodes, the cursor nodes and the current pointing relationships can optionally be updated. Specifically, after the original data is updated according to the node to be updated and the data to be updated, it can also include: updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node.

[0073] Specifically, the nodes of a binary heap are arranged from left to right and from top to bottom to form a node order; the pointing relationship corresponding to the leaf nodes and cursor nodes of non-cursor nodes in the binary heap specifically includes: the left node pointer of the leaf node of the non-cursor node and the tail node points to the previous node of the leaf node, the right node pointer of the leaf node points to the next node of the leaf node, the left node pointer of the cursor node points to the tail node, the right node pointer of the cursor node points to the next node of the cursor node, the left node pointer of the tail node points to the previous node of the tail node, and the right node pointer of the tail node points to the cursor node.

[0074] The data sorting method provided in this embodiment can update the cursor node and the current pointing relationship in a timely manner after completing the update operation on the original data, so as to ensure the rapid positioning of the cursor node and maintain the correctness of the circular bidirectional linked list.

[0075] In order to timely update the cursor node and ensure that the cursor node can be quickly located, the embodiment of the present invention will further describe the update of the current cursor node and the update of the current pointing relationship under different update types and different types of current cursor nodes.

[0076] Figure 3 A flow chart of another data sorting method provided by an embodiment of the present invention. Figure 3 As shown, this embodiment is a detailed description of updating the current cursor node and the current pointing relationship based on the technical solution provided in the above embodiment. The method in this embodiment may include:

[0077] Step 301: Obtain a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type.

[0078] Step 302: According to the data sorting update request, the current cursor node is determined from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the pointing of the current cursor node pointer, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layers, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node.

[0079] The specific implementation process and principle of steps 301 to 302 in this embodiment can be found in the above-mentioned embodiment and will not be described again here.

[0080] Step 303: If it is determined that the update type is to add a data type, determine that the node to be updated corresponding to the data to be updated is a child node to be added of the current cursor node.

[0081] Step 304: If it is determined that the update type is a deletion data type, determine that the node to be updated corresponding to the data to be updated is the tail node, and determine the node to be deleted corresponding to the data to be updated.

[0082] Steps 303 to 304 define the process of determining the node to be updated.

[0083] Specifically, when the update type is to add data type, the node to be updated is the next empty position of the tail node, and the next empty position of the tail node is the child node to be added of the current cursor node, that is, when the current cursor node is the first leaf node, the current cursor node has no left child node, then the node to be updated is the left child node to be added of the current cursor node; when the current cursor node is a half node, the current cursor node has a left child node, then the node to be updated is the right child node to be added of the current cursor node.

[0084] Optionally, when the update type is to add a data type and the binary heap is empty, the node to be updated is the root node.

[0085] Furthermore, when the update type is the delete data type, the node to be updated is the tail node, that is, when the current cursor node is the first leaf node, the current cursor node has no left child node, then the node to be updated is the right child node of the previous node of the current cursor node; when the current cursor node is a half node, the current cursor node has a left child node, then the node to be updated is the left child node of the current cursor node.

[0086] Optionally, when the update type is a delete data type and the binary heap has only one root node, the node to be updated is the root node.

[0087] Specifically, when the update type is a delete data type, the to-be-deleted node corresponding to the to-be-updated data is the node corresponding to the to-be-updated data in the binary heap.

[0088] Step 305: If it is determined that the node to be updated is a child node to be added to the cursor node, a child node is added to the cursor node as the node to be updated, and the data to be updated is added to the node to be updated to complete the update operation on the original data.

[0089] In this embodiment, if the node to be updated is a child node to be added to the cursor node, the current update type is to add data type. According to the cursor node, it is determined to add a left child node or a right child node to the cursor node as the node to be updated, and the update data is added to the above-mentioned node to be updated.

[0090] Step 306: If the update type is to add a data type, the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node.

[0091] Optionally, the step of updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node may be as follows: if the update type is to increase the data type, the type of the current cursor node is the first leaf node, the left node pointer of the node to be updated is updated to point to the previous node of the node to be updated, the right node pointer of the node to be updated is updated to point to the current cursor node, the right node pointer of the previous node of the node to be updated is updated to point to the node to be updated, the left node pointer of the current cursor node is updated to point to the node to be updated, and the pointing direction of the current cursor node pointer is kept unchanged. In addition, the parent node pointer of the node to be updated is updated to point to the current cursor node. Figure 4 A schematic diagram of a cursor node and a current pointing relationship update process provided by an embodiment of the present invention. Figure 4 As shown, the hollow circles represent the nodes in the binary heap, and the solid circles represent the current cursor node. To make the diagram clear, Figure 4 The parent node pointer of each node is not shown.

[0092] Further, optionally, the step of updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node may be as follows: if the update type is to increase the data type, the type of the current cursor node is a half node, the left node pointer of the node to be updated is updated to point to the previous node of the node to be updated, the right node pointer of the node to be updated is updated to point to the next node of the current cursor node, the right node pointer of the previous node of the node to be updated is updated to point to the node to be updated, the right node pointer of the current cursor node is updated to point to the node to be updated, and the current cursor node pointer is updated to point to the next node of the current cursor node, that is, the current cursor node is updated to be the next node of the current cursor node, and the left node pointer of the updated current cursor node is updated to point to the node to be updated. In addition, the parent node pointer of the node to be updated is updated to point to the current cursor node before the update. Figure 5 A schematic diagram of another updating process of a cursor node and a current pointing relationship provided by an embodiment of the present invention. Figure 5 As shown, the hollow circles represent the nodes in the binary heap, and the solid circles represent the current cursor node. To make the diagram clear, Figure 5 The parent node pointer of each node is not shown.

[0093] Optionally, the step of updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node may be as follows: if the update type is to add a data type and the binary heap is empty, the node to be updated is the root node, and the current cursor node pointer points to the node to be updated.

[0094] Step 307: Determine whether the node to be updated and the parent node corresponding to the node to be updated need to be exchanged based on the data to be updated in the node to be updated and the data in the parent node corresponding to the node to be updated. If so, exchange the parent node corresponding to the node to be updated and the node to be updated to complete the sorting operation of the original data.

[0095] In this embodiment, the data to be updated in the node to be updated is compared with the data in the parent node corresponding to the node to be updated to determine whether the above nodes need to be exchanged. For example, if the binary heap is a maximum heap, when the data to be updated in the node to be updated is larger than the data in the parent node corresponding to the node to be updated, it is necessary to exchange the parent node corresponding to the node to be updated and the node to be updated to complete the sorting operation of the original data.

[0096] Furthermore, the exchange operation on the parent node corresponding to the node to be updated and the node to be updated may specifically include: pointing the right node pointer of the node pointed to by the left node pointer of the node to be updated to a special value, such as 0xFFFFFFFFFFFFFFFE, and pointing the left node pointer of the node pointed to by the right node pointer of the node to be updated to the above special value; updating the parent node pointer of the parent node corresponding to the node to be updated to point to the node to be updated, and updating the parent node pointer corresponding to the node to be updated to point to the parent node of the above parent node; if the left child node, right child node and parent node pointers of the parent node corresponding to the node to be updated point to the parent node corresponding to the node to be updated, then point the above pointers to the node to be updated; updating the left node pointer and right node pointer of the node to be updated to point to the same as the left node pointer and right node pointer of the parent node corresponding to the node to be updated; pointing the right node of the node whose right node pointer points to a special value to the parent node corresponding to the node to be updated, and pointing the left node pointer of the node whose left node pointer points to the special value to the parent node corresponding to the node to be updated.

[0097] Steps 305 to 307 define the process of updating and sorting the original data when the node to be updated is a child node of the cursor node.

[0098] Step 308: If it is determined that the node to be updated is the tail node, the tail node is deleted to complete the update operation on the original data.

[0099] In this embodiment, if the node to be updated is the tail node, the current update type is the delete data type. According to the current cursor node, the tail node is determined to be the right child node of the previous node of the current cursor node or the left child node of the current cursor node. The data in the above tail node is temporarily stored in a temporary variable, and the tail node is deleted.

[0100] Step 309: If the update type is a delete data type, the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node.

[0101] Optionally, the step of updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node is executed. Specifically, it can be: if the update type is the delete data type, and the type of the current cursor node is the first leaf node, then the right node pointer of the previous node of the current cursor node is updated to point to the current cursor node, the left node pointer of the current cursor node is updated to point to the previous node of the current cursor node, and the current cursor node pointer is updated to point to the previous node of the current cursor node, that is, the current cursor node is updated to be the previous node of the current cursor node, and the right node pointer of the previous node of the node to be updated is updated to point to the updated current cursor node. Figure 6 A schematic diagram of another updating process of a cursor node and a current pointing relationship provided by an embodiment of the present invention. Figure 6 As shown, the hollow circle represents the node in the binary heap, the solid circle represents the current cursor node, and the dotted hollow circle represents the deleted node to be updated. To make the diagram clear, Figure 6 The parent node pointer of each node is not shown.

[0102] It should be noted that since the previous node of the current cursor node cannot be directly determined through the current cursor node, it is necessary to determine the previous node of the current cursor node based on a circular bidirectional linked list. Specifically, the previous node of the current cursor node can be determined as follows: after deleting the tail node, the left node pointer of the current cursor node points to its predecessor node, and the parent node of the predecessor node can be determined based on the parent node pointer of the predecessor node. The above parent node is the previous node of the current cursor node.

[0103] Further, optionally, the step of updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node is executed. Specifically, it can also be: if the update type is a delete data type and the type of the current cursor node is a half-node, then the left node pointer of the current cursor node is updated to point to the previous node of the node to be updated, and the right node pointer of the previous node of the node to be updated is updated to point to the current cursor node, and the pointing direction of the current cursor node pointer is kept unchanged. Figure 7 A schematic diagram of another updating process of a cursor node and a current pointing relationship provided by an embodiment of the present invention. Figure 7 As shown, the hollow circle represents the node in the binary heap, the solid circle represents the current cursor node, and the dotted hollow circle represents the deleted node to be updated. To make the diagram clear, Figure 7 The parent node pointer of each node is not shown.

[0104] Optionally, the step of updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node is performed. Specifically, if the update type is a delete data type, and the binary heap has one and only one root node, then the current cursor node is the above-mentioned root node, the node to be updated is the above-mentioned root node, and the root node pointer and the current cursor node pointer are cleared.

[0105] Step 310: Use the tail node to replace the node to be deleted as a new node.

[0106] In this embodiment, the data of the tail node temporarily stored in the temporary variable is used to replace the data in the node to be deleted, that is, the tail node is used to replace the node to be deleted. If the pointers of the left child node, right child node and parent node of the node to be deleted point to the node to be deleted, the pointers are pointed to the new node, and the left node pointer, right node pointer and parent node pointer of the new node are updated to be the same as the left node pointer, right node pointer and parent node pointer of the node to be deleted.

[0107] Step 311: Determine whether the new node and the child nodes corresponding to the node to be deleted need to be exchanged based on the data in the new node and the data in the child nodes corresponding to the node to be deleted. If so, exchange the new node and the child nodes corresponding to the node to be deleted to complete the sorting operation of the original data.

[0108] In this embodiment, the data in the new node is compared with the data in the child node corresponding to the node to be deleted to determine whether the above nodes need to be exchanged. For example, if the binary heap is a maximum heap, when the data in the new node is smaller than the data in the child node corresponding to the node to be deleted, the new node needs to be exchanged with the child node corresponding to the node to be deleted to complete the sorting operation of the original data.

[0109] Furthermore, the exchange operation of the new node with the child node corresponding to the node to be deleted may specifically include: pointing the right node pointer of the node pointed to by the left node pointer of the child node corresponding to the node to be deleted to a special value, such as 0xFFFFFFFFFFFFFFFE, and pointing the left node pointer of the node pointed to by the right node pointer of the child node corresponding to the node to be deleted to the above-mentioned special value; updating the parent node pointer of the new node to point to the child node corresponding to the node to be deleted, and updating the parent node pointer of the child node corresponding to the node to be deleted to point to the parent node of the new node; if the left child node, right child node and parent node pointers of the new node point to the new node, then point the above pointers to the child node corresponding to the node to be deleted; update the left node pointer and right node pointer of the child node corresponding to the node to be deleted to point to the same as the left node pointer and right node pointer of the new node; point the right node of the node whose right node pointer points to a special value to the new node, and point the left node pointer of the node whose left node pointer points to the special value to the new node.

[0110] It should be noted that if the child node corresponding to the node to be deleted is neither a leaf node nor a half-node, its left node pointer points to its left child node, and its right node pointer points to its right child node. If the child node corresponding to the node to be deleted is a half-node, its left node pointer points to its left child node.

[0111] Steps 308 to 311 define the process of updating and sorting the original data when the node to be updated is the tail node.

[0112] The data sorting method provided in the present embodiment obtains a data sorting update request, determines the current cursor node according to the pointing of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the update request, and determines the node to be updated according to the update type, and then updates and sorts the original data according to the node to be updated and the data to be updated, and updates the current cursor node and the current pointing relationship according to different update types and different types of the current cursor node, so that the current cursor node can be updated in time, and the current pointing relationship can be updated, so as to ensure the maintenance of the correctness of the circular bidirectional linked list and the rapid positioning of the cursor node, thereby realizing the rapid positioning of the node to be updated, and reducing the time complexity of updating and sorting operations on the original data.

[0113] Figure 8 A schematic diagram of the structure of a data sorting device provided by an embodiment of the present invention. Figure 8 As shown, the data sorting device provided in this embodiment may include: an acquisition module 81 , a first determination module 82 , a second determination module 83 and an execution module 84 .

[0114] An acquisition module 81 is used to acquire a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type;

[0115] A first determination module 82 is used to determine the current cursor node according to the direction of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the data sorting update request, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layers, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node;

[0116] A second determination module 83, configured to determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node;

[0117] The execution module 84 is used to update and sort the original data according to the nodes to be updated and the data to be updated.

[0118] In an optional implementation, the second determining module 83 is specifically configured to:

[0119] If it is determined that the update type is to add a data type, then the to-be-updated node corresponding to the to-be-updated data is determined to be a to-be-added child node of the current cursor node;

[0120] If it is determined that the update type is a deletion data type, the node to be updated corresponding to the data to be updated is determined to be the tail node, and the node to be deleted corresponding to the data to be updated is determined.

[0121] In an optional implementation, when determining that the node to be updated is a child node to be added of the cursor node, the execution module 84 is specifically configured to:

[0122] Add a child node to the cursor node as a node to be updated, and add the data to be updated to the node to be updated to complete the update operation on the original data;

[0123] According to the data to be updated in the node to be updated and the data in the parent node corresponding to the node to be updated, determine whether the node to be updated and the parent node corresponding to the node to be updated need to be exchanged. If so, exchange the parent node corresponding to the node to be updated and the node to be updated to complete the sorting operation of the original data.

[0124] In an optional implementation, when determining that the node to be updated is the tail node, the execution module 84 is further specifically configured to:

[0125] Delete the tail node to complete the update operation on the original data;

[0126] The tail node is used to replace the node to be deleted as a new node;

[0127] Based on the data in the new node and the data in the child node corresponding to the node to be deleted, determine whether the new node and the child node corresponding to the node to be deleted need to be exchanged. If so, exchange the new node and the child node corresponding to the node to be deleted to complete the sorting operation of the original data.

[0128] In an optional implementation, after performing an update operation on the original data according to the to-be-updated node and the to-be-updated data, the execution module 84 is further configured to:

[0129] The current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node.

[0130] In an optional implementation, when the update type is to add a data type and the type of the current cursor node is the first leaf node, the execution module 84 is further used to update the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node:

[0131] Update the left node pointer of the node to be updated to point to the previous node of the node to be updated, update the right node pointer of the node to be updated to point to the current cursor node, update the right node pointer of the previous node of the node to be updated to point to the node to be updated, update the left node pointer of the current cursor node to point to the node to be updated, and keep the pointing direction of the current cursor node pointer unchanged.

[0132] In an optional implementation, when the update type is to add a data type and the type of the current cursor node is a half node, the execution module 84 is further used to update the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node:

[0133] Update the left node pointer of the node to be updated to point to the previous node of the node to be updated, update the right node pointer of the node to be updated to point to the next node of the current cursor node, update the right node pointer of the previous node of the node to be updated to point to the node to be updated, update the right node pointer of the current cursor node to point to the node to be updated, update the current cursor node to be the next node of the current cursor node, and update the left node pointer of the updated current cursor node to point to the node to be updated.

[0134] In an optional implementation, when the update type is a delete data type and the type of the current cursor node is the first leaf node, the execution module 84 is further used to update the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node:

[0135] Update the right node pointer of the previous node of the current cursor node to point to the current cursor node, update the left node pointer of the current cursor node to point to the previous node of the current cursor node, update the current cursor node to be the previous node of the current cursor node, and update the right node pointer of the previous node of the node to be updated to point to the updated current cursor node.

[0136] In an optional implementation, when the update type is a delete data type and the type of the current cursor node is a half-node, the execution module 84 is further used to update the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node:

[0137] Update the left node pointer of the current cursor node to point to the previous node of the node to be updated, update the right node pointer of the previous node of the node to be updated to point to the current cursor node, and keep the pointing direction of the current cursor node pointer unchanged.

[0138] The data sorting device provided in this embodiment can execute the technical solution of the above method embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0139] Fig. 9 A schematic diagram of the structure of a data sorting device provided by an embodiment of the present invention. Fig. 9 As shown, the data sorting device provided in this embodiment includes: a memory 91 and at least one processor 92;

[0140] The memory 91 stores computer-executable instructions;

[0141] The at least one processor 92 executes the computer-executable instructions stored in the memory 91, so that the at least one processor 92 executes the data sorting method described in any of the above embodiments.

[0142] The memory 91 and the processor 92 may be connected via a bus 93 .

[0143] The specific implementation principle and effect of the data sorting device provided in this embodiment can be found in Figure 1-Figure 7 The relevant descriptions and effects corresponding to the illustrated embodiments are not elaborated in detail here.

[0144] An embodiment of the present invention further provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the method described in any of the above embodiments is implemented.

[0145] An embodiment of the present invention further provides a computer program product, including a computer program, which implements the method described in any of the above embodiments when executed by a processor.

[0146] Among them, the computer-readable storage medium may be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.

[0147] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed by the present invention. The description and examples are to be considered exemplary only, and the true scope and spirit of the present invention is indicated by the following claims.

[0148] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.

Claims

1. A data sorting method, characterized in that: include: Obtaining a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type; According to the data sorting update request, the current cursor node is determined from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the pointing of the current cursor node pointer, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layer, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node; Determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node; Performing updating and sorting operations on the original data according to the nodes to be updated and the data to be updated; If it is determined that the update type is to add a data type, then the to-be-updated node corresponding to the to-be-updated data is determined to be a to-be-added child node of the current cursor node; If it is determined that the update type is a deletion data type, determining that the node to be updated corresponding to the data to be updated is the tail node, and determining the node to be deleted corresponding to the data to be updated; The circular bidirectional linked list includes leaf nodes and cursor nodes of non-cursor nodes in the binary heap, and current pointing relationships corresponding to leaf nodes and cursor nodes of non-cursor nodes in the binary heap; After the updating operation is performed on the original data according to the node to be updated and the data to be updated, the method further includes: updating the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node; The nodes of the binary heap are arranged from left to right and from top to bottom to form a node sequence; The current pointing relationship corresponding to the leaf nodes of the non-cursor nodes and the cursor nodes in the binary heap specifically includes: The left node pointer of the leaf node that is not a cursor node and a tail node points to the previous node of the leaf node, the right node pointer of the leaf node points to the next node of the leaf node, the left node pointer of the cursor node points to the tail node, the right node pointer of the cursor node points to the next node of the cursor node, the left node pointer of the tail node points to the previous node of the tail node, and the right node pointer of the tail node points to the cursor node.

2. The method according to claim 1, characterized in that: If it is determined that the node to be updated is a child node to be added by the cursor node, then the updating and sorting operations on the original data according to the node to be updated and the data to be updated include: Add a child node to the cursor node as a node to be updated, and add the data to be updated to the node to be updated to complete the update operation on the original data; According to the data to be updated in the node to be updated and the data in the parent node corresponding to the node to be updated, determine whether the node to be updated and the parent node corresponding to the node to be updated need to be exchanged. If so, exchange the parent node corresponding to the node to be updated and the node to be updated to complete the sorting operation of the original data.

3. The method according to claim 1, characterized in that If it is determined that the node to be updated is the tail node, then the updating and sorting operations on the original data according to the node to be updated and the data to be updated include: Delete the tail node to complete the update operation on the original data; The tail node is used to replace the node to be deleted as a new node; Based on the data in the new node and the data in the child node corresponding to the node to be deleted, determine whether the new node and the child node corresponding to the node to be deleted need to be exchanged. If so, exchange the new node and the child node corresponding to the node to be deleted to complete the sorting operation of the original data.

4. The method according to claim 1, characterized in that: If the update type is to add a data type, and the type of the current cursor node is the first leaf node, then the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node, including: Update the left node pointer of the node to be updated to point to the previous node of the node to be updated, update the right node pointer of the node to be updated to point to the current cursor node, update the right node pointer of the previous node of the node to be updated to point to the node to be updated, update the left node pointer of the current cursor node to point to the node to be updated, and keep the pointing direction of the current cursor node pointer unchanged.

5. The method according to claim 1, characterized in that If the update type is to add a data type and the type of the current cursor node is a half node, the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node, including: Update the left node pointer of the node to be updated to point to the previous node of the node to be updated, update the right node pointer of the node to be updated to point to the next node of the current cursor node, update the right node pointer of the previous node of the node to be updated to point to the node to be updated, update the right node pointer of the current cursor node to point to the node to be updated, update the current cursor node to be the next node of the current cursor node, and update the left node pointer of the updated current cursor node to point to the node to be updated.

6. The method according to claim 1, characterized in that If the update type is a delete data type and the type of the current cursor node is the first leaf node, then the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node, including: Update the right node pointer of the previous node of the current cursor node to point to the current cursor node, update the left node pointer of the current cursor node to point to the previous node of the current cursor node, update the current cursor node to be the previous node of the current cursor node, and update the right node pointer of the previous node of the node to be updated to point to the updated current cursor node.

7. The method according to claim 1, characterized in that If the update type is a delete data type and the type of the current cursor node is a half-node, the current cursor node and the current pointing relationship are updated according to the update type and the type of the current cursor node, including: Update the left node pointer of the current cursor node to point to the previous node of the node to be updated, update the right node pointer of the previous node of the node to be updated to point to the current cursor node, and keep the pointing direction of the current cursor node pointer unchanged.

8. A data sorting device, characterized in that: The device comprises: An acquisition module, used for acquiring a data sorting update request, wherein the data sorting update request includes: data to be updated and an update type; A first determination module is used to determine the current cursor node according to the direction of the current cursor node pointer from the circular bidirectional linked list corresponding to the binary heap storing the original data according to the data sorting update request, the current cursor node is the first leaf node or half node in the binary heap, the binary heap is a binary heap with the root node at the top layer and the leaf nodes at the bottom layer, the first leaf node is the leftmost leaf node at the top layer, and the half node is a node with only a left child node; A second determination module, configured to determine the node to be updated corresponding to the data to be updated in the binary heap according to the update type and the current cursor node; An execution module, used for updating and sorting the original data according to the nodes to be updated and the data to be updated; The second determination module is specifically used to determine that the node to be updated corresponding to the data to be updated is the child node to be added of the current cursor node if the update type is determined to be an add data type; if the update type is determined to be a delete data type, determine that the node to be updated corresponding to the data to be updated is the tail node, and determine the node to be deleted corresponding to the data to be updated; The circular bidirectional linked list includes leaf nodes and cursor nodes of non-cursor nodes in the binary heap, and current pointing relationships corresponding to leaf nodes and cursor nodes of non-cursor nodes in the binary heap; The execution module is also used to update the current cursor node and the current pointing relationship according to the update type and the type of the current cursor node; The nodes of the binary heap are arranged from left to right and from top to bottom to form a node order; the current pointing relationship corresponding to the leaf nodes and cursor nodes of the non-cursor nodes in the binary heap specifically includes: the left node pointer of the leaf node of the non-cursor node and the tail node points to the previous node of the leaf node, the right node pointer of the leaf node points to the next node of the leaf node, the left node pointer of the cursor node points to the tail node, the right node pointer of the cursor node points to the next node of the cursor node, the left node pointer of the tail node points to the previous node of the tail node, and the right node pointer of the tail node points to the cursor node.

9. A data sorting device, characterized in that: include: memory and at least one processor; The at least one processor comprises: The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the data sorting method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 7 is implemented.

11. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.