Data queue management method and system based on balanced binary tree
By using a balanced binary tree structure in data queue management, sending queues according to priority configuration and maintaining balance, the problem of insubstantiation of large data volume and different priority in the prior art is solved, and efficient data processing and resource utilization are achieved.
Patent Information
- Application Number
- CN202411287020.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-13
AI Technical Summary
The existing data message sending queue management algorithm has low insertion time and efficiency under the conditions of large data volume and different priority, resulting in reduced transmission queue processing efficiency and frequent traversal of the queue, resulting in waste of resources.
Adopt the data queue management method based on the balanced binary tree. By establishing a data node structure, the queue is sent according to the priority configuration. Data with high priority is sent before data with low priority, and data nodes are inserted or deleted in the balanced binary tree to maintain balance The balanced state of the binary tree.
It improves the transmission efficiency of data queues, prevents the accumulation of the same data link list, reduces the time cost of insertion and deletion operations, and improves the efficiency of data processing.
Smart Images

Figure CN119316374A_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 growth of wireless communication data volume and the diversified demands for data processing, the data message sending queue management algorithm needs to be changed urgently. 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 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, nowadays, the amount of data messages is increasing, and with the addition of message priority and other requirements, the insertion time and efficiency are becoming lower and lower.
[0003] At present, when there is a lot of data to be sent, the sending queue stores the queued data in the form of a linked list. When the time to send comes, the message at the head of the queue is dequeued. When the message to be sent later needs to be queued, it is necessary to traverse the priority of each data from the head of the queue until the data with a lower priority than the inserted data is found. If the priority of all data in the queue is greater than the priority of the data to be inserted, then the data to be inserted is added to the end of the queue. The disadvantage caused by this is that if a large amount of data needs to be sent in a short time at the sending end, and the priorities are different, because the sending queue is stored in the form of a linked list, the sending queue will become very long. Each time a piece of data is inserted into this queue, the queue must be traversed again from the beginning. The result is that the time of each insertion is uncertain, and the worst result is even to traverse the entire queue. This is very inefficient for the processing of the sending queue, which will take a lot of time and resources. In addition, the sending frequency of different data is different. The data sending 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 embodiment of the present application provides 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 the same data linked list in the balanced binary tree, and improve the sending efficiency of the balanced binary tree queue.
[0005] The present application embodiment 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 the 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: different sending priorities are configured on the communication node, so that data with a high priority is sent before data with a low priority, and the priority of data being redundantly sent is the highest and cannot be interrupted, and the leaf node with the highest priority is determined according to the balanced binary tree, and the sending is executed, and the corresponding data node is deleted;
[0009] When the communication node receives data, the data node is inserted into the balanced binary tree. When the priority of the data to be inserted is greater than the leaf node 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 relevant 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 the node is sending redundantly according to the 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] The frequency factor is used to represent the number of data nodes when data nodes of the same priority 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 nodes of the same order of magnitude;
[0020] The left leaf node pointer is used to store the address of the left leaf node and point 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, within a given time length, multiple statistics are performed according to the priorities of various data types and the divided time lengths, 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, wherein the data type with the highest probability counted multiple times has the highest priority, 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 front 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, rotating the binary balanced tree left or right 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, depending on the absolute value of the balance factor of the balanced binary tree not exceeding 1.
[0032] The embodiment of the present application also 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 data queue management method based on a balanced binary tree are implemented as described above.
[0033] The method of the embodiment of the present application can adjust the priorities 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 of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0036] Figure 1 The overall process diagram of the data queue management method of the balanced binary tree according to the embodiment of the present application is shown. DETAILED DESCRIPTION
[0037] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the 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. On the contrary, 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 present application embodiment provides a data queue management method based on a balanced binary tree. 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 a 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 Redundance Flag Data content Balance Factor FrequencyFactor 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 data priority 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 factor 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 when data nodes of the same priority 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 outward, a corresponding sending queue is established based on a balanced binary tree, wherein the sending queue satisfies: different sending priorities are configured on the communication node, so that data with high priority is sent before data with low priority, and the priority of data being sent redundantly is the highest and cannot be interrupted, that is, its priority is the highest, even if the priority of data inserted into the queue later is higher than the data being sent redundantly, it must be sent after the first data that needs to be sent redundantly. Thus, the leaf node with the highest priority is determined according to the balanced binary tree, the sending is executed, and the corresponding data node is deleted.
[0053] When the communication node receives data, the data node is inserted 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. The original data is stored and deleted by using a balanced binary tree, which not only utilizes the balance characteristics of the balanced binary tree to improve the efficiency of traversing each data node, but also reduces the deletion cost because the node with the highest priority is located at the leaf end of the balanced binary tree.
[0056] In some embodiments, when the communication node sends data externally, the method further includes:
[0057] In the sending queue, within a given time length, multiple statistics are performed according to the priorities of various data types and the divided time lengths, 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, wherein the data type with the highest probability counted multiple times has the highest priority, and the original priority is compared for the same probability.
[0058] In some specific examples, for example, when sending data, the priorities of the eight data types at 20 seconds are sorted by the probability of the highest data type each time in the 5 statistics every 4 seconds, and the priorities of the eight data types abcdefgh are reallocated. The priority of the data with the highest probability in the 5 statistics is adjusted to the highest priority. The original levels of the same probabilities are compared, and the higher the original level, the higher the priority. When the probability of a data type is 0, if another data type priority is inserted before this type, the priority of this type will decrease once.
[0059] In some embodiments, when a communication node receives data, it also includes: traversing the balanced binary tree 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 front 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, it also 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 balanced 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, according to the absolute value of the balance factor of the balanced binary tree not exceeding 1. The frequency factor number of each data type is counted every 4 seconds, and the probability of the maximum frequency factor number of each data type is counted 5 times every 20 seconds.
[0066] The method of the embodiment of the present application can adjust the priorities of different data types according to different types of data, prevent the accumulation of linked lists of the same data in a balanced binary tree, and improve the transmission efficiency of a balanced binary tree queue. The method of the present application utilizes the "balanced" characteristic of a balanced binary tree to make the time cost of searching nearly balanced, the binary tree will not degenerate into a linked list form, and the high priority of the balanced binary tree is located at the leaf node of the balanced binary tree. When a data node needs to be deleted, the leaf node of the binary tree can be directly deleted, and the cost required is also the lowest.
[0067] The embodiment of the present application also 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 data queue management method based on a balanced binary tree are implemented as described above.
[0068] It should be noted that in the various embodiments of the present application, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other identical elements in the process, method, article or device including 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 a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an 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, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a 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 the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present 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 the 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: different sending priorities are configured on the communication node, so that data with a high priority is sent before data with a low priority, and the priority of data being redundantly sent is the highest and cannot be interrupted, and the leaf node with the highest priority is determined according to the balanced binary tree, and the sending is executed, and the corresponding data node is deleted; When the communication node receives data, the data node is inserted into the balanced binary tree. When the priority of the data to be inserted is greater than the leaf node 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 binary balanced tree is rotated left or right according to the balance factor of the balanced binary tree to balance the balanced binary tree.
2. The data queue management method based on a balanced binary tree according to claim 1, characterized in that: The data node structure for establishing a balanced binary tree includes: A relevant 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 the node is sending redundantly according to the 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; The frequency factor is used to represent the number of data nodes when data nodes of the same priority 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 nodes of the same order of magnitude; The left leaf node pointer is used to store the address of the left leaf node and point 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.
3. The data queue management method based on a balanced binary tree according to claim 2, characterized in that: When the communication node sends data outward, it also includes: In the sending queue, within a given time length, multiple statistics are performed according to the priorities of various data types and the divided time lengths, 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, wherein the data type with the highest probability counted multiple times has the highest priority, and the original priority is compared for the same probability.
4. The data queue management method based on a balanced binary tree according to claim 2, 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.
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 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 front 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.
6. The data queue management method based on a balanced binary tree according to claim 5, 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.
7. The data queue management method based on a balanced binary tree according to claim 6, characterized in that: 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 make the balanced binary tree balanced, including: After the insertion or deletion operation is completed, the binary balanced tree is rotated left or right to balance the binary balanced tree, depending on the absolute value of the balance factor of the balanced binary tree not exceeding 1.
8. A data queue management system based on a balanced binary tree, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data queue management method based on a balanced binary tree are implemented as described in any one of claims 1 to 7.
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
Message queue implementation method and system, electronic equipment and readable storage medium
CN115934384A
Event triggering processing method based on voice recognition
CN118486305A
Bounded sub-optimal problem solving
US20090144310A1
Cited By
Data processing method and device, data processing equipment and storage medium
CN121277939A