A data queue management method and system based on balanced binary tree
By optimizing data insertion and deletion operations through a data queue management method based on a balanced binary tree, the problem of low queue management efficiency in existing technologies is solved, and efficient data transmission and resource utilization are achieved.
Patent Information
- Application Number
- CN202411287020.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2044-09-13
AI Technical Summary
Existing data message sending queue management algorithms suffer from inconsistent insertion times and low efficiency when dealing with large amounts of data and different priorities. Furthermore, the sending queue requires frequent traversal, leading to resource waste and reduced efficiency.
A data queue management method based on a balanced binary tree is adopted. By establishing a balanced binary tree structure, data insertion and deletion operations are optimized according to data priority and redundancy sending status. This ensures that high-priority data is sent first, and the balance of the tree is maintained by a balance factor, thereby improving the efficiency of insertion and deletion.
It effectively prevents the accumulation of identical data linked lists in a balanced binary tree, improves the sending efficiency of the data queue, reduces the cost of searching and deleting, and ensures the high efficiency of data sending and resource utilization.
Smart Images

Figure CN119316374B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a data queue management method and system based on a balanced binary tree. Background Art
[0002] With the growing demand for wireless communication data and the diverse demands for data processing, the data message sending queue management algorithm needs urgent changes. The original data message sending queue management uses a linear table format to store the message sending sequence. For messages of different priorities, the linear comparison insertion method is still used when inserting them into the queue. Only when the inserted data has a higher priority or a smaller amount of data, the original linear traversal and insertion speed will be fast. However, with the increasing amount of data messages and the addition of message priority and other requirements, the insertion time and efficiency are becoming increasingly lower.
[0003] Currently, when there is a large amount of data to be sent, the send queue stores the queued data in a linked list format. When the time comes to send, the message at the head of the queue is dequeued. When the subsequent messages need to be queued, they must start from the head of the queue and traverse the priority of each data until a data with a lower priority than the inserted data is found. If the priority of all the data in the queue is higher than the priority of the data to be inserted, the inserted data is added to the end of the queue. The disadvantage of this is that if the sender needs to send a large amount of data in a short period of time with different priorities, the send queue will become very long because it is stored in the form of a linked list. The queue must be traversed from the beginning every time a data item is inserted. As a result, the time for each insertion is uncertain, and in the worst case, the entire queue must be traversed. This is very inefficient for the send queue processing and consumes a lot of time and resources. In addition, the sending frequency of different data varies, and the data send queue must be adjusted according to the actual sending situation, otherwise the sending efficiency of the data queue will be reduced. Summary of the Invention
[0004] The embodiments of the present application provide a data queue management method and system based on a balanced binary tree, which is used to adjust the priority of different data types according to different types of data, prevent the accumulation of identical data linked lists in the balanced binary tree, and improve the sending efficiency of the balanced binary tree queue.
[0005] The present invention provides a data queue management method based on a balanced binary tree, including:
[0006] Establish the data node structure of a balanced binary tree;
[0007] According to task requirements, data is received or sent through the queue, where:
[0008] When a communication node sends data outward, a corresponding sending queue is established based on a balanced binary tree, wherein the sending queue satisfies the following requirements: different sending priorities are configured on the communication node, so that data with higher priority is sent before data with lower priority, and data being redundantly sent has the highest priority and cannot be interrupted; the leaf node with the highest priority is determined based on the balanced binary tree, the data is sent, and the corresponding data node is deleted;
[0009] When a communication node receives data, it inserts the data node into the balanced binary tree. If the priority of the data to be inserted is higher than the leaf node that needs to be sent redundantly, the data is inserted after the corresponding leaf node; otherwise, the data is inserted before the corresponding leaf node.
[0010] After the insertion or deletion operation is completed, the binary balanced tree is rotated left or right according to the balance factor of the balanced binary tree to balance the balanced binary tree.
[0011] Optionally, establishing a data node structure of a balanced binary tree includes:
[0012] A related structure attribute is set for any data node to implement the data structure function by using the structure attribute, wherein the structure attribute includes:
[0013] Data type, used to indicate the type of data;
[0014] Priority, used to indicate the priority of inserting data nodes into a balanced binary tree;
[0015] Redundant sending flag, which describes whether this node is sending redundantly based on its value;
[0016] Data content, used to store the specific content of the sent data;
[0017] The balance factor is used to represent the value of the left subtree depth minus the right subtree depth of a balanced binary tree;
[0018] Frequency factor, used to represent the number of data nodes with the same priority when they are stored in a linked list;
[0019] Next node pointer, used to point to the next node in the form of a linked list when there are the same order of magnitude;
[0020] The left leaf node pointer is used to store the address of the left leaf node and points to the left leaf node;
[0021] The right leaf node pointer is used to store the address of the right leaf node and points to the right leaf node.
[0022] Optionally, when the communication node sends data outward, the method further includes:
[0023] In the sending queue, for a given time length, multiple statistics are performed according to the priority of various data types and the divided time length, and the probability of occurrence of the data types counted each time is sorted to reallocate the priority of the data in the sending queue, among which the priority of the data type with the highest probability counted multiple times is adjusted to the highest, and the original priority is compared for the same probability.
[0024] Optionally, when the communication node receives data, the method further includes:
[0025] The balanced binary tree is traversed from the vertex of the balanced binary tree, and data is inserted into the balanced binary tree based on the fact that the priority of the leaf node of the balanced binary tree is greater than that of the parent node and the priority of the right leaf node is greater than that of the left leaf node.
[0026] Optionally, when the communication node receives data, the method further includes:
[0027] When inserting data, if there is a data node with the same priority as the inserted data in the balanced binary tree, the inserted data will be linked to the original data node in the format of a linked list, and the frequency factor of the first data node in the linked list will be increased by 1 according to the number of links. If data is sent, the data node in the linked list will be deleted and the frequency factor will be reduced by 1.
[0028] Optionally, when the communication node sends data, the method further includes:
[0029] When sending data, the leaf node with the highest priority is determined according to the balanced binary tree, and the corresponding data node is deleted.
[0030] Optionally, after the insertion or deletion operation is completed, performing a left rotation or a right rotation on the balanced binary tree according to the balance factor of the balanced binary tree to balance the balanced binary tree includes:
[0031] After the insertion or deletion operation is completed, the binary balanced tree is rotated left or right to balance the binary balanced tree according to the absolute value of the balance factor of the balanced binary tree not exceeding 1.
[0032] An embodiment of the present application further proposes a data queue management system based on a balanced binary tree, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by the processor, the steps of the aforementioned data queue management method based on a balanced binary tree are implemented.
[0033] The method of the embodiment of the present application can adjust the priority of different data types according to different types of data, prevent the accumulation of the same data linked list in the balanced binary tree, and improve the sending efficiency of the balanced binary tree queue.
[0034] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present application. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0036] Figure 1 The figure shows the overall process of the data queue management method of the balanced binary tree according to the embodiment of the present application. DETAILED DESCRIPTION
[0037] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0038] The embodiment of the present application provides a data queue management method based on a balanced binary tree, such as Figure 1 As shown, the following steps are included:
[0039] In step S101, a data node structure of a balanced binary tree is established. In some embodiments, establishing the data node structure of a balanced binary tree includes:
[0040] A related structure attribute is set for any data node to implement the data structure function by using the structure attribute, wherein the structure attribute is shown in Table 1:
[0041] Data Type Priority Redundence Flag Data content Balance Factor Frequency Factor Next node pointer (NodeNext) Left leaf node pointer (NodeLeft) Right leaf node pointer (NodeRight)
[0042] Among them, data type (DataType): represents the type of data. In this example, it is divided into 8 types: a, b, c, d, e, f, g, h
[0043] Priority: represents the priority of inserting data nodes into a balanced binary tree. In this example, the data priority is (0 to 7), where the priority of data increases from 0 to 7.
[0044] Redundancy Flag: When the Redundancy Flag is 1, it means that the node is performing redundant transmission. Regardless of the value of the Priority, the priority of the node in the balanced binary tree is the highest.
[0045] Data content (Data): stores the specific content of the sent data.
[0046] Balance Factor: represents the value of the left subtree depth minus the right subtree depth of a balanced binary tree. The balance factors of all nodes in a balanced binary tree can only be -1, 0, or 1.
[0047] The frequency factor represents the number of data nodes with the same priority when the data nodes are stored in a linked list.
[0048] The Next node pointer (NodeNext) points to the next node in the form of a linked list when they have the same order of magnitude.
[0049] Left leaf node pointer (NodeLeft): The pointer of the left leaf, which stores the address of the left leaf node and points to the left leaf node.
[0050] Right leaf node pointer (NodeRight): The pointer of the right leaf, which stores the address of the right leaf node and points to the right leaf node.
[0051] In step S102, data is received or sent through a queue according to task requirements, wherein:
[0052] When a communication node sends data, a corresponding send queue is established based on a balanced binary tree. The send queue satisfies the following requirements: Different send priorities are configured at the communication node, ensuring that high-priority data is sent before lower-priority data, and that data being redundantly sent has the highest priority and cannot be interrupted. In other words, even if data inserted later into the queue has a higher priority than the redundantly sent data, it is sent after the first data requiring redundant transmission. The balanced binary tree then determines the leaf node with the highest priority, executes the transmission, and deletes the corresponding data node.
[0053] When a communication node receives data, it inserts the data node into the balanced binary tree. When the priority of the data to be inserted is greater than the leaf node that needs to be sent redundantly, the data is inserted after the corresponding leaf node; otherwise, the data is inserted before the corresponding leaf node.
[0054] In step S103, after the insertion or deletion operation is completed, the binary balanced tree is rotated left or right according to the balance factor of the balanced binary tree to balance the balanced binary tree.
[0055] The queue of the data queue management method of the embodiment of the present application is a process of inserting and deleting an ordered data structure. By using a balanced binary tree to store and delete the original data, the balance characteristics of the balanced binary tree are utilized to improve the efficiency of traversing each data node. In addition, since the node with the highest priority is located at the leaf end of the balanced binary tree, the deletion cost is reduced.
[0056] In some embodiments, when the communication node sends data outward, the method further includes:
[0057] In the sending queue, for a given time length, multiple statistics are performed according to the priority of various data types and the divided time length, and the probability of occurrence of the data types counted each time is sorted to reallocate the priority of the data in the sending queue, among which the priority of the data type with the highest probability counted multiple times is adjusted to the highest, and the original priority is compared for the same probability.
[0058] In some specific examples, such as when sending data, the priorities of the eight data types at 20 seconds are sorted by the probability of the data type with the highest probability each time, calculated five times every four seconds. The priorities of the eight data types abcdefgh are then reallocated, with the highest probability in the five statistics being given the highest priority. Data types with the same probability are compared with their original rankings, with the higher priority given the higher priority. If the probability of a data type occurring is 0, if another data type precedes it, the priority of that data type is reduced one by one.
[0059] In some embodiments, when a communication node receives data, it also includes: traversing the balanced binary tree starting from the vertex of the balanced binary tree, and inserting data into the balanced binary tree based on the fact that the priority of the leaf node of the balanced binary tree is greater than that of the parent node and the priority of the right leaf node is greater than that of the left leaf node.
[0060] In some embodiments, when the communication node receives data, the method further includes:
[0061] When inserting data, if there is a data node with the same priority as the inserted data in the balanced binary tree, the inserted data will be linked to the original data node in the format of a linked list, that is, the Next node pointer of the previous node points to the inserted data node, and the frequency factor of the first data node in the linked list is increased by 1 according to the number of links. If data is sent, the data node in the linked list is deleted and the frequency factor is reduced by 1.
[0062] If data is sent, find the leaf node with the highest priority according to the properties of the balanced binary tree and delete the corresponding data node.
[0063] In some embodiments, when a communication node sends data, the method further includes: when sending data, determining a leaf node with the highest priority according to a balanced binary tree, and deleting the corresponding data node.
[0064] In some embodiments, after the insertion or deletion operation is completed, rotating the binary tree left or right according to the balance factor of the balanced binary tree to balance the balanced binary tree includes:
[0065] After the insertion or deletion operation is completed, the binary tree is rotated left or right to balance the binary tree, provided that the absolute value of the balance factor does not exceed 1. The frequency factor of each data type is counted every 4 seconds, and the probability of the maximum frequency factor of each data type is counted 5 times every 20 seconds.
[0066] The method of the embodiment of the present application can adjust the priority of different data types according to different types of data, prevent the accumulation of the same data linked list in the balanced binary tree, and improve the sending efficiency of the balanced binary tree queue. The method of the present application utilizes the "balanced" characteristic of the balanced binary tree to make the time cost of the search almost balanced, the binary tree will not degenerate into the form of a linked list, and the high priority of the balanced binary tree is located in the leaf node of the balanced binary tree. When it is necessary to delete a data node, the leaf node of the binary tree can be directly deleted, and the cost required is also the lowest.
[0067] An embodiment of the present application further proposes a data queue management system based on a balanced binary tree, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by the processor, the steps of the aforementioned data queue management method based on a balanced binary tree are implemented.
[0068] It should be noted that, in the various embodiments of the present application, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0069] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0070] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0071] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are protected by this application.
Claims
1. A data queue management method based on a balanced binary tree, characterized in that: include: Establish the data node structure of a balanced binary tree; According to task requirements, data is received or sent through the queue, where: When a communication node sends data outward, a corresponding sending queue is established based on a balanced binary tree, wherein the sending queue satisfies the following requirements: different sending priorities are configured on the communication node, so that data with higher priority is sent before data with lower priority, and data being redundantly sent has the highest priority and cannot be interrupted; the leaf node with the highest priority is determined based on the balanced binary tree, the data is sent, and the corresponding data node is deleted; When a communication node receives data, it inserts the data node into the balanced binary tree. If the priority of the data to be inserted is higher than the leaf node that needs to be sent redundantly, the data is inserted after the corresponding leaf node; otherwise, the data is inserted before the corresponding leaf node. After the insertion or deletion operation is completed, the balanced binary tree is rotated left or right according to the balance factor of the balanced binary tree to make it balanced; The data node structure for establishing a balanced binary tree includes: A related structure attribute is set for any data node to implement the data structure function by using the structure attribute, wherein the structure attribute includes: Data type, used to indicate the type of data; Priority, used to indicate the priority of inserting data nodes into a balanced binary tree; Redundant sending flag, which describes whether this node is sending redundantly based on its value; Data content, used to store the specific content of the sent data; The balance factor is used to represent the value of the left subtree depth minus the right subtree depth of a balanced binary tree; Frequency factor, used to represent the number of data nodes with the same priority when they are stored in a linked list; Next node pointer, used to point to the next node in the form of a linked list when there are the same order of magnitude; The left leaf node pointer is used to store the address of the left leaf node and points to the left leaf node; The right leaf node pointer is used to store the address of the right leaf node and points to the right leaf node.
2. The data queue management method based on a balanced binary tree according to claim 1, characterized in that: When a communication node sends data outward, it also includes: In the sending queue, for a given time length, multiple statistics are performed according to the priority of various data types and the divided time length, and the probability of occurrence of the data types counted each time is sorted to reallocate the priority of the data in the sending queue, among which the priority of the data type with the highest probability counted multiple times is adjusted to the highest, and the original priority is compared for the same probability.
3. The data queue management method based on a balanced binary tree according to claim 1, characterized in that: In the case where the communication node receives data, it also includes: The balanced binary tree is traversed from the vertex of the balanced binary tree, and data is inserted into the balanced binary tree based on the fact that the priority of the leaf node of the balanced binary tree is greater than that of the parent node and the priority of the right leaf node is greater than that of the left leaf node.
4. The data queue management method based on a balanced binary tree according to claim 3, characterized in that: In the case where the communication node receives data, it also includes: When inserting data, if there is a data node with the same priority as the inserted data in the balanced binary tree, the inserted data will be linked to the original data node in the format of a linked list, and the frequency factor of the first data node in the linked list will be increased by 1 according to the number of links. If data is sent, the data node in the linked list will be deleted and the frequency factor will be reduced by 1.
5. The data queue management method based on a balanced binary tree according to claim 4, characterized in that: In the case where the communication node sends data, it also includes: When sending data, the leaf node with the highest priority is determined according to the balanced binary tree, and the corresponding data node is deleted.
6. The data queue management method based on a balanced binary tree according to claim 5, characterized in that: After the insertion or deletion operation is completed, the balanced binary tree is rotated left or right according to the balance factor of the balanced binary tree to make the balanced binary tree balanced. After the insertion or deletion operation is completed, the balanced binary tree is rotated left or right to balance the balanced binary tree according to the absolute value of the balance factor of the balanced binary tree not exceeding 1.
7. A data queue management system based on a balanced binary tree, characterized in that: The method comprises a processor and a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the method implements the steps of the data queue management method based on a balanced binary tree according to any one of claims 1 to 6.
Citation Information
Patent Citations
Queue scheduling method and device
CN104144134A
A method and device for dynamically adding a database by a strict balanced binary tree
CN109815238A