Ring queue storage method, device, computing device, and storage medium
By expanding storage space when the ring queue is full and reducing it when it is not needed, the problem that the ring queue cannot be scaled is solved, and processing efficiency and responsiveness are improved.
Patent Information
- Application Number
- CN202010564489.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-19
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2040-06-19
AI Technical Summary
The existing ring queue requires a fixed-length array when initializing, and cannot expand the storage space, resulting in the failure of data placement in high concurrency scenarios, affecting the normal response of the program.
By determining the expansion position when the queue is full, adding the expansion array, storing elements into the expansion array, and deleting the excess expansion array when the queue is not saturated, dynamically adjusting the storage space of the queue.
It effectively expands the storage space of the queue, improves processing efficiency and program responsiveness, and avoids the risk of failure in data placement.
Smart Images

Figure CN111708495B_ABST
Abstract
Description
Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology. In financial technology, when facing massive data, queues are often needed for data processing. Queues are an ordered set that only allows deletion operations at the front end of the set and insertion operations at the back end of the set. Connecting the array subscripts q[0] and q[N-1] to form a ring space for storing queues can form a ring queue, where N indexes the length of the group.
[0003] Since a fixed-length array needs to be applied for when the circular queue is initialized, the number of elements that the circular queue can actually store is limited, and the storage space of the circular queue cannot be expanded. If the concurrency of the actual application scenario of the circular queue cannot be accurately estimated in advance, when using the circular queue, the configured circular queue length is too short, and the speed of putting data into the circular queue is greater than the speed of taking data out of the circular queue, the program that stores data through the circular queue will fail to put data into the storage, affecting the normal response of the program.
[0004] Based on this, the present application proposes a circular queue storage method to improve the configuration efficiency of the queue so as to adapt to the needs of various programs. Summary of the invention
[0005] The present application provides a ring queue storage method, apparatus, computing device, and storage medium to solve the problem that the existing ring queue storage space cannot be expanded, thereby improving the queue configuration efficiency and expanding the queue storage space.
[0006] In a first aspect, an embodiment of the present application provides a circular queue storage method. When the working status of the queue continues to be full within a first preset time period, the expansion position of the queue is determined and an expansion array of a specified length is expanded at the expansion position; the elements stored at the expansion position are stored to the position where the first subscript of the expansion array is located, and an expansion identifier for pointing to the expansion array is stored at the expansion position.
[0007] In this scheme, when it is determined that the working state of the queue continues to be full within the first preset time, that is, the storage space of the queue is insufficient, it is determined to add an expansion array in the queue, thereby expanding the storage space of the queue. Among them, the expansion position of the queue is determined and the expansion array of the specified length is expanded at the expansion position, the elements stored at the expansion position are stored to the position where the first subscript of the expansion array is located, and the expansion identifier for pointing to the expansion array is stored at the expansion position. In this way, the storage space of the queue is increased, and at the same time, the expanded queue is used to serve the program, which can further improve the processing efficiency of the program.
[0008] In an optional embodiment, the subscript of each storage location in the expanded array is a multi-dimensional subscript consisting of the subscript of the expanded location and the position of the storage location in the expanded array.
[0009] In this way, the location of the expansion space after the queue is expanded can be accurately determined, and the stored elements can be accurately found according to the index, further improving the efficiency of processing data through the queue.
[0010] In an optional embodiment, determining the expansion position of the queue includes:
[0011] If the queue is full for the first time, the expansion position is the position of the first subscript of the queue; if the queue is full for not the first time, the position of the most recent expansion identifier is determined, and the first position after the most recent expansion identifier is determined as the expansion position.
[0012] This method can accurately determine the expansion location so as to better configure the resources of the queue.
[0013] In an optional embodiment, after storing the expansion identifier pointing to the expansion array at the expansion position, the method further includes: when it is determined that the tail position index of the queue points to the expansion identifier, storing the element to be stored in the expansion array.
[0014] In this way, the elements to be stored can be stored in the expanded array.
[0015] In an optional embodiment, when the working state of the queue continues to be unsaturated within a second preset time period, the expansion identifier in the queue is searched; when no elements are stored in the expansion array corresponding to the expansion identifier, the expansion array corresponding to the expansion identifier is deleted.
[0016] This method can be used to delete redundant expansion arrays in the queue to better configure the queue's resources.
[0017] In an optional embodiment, it is determined that the queue is not saturated by: determining the number of expansion arrays of the queue;
[0018] When it is determined that the number of elements stored in the circular queue is less than a preset value, it is determined that the queue is not saturated; wherein the preset value is determined by performing an operation on the number of expansion arrays of the queue and the specified length.
[0019] This method can accurately determine when the operation of deleting the expanded array will be executed.
[0020] In an optional embodiment, an element deletion instruction is received, wherein the element deletion instruction includes a subscript of an element to be deleted;
[0021] The position corresponding to the subscript of the element to be deleted in the queue is set to empty.
[0022] By deleting elements in the queue in this way, the configuration efficiency of the queue is improved.
[0023] In a second aspect, an embodiment of the present application provides a ring queue storage device, comprising:
[0024] The determination module is used to determine the expansion position of the queue and expand the expansion array of the specified length at the expansion position when the working state of the queue continues to be full within a first preset time length.
[0025] The storage module is used to store the element stored in the expansion position to the position where the first subscript of the expansion array is located, and store an expansion identifier for pointing to the expansion array at the expansion position.
[0026] When it is determined that the working state of the queue continues to be full within the first preset time, that is, the storage space of the queue is insufficient, it is determined to add an expansion array in the queue to expand the storage space of the queue. Among them, the expansion position of the queue is determined and the expansion array of the specified length is expanded at the expansion position; the elements stored in the expansion position are stored to the position where the first subscript of the expansion array is located, and the expansion identifier for pointing to the expansion array is stored at the expansion position. The storage space of the queue is increased by the device, and the expanded queue is used to serve the program, which can further improve the processing efficiency of the program.
[0027] In an optional embodiment, the subscript of each storage location in the expanded array is a multi-dimensional subscript consisting of the subscript of the expanded location and the position of the storage location in the expanded array.
[0028] The device can accurately determine the location of the expansion space after the queue is expanded, and the stored data can be accurately found according to the index, further improving the efficiency of processing data through the queue.
[0029] In an optional embodiment, the determining module is used to:
[0030] If the queue is full for the first time, the expansion position is the position of the first subscript of the queue; if the queue is full for not the first time, the position of the most recent expansion identifier is determined, and the first position after the most recent expansion identifier is determined as the expansion position.
[0031] The device can accurately determine the expansion location so as to better configure the resources of the queue.
[0032] In an optional embodiment, the circular queue storage device further includes: an element storage module, which is used to store the element to be stored in the expansion array when it is determined that the tail position index of the queue points to the expansion identifier.
[0033] The device can be used to store the elements to be stored in the expanded array.
[0034] In an optional embodiment, the device also includes: a search module for searching for an expansion identifier in the queue when the working state of the queue continues to be unsaturated within a second preset time period; and when no elements are stored in the expansion array corresponding to the expansion identifier, deleting the expansion array corresponding to the expansion identifier.
[0035] This device can be used to delete redundant expansion arrays in the queue to better configure the resources of the queue.
[0036] In an optional embodiment, the device also includes: a queue status determination module, used to determine the number of expansion arrays of the queue; when it is determined that the number of elements stored in the circular queue is less than a preset value, it is determined that the queue is not saturated; wherein the preset value is determined by performing an operation on the number of expansion arrays of the queue and the specified length.
[0037] The device can accurately determine when the operation of deleting the expanded array will be executed.
[0038] In an optional embodiment, the device further includes an element deletion module, which is used to receive an element deletion instruction, wherein the element deletion instruction includes the subscript of the element to be deleted;
[0039] The position corresponding to the subscript of the element to be deleted in the queue is set to empty.
[0040] By using the device to delete elements in the queue, the configuration efficiency of the queue is improved.
[0041] In a third aspect, an embodiment of the present application further provides a computing device, including:
[0042] Memory and processor;
[0043] A memory for storing program instructions;
[0044] The processor is used to call the program instructions stored in the memory, and obtain the ring queue storage method described in any one of the first aspects of the program instructions.
[0045] In a fourth aspect, an embodiment of the present application further provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions are used to enable a computer to execute any of the circular queue storage methods in the embodiments of the present application.
[0046] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings introduced below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0048] Figure 1 A schematic diagram of a ring queue provided for related art;
[0049] Figure 2 A schematic diagram of a flow chart of a ring queue storage method provided in an embodiment of the present application;
[0050] Figure 3 A schematic diagram of queue expansion provided in an embodiment of the present application;
[0051] Figure 4 A schematic diagram of queue expansion provided in an embodiment of the present application;
[0052] Figure 5 A schematic diagram of queue expansion provided in an embodiment of the present application;
[0053] Figure 6 A schematic diagram of queue expansion provided in an embodiment of the present application;
[0054] Figure 7 A schematic diagram of queue expansion provided in an embodiment of the present application;
[0055] Figure 8 A schematic diagram of a process for reducing the capacity of a queue provided in an embodiment of the present application;
[0056] Fig. 9 A schematic diagram of queue reduction provided in an embodiment of the present application;
[0057] Fig.10 A schematic diagram of the structure of a ring queue storage device provided in an embodiment of the present application;
[0058] Fig.11 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0060] It should be noted that the terms "first", "second", etc. in this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0061] As described in the background technology, the length of the circular queue in the related art is limited, and the storage space cannot be expanded. Usually, the circular queue uses a modulo operation to realize the closed loop of the array logic, so that the queue head position index front and the queue tail position index rear can be repeatedly used in this closed loop. Figure 1 As shown, the length of the array is 8. The subscript 0 and subscript 7 of the array are connected to form a storage space of a circular queue. The front initially points to the subscript 0. If the data of the circular queue is full, the rear points to the subscript 7. When it is necessary to take out an element from the queue, it is necessary to take out the element from the front. Assuming that two elements are taken out, the front moves to the subscript 2 position. If an element is added to the queue at this time, the element is added after the rear. Adding an element is the 9th element that needs to be stored in the circular queue. By taking the array length 8 modulo 9 to get 1, the rear is moved to the subscript 1. However, since the length of the circular queue is limited, if a large number of elements need to be stored in the circular queue, it is necessary to reconfigure a circular queue with a larger storage space to store the elements. The reconfigured circular queue needs to copy the elements stored in the previous circular queue to a circular queue with a larger storage space. If the storage space is still insufficient after the elements are copied, it is necessary to continuously copy the elements and continuously configure a new circular queue with a larger storage space. This method of continuously copying elements wastes processor resources.
[0062] Based on this, the present application provides a ring queue storage method to improve the configuration efficiency of the queue, so that the expanded queue is more adaptable to the needs of the program.
[0063] The following is a detailed introduction to the ring queue storage process. In the following embodiments of the present application, "and / or" describes the association relationship of the associated objects, indicating that there may be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following" or its similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple. The singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear indication to the contrary in the context. Furthermore, unless otherwise specified, the ordinal numbers such as "first" and "second" mentioned in the embodiments of the present application are used to distinguish multiple objects, and are not used to limit the order, time sequence, priority or importance of multiple objects. For example, the first vehicle and the second vehicle are only used to distinguish different vehicles, and do not indicate the difference in priority or importance of the two vehicles.
[0064] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0065] like Figure 2 As shown, a circular queue storage method provided by an embodiment of the present application can be applied to a server of an application program that stores data and consumes data in a queue manner, and can also be applied to a server that processes data. The present application is not specifically limited here, and any device that uses a circular queue to store and consume data can execute the scheme of the present application. The present application is illustrated with the execution subject being a server. When it is specifically implemented, step 201 can be executed first. When the working state of the queue continues to be full within the first preset time length, the expansion position of the queue is determined and the expansion array of the specified length is expanded at the expansion position.
[0066] It should be noted that when the server monitors that the next position of the queue tail index of the queue within the first preset time is the head index, it is determined that the queue is in a full state, that is, the ring queue storage space is full, and the queue needs to be expanded. In addition, it should be noted that the first preset time can be configured according to user needs, such as: the first preset time is 30 seconds, the first preset time is 1 minute, and the value of the first preset time is not specifically limited here. Any time that meets user needs is applicable to this application.
[0067] Step 202: Store the element stored in the expanded position to the position where the first subscript of the expanded array is located, and store an expanded identifier for pointing to the expanded array in the expanded position.
[0068] It should be noted that when it is determined that the queue needs to be expanded, the expansion position needs to be determined. The method of determining the expansion position is inconsistent for the first expansion of the queue and the non-first expansion. In addition, the specified length of the expansion array is consistent with the initial length of the queue before expansion. The expansion position can be determined in the following way:
[0069] Method 1: Initial expansion of the queue
[0070] If the queue is full for the first time, that is, the queue needs to be expanded for the first time, the expansion position is the position of the first index of the queue. Figure 3 As shown, assuming that the queue has storage space for storing arrays of length n before expansion, when the server detects that the queue is full within a first preset time, that is, the next position of the rear is the front, the storage space of the array of length n is expanded at the expansion position. Figure 3 In the example, front points to subscript 3, and rear points to subscript 2, which means that the queue is full. Since the first subscript of the queue is located at the position of subscript 0, the position of subscript 0 is expanded, and the storage space of the expanded array with a length of n is expanded. The elements stored in the expanded position of subscript 0 are stored in the position of the first subscript of the expanded array 0, and the expansion identifier K=(0) used to point to the expanded array is stored in the expanded position so that the expanded array can be found.
[0071] When it is determined that the tail position index rear of the queue points to the expansion mark and there are new elements to be stored in the queue, the elements to be stored are stored in the expansion array. In this way, the elements to be stored can be stored in the expansion array. Figure 3Assume that front moves to the first index of the expansion array. After the element stored in the first index of the expansion array is taken out, since no elements are stored in other positions of the expansion array, front moves to index 1. At this time, if a new element is added to the queue and it is determined that rear points to the expansion identifier, the element to be stored is stored in the expansion array 0. When rear points to the last index of the expansion array, such as Figure 4 As shown. At this time, the server detects that the queue meets Figure 4 If the duration of the state in is the first preset duration, it is necessary to expand the queue again, which can be performed by referring to method 2.
[0072] Method 2: Queue expansion is not the first time
[0073] If the queue full working state does not occur for the first time, that is, the queue needs to be expanded again, the position of the most recent expansion marker is determined, and the first position after the most recent expansion marker is determined as the expansion position.
[0074] based on Figure 4 In the case of , we know that since the expansion mark is located at the position of subscript 0, the next position of subscript 0 is subscript 1, so we know that the expansion position is the position of subscript 1, and we can get Figure 5 The expansion array 1 is shown, and the expansion identifier is added to subscript 1. However, if the storage space of the queue still cannot meet the demand after subscript 0-subscript n-1 are expanded, it is necessary to expand again. In order to better identify the expansion position, a multi-dimensional subscript is introduced. The subscript in the expansion array is a multi-dimensional subscript composed of the subscript of each storage position of the expansion position and the position of the storage position in the expansion array. Figure 6 As shown, Figure 6 is Figure 5 The subscript identification is based on the expansion array 0. The first subscript is (0, 0), the second subscript is (0, 1), and so on, and the last subscript is (0, n-1); the first subscript of the expansion array 1 is (1, 0), the second subscript is (1, 1), and so on, and the last subscript is (1, n-1). When the queue is expanded to the expansion array n-1, and it still needs to continue to expand, the expansion identifier is pointed to the subscript (0, 0), and the expansion array (0, 0), such as Figure 7 As shown, the subscript of the expanded array is a three-dimensional subscript, where the first two digits are used to indicate the subscript of the array expansion position, and the third digit is used to indicate the position of the storage position in the expanded array, such as the first subscript is (0, 0, 0). The queue is expanded in this way, which avoids multiple copies of elements and can expand the storage space according to user needs.
[0075] When it is determined that the working status of the queue continues to be full within the first preset time period, that is, the storage space of the queue is insufficient, it is determined to add an expansion array in the queue to expand the storage space of the queue, determine the expansion position of the queue and add an expansion array of a specified length between the expansion position and the next position of the expansion position, store the elements stored in the expansion position to the position where the first subscript of the expansion array is located, and store an expansion identifier for pointing to the expansion array at the expansion position. In this way, the storage space of the queue is increased, and at the same time, the expanded queue is used to serve the program, which can further improve the processing efficiency of the program.
[0076] It should be noted that when the queue continues to expand for a period of time, some storage space may not store elements for a long time, then the queue needs to be reduced. Figure 8 To execute the step of reducing the capacity of the queue, step 801 may be executed first, and when the working state of the queue continues to be that the queue is not saturated within the second preset time period, an expansion flag in the queue is searched.
[0077] When the server detects that the queue is not saturated within the second preset time, it needs to reduce the storage space of the queue. In addition, it should be noted that the second preset time can be configured according to the user's needs. The length of the second preset time can be the same as the first preset time, or it can be different, such as: the second preset time is 45 seconds, the second preset time is 2 minutes, and the value of the second preset time is not specifically limited here. Any time that meets the user's needs is applicable to this application.
[0078] For example, the queue is not saturated, which does not only mean that the queue is not full, but is mainly determined in the following ways:
[0079] Step A1: Determine the number of queue expansion arrays.
[0080] Step A2: When it is determined that the number of elements stored in the circular queue is less than a preset value, it is determined that the queue is not saturated; wherein the preset value is determined by calculating the number of queue expansion arrays and the specified length.
[0081] Step 802: When no elements are stored in the capacity expansion array corresponding to the capacity expansion identifier, the capacity expansion array corresponding to the capacity expansion identifier is deleted.
[0082] For example, when the queue is not expanded, the number of elements that can be stored is n. After the first expansion, the number of expansion arrays is 1, and the number of elements that can be stored is 2n-1, because the position of subscript 0 is used to point to the expansion array 0 and does not store elements. By analogy, when the queue is expanded n times, the number of expansion arrays is n and the number of elements that can be stored is n*n. When the number of expansion arrays is 1, the preset value is 1*n, and the number of elements that can be stored after the queue is expanded is 2n-1, but the number of elements actually stored in the queue is less than n, so it is a waste to expand the expansion space of array 0, so the storage space can be deleted; based on the same reason, when the number of expansion arrays is n, the corresponding expansion identifier is K(n-1), and all the storage space of the original queue will not store any elements. Therefore, the preset value needs to be subtracted from the storage space length of the original queue, so the preset value is n*nn, and the number of elements that can be stored after the queue is expanded is n*n, but the number of elements actually stored in the queue is less than n*nn, so it is a waste to expand the expansion space of array n-1, so the storage space can be deleted. This method can be used to delete redundant expansion arrays in the queue to better configure the queue's resources. Fig. 9 As shown, the expansion mark is K(1). Fig. 9 If there are n elements stored in the array, the expansion array 1 can be deleted, the expansion identifier K(1) can be deleted, and the element NULL, i.e., an empty element, can be stored in subscript 1, and the expansion identifier K(0) can be stored in subscript 0.
[0083] In addition, in order to better calculate the number of expansion arrays, the calculation can be performed in the following way, where y(k) represents the number of expansion arrays that can be filled with elements under the expansion identifier K(k), as follows:
[0084] y(a)=a+1 Formula (1)
[0085] y(a,b)=a*n+(na-1)+b+1 Formula (2)
[0086] y(a, b, c) = a*n 2 +(na-1)*n+b*n+(nb-1)+c+1 Formula (3)
[0087] Where a, b, c>=0 and are integers. Formula (1) calculates the number of expansion arrays when the expansion mark is a one-dimensional subscript; formula (2) calculates the number of expansion arrays when the expansion mark is a two-dimensional subscript; formula (3) calculates the number of expansion arrays when the expansion mark is a one-dimensional subscript.
[0088] For example, when the expansion mark is a one-dimensional subscript K(0), the number of expansion arrays calculated by formula (1) is 1; when the expansion mark is a two-dimensional subscript K(0,0), the number of expansion arrays calculated by formula (2) is n+1; when the expansion mark is a two-dimensional subscript K(0,0,0), the number of expansion arrays calculated by formula (3) is n. 2 +1. Therefore, it is deduced that when the expansion identifier is an m-dimensional subscript, the number of expansion arrays can be expressed by the following formula.
[0089] y(X 1 , X 2 , …X m )=X 1 *n (m-1) +(nX 1 -1)*n (m-2) +X 2 *n (m-2) +(nX 2 -1)*n (m-3) +…+X m +1Formula(4)
[0090] Among them, X 1 , X 2 , …X m >=0 and is an integer.
[0091] By using formula (4), the number of expansion arrays can be accurately determined.
[0092] Next, the application introduces how to delete elements in the queue. Since multiple threads can read data (elements) in the circular queue and write elements in the circular queue, when a large number of threads write a lot of elements in the circular queue, but want to delete some elements at the same time, the existing queue is difficult to implement. Since elements are deleted in the existing queue, it is necessary to add a global lock to the queue first to prevent other threads from performing operations on the circular queue, and all elements after the subscript of the element to be deleted are moved to the previous subscript position, that is, the element is deleted. For example: the circular queue has 10 storage spaces, the subscript starts from 0, the element stored in subscript 7 is 1, the element stored in subscript 8 is 8, and the element stored in subscript 9 is 9; assuming that the element 1 stored in subscript 7 needs to be deleted, first add a global lock to the circular queue, and then move the elements stored at subscripts 8-9 one position forward in sequence, and also move the element 8 stored in subscript 8 to the position of subscript 7, and move the element 9 stored in subscript 9 to the position of subscript 8. Deleting elements in the queue in this way is inefficient and affects other process operations.
[0093] In this application, after receiving an element deletion instruction, the element deletion instruction includes the subscript of the element to be deleted; the position corresponding to the subscript of the element to be deleted in the queue is set to empty. When fetching data, the empty storage space is skipped, that is, the elements in the queue are deleted, and there is no need to add a global lock, which further saves the processing resources of the processor. By deleting elements in the queue in this way, the configuration efficiency of the queue is improved.
[0094] Based on the same concept, the ring queue storage device provided in the embodiment of the present application is as follows: Fig.10 As shown, the device includes: a determination module 100 and a storage module 101.
[0095] The determination module 100 is used to determine the expansion position of the queue and expand the expansion array of a specified length at the expansion position when the working state of the queue continues to be full within a first preset time.
[0096] The storage module 101 is used to store the element stored in the expansion position to the position where the first subscript of the expansion array is located, and store an expansion identifier for pointing to the expansion array in the expansion position.
[0097] When it is determined that the working state of the queue within the first preset time period continues to be full, that is, the storage space of the queue is insufficient, it is determined to add an expansion array in the queue to expand the storage space of the queue, determine the expansion position of the queue and expand the expansion array of a specified length at the expansion position, store the elements stored at the expansion position to the position where the first subscript of the expansion array is located, and store an expansion identifier for pointing to the expansion array at the expansion position. The storage space of the queue is increased by the device, and the expanded queue is used to serve the program, which can further improve the processing efficiency of the program.
[0098] In an optional embodiment, the subscript of each storage location in the expanded array is a multi-dimensional subscript consisting of the subscript of the expanded location and the position of the storage location in the expanded array.
[0099] The device can accurately determine the location of the expansion space after the queue is expanded, and the stored data can be accurately found according to the index, further improving the efficiency of processing data through the queue.
[0100] In an optional embodiment, the determining module 100 is used to:
[0101] If the queue is full for the first time, the expansion position is the position of the first subscript of the queue; if the queue is full for not the first time, the position of the most recent expansion identifier is determined, and the first position after the most recent expansion identifier is determined as the expansion position.
[0102] The device can accurately determine the expansion location so as to better configure the resources of the queue.
[0103] In an optional embodiment, the circular queue storage device further includes: an element storage module, which is used to store the element to be stored in the expansion array when it is determined that the tail position index of the queue points to the expansion identifier.
[0104] The device can be used to store the elements to be stored in the expanded array.
[0105] In an optional embodiment, the device also includes: a search module for searching for an expansion identifier in the queue when the working state of the queue continues to be unsaturated within a second preset time period; and when no elements are stored in the expansion array corresponding to the expansion identifier, deleting the expansion array corresponding to the expansion identifier.
[0106] This device can be used to delete redundant expansion arrays in the queue to better configure the resources of the queue.
[0107] In an optional embodiment, the device also includes: a queue status determination module, used to determine the number of expansion arrays of the queue; when it is determined that the number of elements stored in the circular queue is less than a preset value, it is determined that the queue is not saturated; wherein the preset value is determined by performing an operation on the number of the queue expansion array and the specified length.
[0108] The device can accurately determine when to execute the operation of deleting multiple expansion data.
[0109] In an optional embodiment, the device further includes an element deletion module, which is used to receive an element deletion instruction, wherein the element deletion instruction includes the subscript of the element to be deleted;
[0110] The position corresponding to the subscript of the element to be deleted in the queue is set to empty.
[0111] By using the device to delete elements in the queue, the configuration efficiency of the queue is improved.
[0112] After introducing the circular queue storage method and apparatus in the exemplary embodiment of the present application, next, a computing device in another exemplary embodiment of the present application is introduced.
[0113] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.
[0114] In some possible implementations, the computing device according to the present application may include at least one processor and at least one memory. The memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the ring queue storage method according to various exemplary implementations of the present application described above in this specification. For example, the processor may execute the following steps: Figure 2 Steps 201-202 shown in FIG.
[0115] Refer to the following Fig.11 hereinafter, a computing device 130 according to this embodiment of the present application is described. Fig.11 The computing device 130 shown is only an example and should not limit the functionality and scope of use of the embodiments of the present application. Fig.11 As shown, the computing device 130 is in the form of a general intelligent terminal. The components of the computing device 130 may include but are not limited to: at least one processor 131, at least one memory 132, and a bus 133 connecting different system components (including the memory 132 and the processor 131).
[0116] Bus 133 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus structures. Memory 132 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 1321 and / or a cache memory 1322, and may further include a read-only memory (ROM) 1323. Memory 132 may also include a program / utility 1325 having a set (at least one) of program modules 1324, such program modules 1324 include but are not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include the implementation of a network environment.
[0117] The computing device 130 may also communicate with one or more external devices 134 (e.g., keyboards, pointing devices, etc.), and / or with any device (e.g., routers, modems, etc.) that enables the computing device 130 to communicate with one or more other intelligent terminals. Such communication may be performed via an input / output (I / O) interface 135. In addition, the intelligent terminal 130 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 136. As shown, the network adapter 136 communicates with other modules for the computing device 130 via a bus 133. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the computing device 130, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0118] In some possible implementations, various aspects of the ring queue storage method provided by the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on a computer device, the computer program is used to cause the computer device to execute the steps of the ring queue storage method according to various exemplary implementations of the present application described above in this specification. For example, the processor may execute the following steps: Figure 2 Steps 201-202 shown in FIG.
[0119] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0120] The program product for three-dimensional visual relocalization of the embodiment of the present application may adopt a portable compact disk read-only memory (CD-ROM) and include a computer program, and can be run on a smart terminal. However, the program product of the present application is not limited thereto. In this document, a readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus, or device.
[0121] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, in which a readable computer program is carried. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0122] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units to be embodied.
[0123] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0124] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0125] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0126] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0127] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0128] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A ring queue storage method, characterized in that: include: When the working state of the queue continues to be full within the first preset time, determining the expansion position of the queue and expanding the expansion array of the specified length at the expansion position; The element stored in the expansion position is stored in the position where the first subscript of the expansion array is located, and an expansion identifier for pointing to the expansion array is stored in the expansion position; The subscript of each storage position in the capacity expansion array is a multi-dimensional subscript consisting of the subscript of the capacity expansion position and the position of the storage position in the capacity expansion array.
2. The method according to claim 1, characterized in that The determining the expansion position of the queue includes: If the queue is full for the first time, the expansion position is the position of the first subscript of the queue; If the queue full working state does not occur for the first time, the position of the most recent expansion mark is determined, and the first position after the most recent expansion mark is determined as the expansion position.
3. The method according to claim 1, characterized in that After storing the expansion identifier pointing to the expansion array at the expansion position, the method further includes: When it is determined that the tail position index of the queue points to the expansion identifier, the elements to be stored are stored in the expansion array.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When the working state of the queue within the second preset time period continues to be that the queue is not saturated, searching for an expansion flag in the queue; When no elements are stored in the capacity expansion array corresponding to the capacity expansion identifier, the capacity expansion array corresponding to the capacity expansion identifier is deleted.
5. The method according to claim 4, characterized in that Verify that the queue is not saturated by: Determining the number of expansion arrays of the queue; When it is determined that the number of elements stored in the circular queue is less than a preset value, it is determined that the queue is not saturated; wherein the preset value is determined by performing an operation on the number of expansion arrays of the queue and the specified length.
6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Receiving an element deletion instruction, wherein the element deletion instruction includes a subscript of an element to be deleted; The position corresponding to the subscript of the element to be deleted in the queue is set to empty.
7. A ring queue storage device, characterized in that: include: A determination module, configured to determine a capacity expansion position of the queue and expand a capacity expansion array of a specified length at the capacity expansion position when the working state of the queue continues to be full within a first preset time length; A storage module, used for storing the element stored in the expansion position to the position where the first subscript of the expansion array is located, and storing an expansion identifier for pointing to the expansion array at the expansion position; The subscript of each storage position in the capacity expansion array is a multi-dimensional subscript consisting of the subscript of the capacity expansion position and the position of the storage position in the capacity expansion array.
8. A computing device, characterized in that include: Memory and processor; Memory, used to store programs; A processor, configured to call the program stored in the memory, and execute the method according to any one of claims 1 to 6 according to the obtained program.
9. A computer storage medium storing a computer program executable by a computer, characterized in that: The computer executable computer program is used to perform the method according to any one of claims 1-6.
Citation Information
Patent Citations
Extension ring buffer for data transmission
JP1990253462A