A data access method for priority queue

By combining the data structure of the jump list and multiple single linked lists, the efficiency problem of priority queue in the number of data when the number of data is far greater than the priority, and achieves efficient priority element operation and priority scope statistics.

CN114489485BActive Publication Date: 2025-01-24SHANGHAI SAIKE MOBILITY TECH SERVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111612991.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2025-01-24
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

When the data number of existing priority queues is much larger than priority, their dequeue efficiency and efficiency by priority are poor, and it is difficult to effectively count the priority range.

Method used

Using a combined data structure of jump lists and multiple single-linked lists, efficient insertion, search, and deletion of priority elements can be achieved by constructing linked lists and single-linked lists of multi-layer sparse subsequences.

Benefits of technology

The efficiency of the use scenario of the priority queue in the use of priority minority, which is significantly improved, improved the performance of the team and operating in accordance with the priority, and can effectively count the priority scope.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114489485B_ABST
    Figure CN114489485B_ABST
Patent Text Reader

Abstract

The present invention relates to data access related fields of data structures, and specifically to a data access method for a priority queue. The present invention provides a data access method for a priority queue to solve the problem that when the number of data in the priority queue is much larger than the priority, the dequeue efficiency and priority efficiency performance of the priority queue are poor. This structure can also count the priority range, and can significantly improve the efficiency for the usage scenario with a small number of priorities and a large amount of data. The advantage of this algorithm is that a new data structure is proposed, which combines the advantages of a skip list and a plurality of singly linked lists to provide an efficient data access method for a priority queue, thereby improving the execution efficiency and providing practical functions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field related to data access of data structures, and in particular to a data access method for a priority queue. Background Art

[0002] In the process of using existing computers, computer programs access corresponding data by constructing data structures. Different data structures have different functions. A queue is a first-in-first-out data structure. Elements are added to the end of the queue and deleted from the head of the queue. A priority queue is a queue with element priority. When adding elements, the elements are placed in the appropriate position according to the priority. When deleting elements, they are deleted from the head of the queue.

[0003] Priority queues are usually implemented using a max-heap or a min-heap. This data structure faces heap adjustments when dequeuing, and to count the number of elements with the same priority, the entire data set needs to be traversed. The heap data structure is not conducive to scenarios where the number of elements is much larger than the number of priorities. In some applications that process tasks (many tasks) by priority (few priorities), the performance of deleting and counting the number of statistics will be affected. Therefore, a data access method for a priority queue is provided. Summary of the invention

[0004] The object of the present invention is to provide a data access method of a priority queue to solve the problems raised in the above background technology.

[0005] To achieve the above object, the present invention provides the following technical solution: a data access method of a priority queue, comprising the following steps:

[0006] Step S1, constructing a skip list, wherein the skip list is composed of a linked list of multiple layers of sparse subsequences, and each layer of the linked list of the sparse subsequences is represented by a plurality of arrow boxes, and a number box representing the priority is set at the bottom layer of the skip list;

[0007] Step S2, inserting the priority element e into the linked list of the sparse subsequence in step S1, wherein the front and back index points need to be confirmed, specifically, finding a node that is just larger than the element e, and whose backward nodes are all larger than the element e, and a node that is just smaller than the element, and whose forward nodes are all smaller than the element e, and directly inserting the element e into the front and back index points;

[0008] Step S3, when it is necessary to find the priority element e, the algorithm first searches in the linked list level of the sparsest sparse subsequence until the element to be found is between two adjacent elements in this level. At this time, the algorithm will jump to the next level and repeat the previous search until the priority element e to be found is found;

[0009] Step S4: When the priority element e needs to be deleted, the priority element e appears in the index. First, delete the node in the original linked list, and then delete the node in the index.

[0010] Preferably, the elements in each layer of the linked list of the multi-layer sparse subsequence in step S1 are a subset of the elements in the linked list of the previous layer.

[0011] Preferably, the linked list of the sparse subsequence of each layer in step S1 adopts a bidirectional linked list to store the head node and the tail node. The head node and the tail node are convenient for obtaining the data range of the jump list. The head node is the smallest node of the layer, and the tail node is the largest node of the layer.

[0012] Preferably, in step S2, directly inserting element e into the front and rear index points will cause too many nodes between the two index points. At this time, the jump list height height is set, and a random integer α between [1, height] is randomly generated by a random function to maintain the size balance between the index and the original linked list. The random number determines the height of the newly added element index. For each layer β, a corresponding new element index is established in each layer, 1≤β≤α. If the random number α=height, a blank layer is added to the top layer of the jump list. This layer initially has no index, and the jump list height is increased by 1. At this time, the index and reach a balance.

[0013] Preferably, in step S2, a single linked list and a number count are associated with the priority element e, which are used to record the number of data in the single linked list.

[0014] Preferably, the single linked list has the following characteristics:

[0015] a. A singly linked list contains a head node and a tail node.

[0016] b. Method of enqueuing priority element e data: find the corresponding singly linked list according to the priority, then add an element data to the end of the singly linked list, adjust the tail pointer, and add 1 to count;

[0017] c. Method to remove priority element e from the queue: find the single linked list corresponding to the head of the jump list, remove the first data element from the single linked list, adjust the head pointer of the single linked list, and reduce count by 1; if this data element is the last element of this linked list, delete the linked list and the corresponding priority of the adjusted list

[0018] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention provides a data access method for a priority queue to solve the problem that the priority queue has poor dequeue efficiency and priority efficiency when the number of data is much larger than the priority. This structure can also count the priority range, which can significantly improve the efficiency for usage scenarios with a small number of priorities and a large amount of data.

[0019] The advantage of this algorithm is that it proposes a new data structure, combining the advantages of skip lists and multiple singly linked lists, providing an efficient priority queue data access method, improving execution efficiency and providing practical functions. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A schematic diagram of the skip list structure of the present invention;

[0021] Figure 2 It is a schematic diagram of the jump list and multiple single linked lists structure of the present invention. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.

[0023] See also Figure 1-2 The present invention provides a technical solution: a data access method for a priority queue, comprising the following steps:

[0024] Step S1, constructing a skip list, wherein the skip list is composed of a linked list of multiple layers of sparse subsequences, and each layer of the linked list of the sparse subsequences is represented by a plurality of arrow boxes, and a number box representing the priority is set at the bottom layer of the skip list;

[0025] Step S2, inserting the priority element e into the linked list of the sparse subsequence in step S1, wherein the front and back index points need to be confirmed, specifically, finding a node that is just larger than the element e, and whose backward nodes are all larger than the element e, and a node that is just smaller than the element, and whose forward nodes are all smaller than the element e, and directly inserting the element e into the front and back index points;

[0026] Step S3, when it is necessary to find the priority element e, the algorithm first searches in the linked list level of the sparsest sparse subsequence until the element to be found is between two adjacent elements in this level. At this time, the algorithm will jump to the next level and repeat the previous search until the priority element e to be found is found;

[0027] Step S4: When the priority element e needs to be deleted, the priority element e appears in the index. First, delete the node in the original linked list, and then delete the node in the index.

[0028] Furthermore, the elements in each layer of the linked list of the multi-layer sparse subsequence in step S1 are subsets of the elements in the linked list of the previous layer.

[0029] Furthermore, in step S1, the linked list of the sparse subsequence of each layer adopts a bidirectional linked list to store the head node and the tail node. The head node and the tail node are convenient for obtaining the data range of the skip list. The head node is the smallest node of the layer, and the tail node is the largest node of the layer.

[0030] Furthermore, in step S2, when element e is directly inserted into the front and rear index points, there will be too many nodes between the two index points. At this time, the jump list height height is set, and a random integer α between [1, height] is randomly generated by a random function to maintain the size balance of the index and the original linked list. The random number determines the height of the newly added element index. For each layer β, a corresponding new element index is established in each layer, 1≤β≤α. If the random number α=height, a blank layer is added to the top layer of the jump list. This layer initially has no index, and the jump list height is increased by 1. At this time, the index and reach a balance.

[0031] Furthermore, in step S2, a single linked list and a number count are associated with the priority element e to record the number of data in the single linked list.

[0032] Furthermore, the singly linked list has the following characteristics:

[0033] a. A singly linked list contains a head node and a tail node.

[0034] b. Method of enqueuing priority element e data: find the corresponding singly linked list according to the priority, then add an element data to the end of the singly linked list, adjust the tail pointer, and add 1 to count;

[0035] c. Method to dequeue data of priority element e: find the singly linked list corresponding to the head of the jump list, dequeue the first data element of the single linked list, adjust the head pointer of the single linked list, and reduce count by 1; if this data element is the last element of this linked list, delete the linked list and the corresponding priority of the adjusted list.

[0036] The present invention provides a data access method for a priority queue to solve the problem that the priority queue has poor dequeue efficiency and priority efficiency when the number of data is much larger than the priority. This structure can also count the priority range, which can significantly improve the efficiency for usage scenarios with a small number of priorities and a large amount of data.

[0037] The advantage of this algorithm is that it proposes a new data structure, combining the advantages of skip lists and multiple singly linked lists, providing an efficient priority queue data access method, improving execution efficiency and providing practical functions.

[0038] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A data access method for a priority queue, characterized in that , including the following steps: Step S1, constructing a skip list, wherein the skip list is composed of a linked list of multiple layers of sparse subsequences, and each layer of the linked list of the sparse subsequences is represented by a plurality of arrow boxes, and a number box representing the priority is set at the bottom layer of the skip list; Step S2, inserting the priority element e into the linked list of the sparse subsequence in step S1, wherein the front and back index points need to be confirmed, specifically, finding a node that is just larger than the element e, and whose backward nodes are all larger than the element e, and a node that is just smaller than the element, and whose forward nodes are all smaller than the element e, and directly inserting the element e into the front and back index points; Step S3, when it is necessary to find the priority element e, the algorithm first searches in the linked list level of the sparsest sparse subsequence until the element to be found is between two adjacent elements in this level. At this time, the algorithm will jump to the next level and repeat the previous search until the priority element e to be found is found; if the element e is directly inserted into the front and back index points, there will be too many nodes between the two index points. At this time, the jump list height height is set, and a random integer α between [1, height] is randomly generated by a random function to maintain the size balance between the index and the original linked list. The random number determines the height of the newly added element index. For each layer β, a corresponding new element index is established in each layer, 1≤β≤α. If the random number α=height, a blank layer is added to the top layer of the skip list. This layer initially has no index, and the skip list height is increased by 1. At this time, the index and reach a balance; wherein a single linked list and a number count are associated with the priority element e, which are used to record the number of data in the single linked list; Step S4: When the priority element e needs to be deleted, the priority element e appears in the index. First, delete the node in the original linked list, and then delete the node in the index.

2. A data access method for a priority queue according to claim 1, characterized in that: The elements in each layer of the linked list of the multi-layer sparse subsequence in step S1 are subsets of the elements in the linked list of the previous layer.

3. The data access method of a priority queue according to claim 1, characterized in that: In step S1, the linked list of the sparse subsequence of each layer adopts a bidirectional linked list to store the head node and the tail node. The head node and the tail node are convenient for obtaining the data range of the skip list. The head node is the smallest node of the layer, and the tail node is the largest node of the layer.

4. The data access method of a priority queue according to claim 1, characterized in that: The singly linked list has the following characteristics: a. A single linked list contains a head node and a tail node; b. Method of enqueuing priority element e data: find the corresponding singly linked list according to the priority, then add an element data to the end of the singly linked list, adjust the tail pointer, and add 1 to count; c. Method to dequeue data of priority element e: find the singly linked list corresponding to the head of the jump list, dequeue the first data element of the single linked list, adjust the head pointer of the single linked list, and reduce count by 1; if this data element is the last element of this linked list, delete the linked list and the corresponding priority of the adjusted list.

Citation Information

Patent Citations

  • Queuing and de-queuing of data with a status cache

    US20040037302A1

  • Method and apparatus for implementing a lock-free skip list that supports concurrent accesses

    US7308448B1