A numbering allocation method, apparatus, electronic device, and storage medium
By managing numbers through a skip list with a numbered storage, and utilizing a multi-level index hierarchy and a binary search algorithm, the problem of low efficiency in number management is solved, enabling fast number allocation and efficient statistics. It is suitable for scenarios that support pre-allocation and non-contiguous number allocation.
Patent Information
- Application Number
- CN202310141649.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-13
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2043-02-13
AI Technical Summary
Existing technologies suffer from inefficiency in number management, inability to support pre-allocation scenarios, and inability to efficiently count the usage of number ranges. In particular, under the unidirectional linked list storage method, the efficiency of number allocation and query is not high, and it cannot meet the needs of non-contiguous number allocation.
Numbering is managed using a numbered skip list. Target data elements are searched through multi-level indexes, and valid numbers within the numbering interval to be assigned are marked in the numbered skip list. A binary search algorithm is then used to quickly find valid data elements, achieving fast numbering and efficient statistics.
It enables fast and batch number allocation in number pre-occupancy scenarios, supports efficient statistics on the number of valid numbers used in any number range, and improves the efficiency of number allocation and query.
Smart Images

Figure CN116010427B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing technology, and includes, but is not limited to, a numbering allocation method, apparatus, electronic device, and storage medium. Background Technology
[0002] For the generation or management of serial numbers, a singly linked list is generally used for storage. However, the singly linked list storage method has the following drawbacks: First, it is inefficient when supporting pre-allocation scenarios, as all data needs to be traversed and queried each time a serial number is allocated. Second, when counting the usage of valid serial numbers, all valid serial numbers need to be aggregated and counted, which is inefficient. Third, it cannot achieve efficient statistical counting of serial number ranges. In addition, compared with ordinary data query scenarios, serial number allocation may involve pre-occupancy, meaning that the allocated serial numbers are not consecutive, and traditional binary search cannot meet the requirements of this scenario. Summary of the Invention
[0003] In view of this, embodiments of the present disclosure provide a numbering allocation method, apparatus, electronic device, and storage medium.
[0004] In a first aspect, embodiments of this disclosure provide a numbering allocation method, the method comprising:
[0005] The first target data element located in the next lowest level index is retrieved from the numbered skip list; wherein the numbered skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different numbering intervals in the lowest level index level; the attribute information of the data element includes at least the statistical value of the valid number in the numbering interval corresponding to the data element; the statistical value of the first target data element is greater than zero;
[0006] Determine the first numbering interval to be assigned corresponding to the first target data element in the lowest level index;
[0007] If the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element, the first k valid numbers in the first number interval to be assigned are marked as assigned numbers; where m and k are both positive integers.
[0008] In some embodiments, the attribute information of the data element further includes: usage status; the usage status includes at least occupancy and availability.
[0009] In some embodiments, the valid number is the number whose statistical value is 1 and whose usage status is "available". Marking the first k valid numbers in the first number interval to be assigned includes:
[0010] The statistical value of the first k valid numbers in the first numbering interval to be allocated is marked as 0, and the usage status of the first k valid numbers in the first numbering interval to be allocated is marked as occupied.
[0011] In some embodiments, marking the first k valid numbers in the first numbering interval to be assigned further includes:
[0012] The numerical value of the statistical value of the first target data element in each index level of the numbered skip list is marked as mk.
[0013] In some embodiments, when the number of numbers to be assigned, k, is greater than the statistical value m of the first target data element, the method further includes:
[0014] Determine the second target data element located in the next lower level index based on the first target data element;
[0015] Determine the second numbering interval to be assigned corresponding to the second target data element in the lowest level index;
[0016] The first km of valid numbers in the second numbering interval to be assigned are marked as assigned numbers.
[0017] In some embodiments, the valid number is the number whose statistical value is 1 and whose usage status is "available". Marking the first km valid numbers in the second numbering interval to be assigned includes:
[0018] The statistical values of all valid numbers in the first number interval to be allocated and the first km valid numbers in the second number interval to be allocated are all marked as 0. Furthermore, the usage status of all numbers in the first number interval to be allocated and the first km valid numbers in the second number interval to be allocated is marked as occupied.
[0019] In some embodiments, marking the first km valid numbers in the second numbering interval to be assigned further includes:
[0020] The statistical value of the first target data element in each index level of the numbered skip list is marked as 0, and the statistical value of the second target data element in each index level of the numbered skip list is marked as n-k+m, where n is the statistical value of the second target data element and n is a positive integer.
[0021] In some embodiments, the attribute information of the data element further includes: number, index level, down pointer, and right pointer;
[0022] Wherein, the data element number in the lowest level index is valid; the usage status of the data elements corresponding to other index levels besides the lowest level index is invalid;
[0023] In the other index levels, the span values of the numbering intervals corresponding to any adjacent data elements are the same.
[0024] In some embodiments, retrieving the first target data element located in the next lower level index from the numbered skip list includes:
[0025] The binary search algorithm is used to find the first valid data element with a statistical value greater than zero, starting from the highest level of the index.
[0026] Based on the lower pointer of the valid data element, the first target data element located in the next lower level index is found.
[0027] In some embodiments, determining the first numbering interval to be assigned corresponding to the first target data element in the lowest level index includes:
[0028] The interval containing the number of the first target data element in the lowest level index is determined as the first number interval to be assigned.
[0029] In some embodiments, determining a second target data element based on the first target data element includes:
[0030] The data element pointed to by the right pointer of the first target data element is determined as the second target data element.
[0031] Secondly, embodiments of this disclosure provide a numbering allocation device, comprising:
[0032] The query module is used to find the first target data element located in the second lowest level index from the number storage skip list; wherein, the number storage skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different number intervals in the lowest level index level; the attribute information of the data element includes at least the statistical value of the valid number in the number interval corresponding to the data element; the statistical value of the first target data element is greater than zero;
[0033] The first determining module is used to determine the first numbering interval to be assigned corresponding to the first target data element in the lowest level index level;
[0034] The marking module is used to mark the first k valid numbers in the first interval of numbers to be assigned as assigned numbers when the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element; where m and k are both positive integers.
[0035] In some embodiments, a second determining module is also included;
[0036] The second determining module is used to determine a second target data element located in the next lower level index based on the first target data element;
[0037] The first determining module is further configured to determine the second numbering interval to be assigned corresponding to the second target data element in the lowest level index level;
[0038] The marking module is further configured to mark the first km valid numbers in the second number interval as assigned numbers when the number of numbers to be assigned k is greater than the number of valid numbers used in the first number interval to be assigned m.
[0039] Thirdly, embodiments of this disclosure provide an electronic device, including: a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor executes the program to implement the steps in the above-described method.
[0040] Fourthly, embodiments of this disclosure provide a storage medium storing executable instructions for inducing a processor to execute the steps in the above-described method.
[0041] The number allocation method, apparatus, electronic device, and storage medium provided in this disclosure include: retrieving the first target data element located in the second-lowest index level from a number storage skip list; determining the first number interval to be allocated corresponding to the first target data element in the lowest index level; and marking the first k valid numbers in the first number interval to be allocated as allocated numbers if the number of numbers to be allocated, k, is less than or equal to the statistical value m of the first target data element. Since this disclosure manages and allocates numbers through a number storage skip list, it can achieve fast number allocation in scenarios supporting number pre-occupancy and supports batch number allocation. Furthermore, since the attribute value of each data element in the number storage skip list in this disclosure includes a statistical value, it is possible to efficiently count the number of valid numbers used in any number interval. Attached Figure Description
[0042] Figure 1 This is a schematic diagram of the skip list structure;
[0043] Figure 2Schematic diagram of the implementation process of the numbering allocation method provided in the embodiments of this disclosure Figure 1 ;
[0044] Figure 3 Schematic diagram of the implementation process of the numbering allocation method provided in the embodiments of this disclosure Figure 2 ;
[0045] Figure 4 Schematic diagram of the implementation process of the numbering allocation method provided in the embodiments of this disclosure Figure 3 ;
[0046] Figure 5 This is a schematic diagram of the structure of the number storage skip list provided in the embodiments of this disclosure;
[0047] Figure 6 A schematic diagram illustrating the composition structure of a data element provided in an embodiment of this disclosure;
[0048] Figure 7 This is a schematic diagram of the composition structure of the numbering allocation device provided in the embodiments of this disclosure;
[0049] Figure 8 This is a schematic diagram of a hardware entity of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of this disclosure clearer, the disclosure will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this disclosure. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0051] In the following description, references to "some embodiments" describe a subset of all possible embodiments; however, it is understood that "some embodiments" may be the same or different subsets of all possible embodiments and may be combined with each other without conflict. Unless otherwise defined, all technical and scientific terms used in the embodiments of this disclosure have the same meaning as commonly understood by one of ordinary skill in the art to which the embodiments of this disclosure belong. The terminology used in the embodiments of this disclosure is for the purpose of describing the embodiments of this disclosure only and is not intended to be limiting of the disclosure.
[0052] It should be noted that the terms "first, second, and third" used in the embodiments of this disclosure are merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0053] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which these embodiments pertain. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0054] Assigning numbers (e.g., employee IDs, project numbers, document numbers, etc.) is a very important task in the field of data processing technology. Below, using employee IDs as a reference, the solution of this disclosure embodiment will be described in further detail.
[0055] The generation and maintenance of employee ID numbers play a crucial role in human resources systems. As an employee's unique identifier within the company, the employee ID is linked to a vast amount of personal data. Therefore, the employee ID generation and maintenance system needs to possess the following characteristics: Efficiency: During peak employee onboarding periods (such as the peak onboarding period for recent graduates), it needs to support efficient employee ID maintenance; Pre-allocation: From the time an employee registers until they actually report for duty, their employee ID is in a pre-occupied state, and if the employee does not actually start work, the system needs to support the retrieval of the ID; Continuity: Employee ID numbers should be allocated sequentially based on the order of onboarding, in an ascending order; Fixed length: Employee ID numbers are fixed-length numbers. For employee ID generation and management, a singly linked list is generally used for storage. However, this method has the following drawbacks: First, it is inefficient in scenarios supporting pre-allocation, requiring a complete traversal of all data each time an ID is allocated. Second, when calculating the usage of valid employee IDs, it is inefficient to aggregate and count all valid IDs. Third, it cannot efficiently perform statistical counting of defined employee ID ranges. Furthermore, compared to ordinary data query scenarios, employee ID allocation involves pre-occupancy, meaning that allocated employee IDs are not consecutive, making traditional binary search unsuitable for this scenario.
[0056] Based on this, embodiments of this disclosure provide a number allocation method that manages and allocates numbers through a number storage skip list. In scenarios supporting number pre-occupancy, this method enables rapid number allocation and supports batch number allocation. Furthermore, since the attribute value of each data element in the number storage skip list of this disclosure includes a statistical value, it is possible to efficiently count the number of valid numbers used within any number range.
[0057] The number allocation method provided in this disclosure can be implemented by a processor in an electronic device calling program code, which can be stored in the storage medium of the electronic device. Furthermore, since the number allocation method provided in this disclosure manages numbers based on a number storage skip list, the skip list will be described first before detailing the number allocation method in this disclosure.
[0058] A skip list is a data structure used for fast searching of ordered sequences of elements. It's a randomized data structure, essentially an ordered linked list that allows for binary search. Skip lists add multi-level indexes to an existing ordered linked list, enabling fast lookups. Skip lists not only improve search performance but also the performance of insertion and deletion operations. Its performance is comparable to red-black trees and AVL trees, but the principle behind skip lists is much simpler, and their implementation is also much simpler.
[0059] Searching, inserting, and deleting operations in a skip list all have a time complexity of O(log n), however, the worst-case time complexity becomes O(n). In contrast, insertion or deletion operations in a sorted array or linked list have a time complexity of O(n), with a worst-case time complexity of O(n).
[0060] Figure 1 This is a schematic diagram of the skip list structure. The following section combines... Figure 1 The skip list search process works as follows: First, it searches for the last element less than or equal to the current element at the highest-level index. Then, it jumps to the next higher-level index to continue searching until it reaches the lowest-level index, at which point it is very close to the element being searched for. For example, when searching for element 5, the highest-level index determines the current element's position to be within the range [-1, 6]. The next higher-level index determines its position to be within the range [4, 6]. Then, it uses the down pointer to jump to the lowest-level index until element 5 is found. Because multiple elements can be skipped at once using the index, the search speed is faster than a normal traversal search.
[0061] Figure 2 Schematic diagram of the implementation process of the numbering allocation method provided in the embodiments of this disclosure Figure 1 ,like Figure 2 As shown, the numbering allocation method includes the following steps:
[0062] Step S201: Locate the first target data element in the second-lowest index level from the number storage skip list; wherein, the number storage skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different number intervals in the lowest index level; the attribute information of the data element includes at least the statistical value of the valid number in the number interval corresponding to the data element; the statistical value of the first target data element is greater than zero.
[0063] It should be noted that the number in the numbering allocation method provided in this embodiment can be an employee number, a file number, a project number, a product number, or other continuous and fixed-length string of numbers.
[0064] In this embodiment, the number storage skip list is a skip list with multiple index levels. Each index level includes multiple data elements, and each data element corresponds to a different numbering interval in the lowest-level index level. Each data element in the lowest-level index level corresponds to one number. The attribute information of the data element includes at least the statistical value of the valid numbers in the numbering interval corresponding to the data element. That is, each data element records the number of unoccupied numbers in the numbering interval corresponding to the data element. The statistical value of each data element in the lowest-level index level is 0 or 1.
[0065] In other embodiments, the attribute information of the data element also includes number, usage status, index level, right pointer, and down pointer. The usage status refers to the usage status of the number in different numbering intervals within the lowest-level index level corresponding to the data element. Usage status includes available, occupied, and obsolete, where occupied includes pre-occupied and already occupied.
[0066] It should be noted that the second-lowest level index is the index level that is adjacent to the lowest level index and is one level above the lowest level index. For example, the lowest level index can be level 0, and the second-lowest level index can be level 1.
[0067] It should also be noted that the data element numbers in the lowest level index are valid; the usage status of data elements in other index levels is invalid.
[0068] In some embodiments, the span values of the numbering intervals corresponding to any adjacent data elements in the index levels other than the lowest level are the same. This makes the numbering intervals more uniform, which is beneficial to improving search efficiency.
[0069] In this embodiment of the disclosure, before number allocation, it is necessary to find the first target data element located in the second lowest level index from the number storage skip list, and the statistical value of the first target data element is greater than zero. In other words, before number allocation, it is necessary to find the first number interval with a valid number of usage greater than zero, and number allocation will be carried out in this number interval.
[0070] Step S202: Determine the first numbering interval to be assigned in the lowest level index for the first target data element.
[0071] In this embodiment of the disclosure, each data element has a corresponding numbering interval in the lowest level index. The specific correspondence process is as follows: assuming the data span between adjacent data elements is u, and assuming the first target data element found is Slot[i][1], then the first numbering interval to be assigned in the corresponding lowest level index is Slot[i-u+1][0]~Slot[1][0].
[0072] Step S203: If the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element, mark the first k valid numbers in the first number interval to be assigned as assigned numbers; where m and k are both positive integers.
[0073] It should be noted that before assigning numbers, it is necessary to determine the relationship between the statistical value m of the first target data element and the data k to be assigned. That is, to confirm whether the number of valid numbers used in the first number interval to be assigned corresponding to the first target data element is sufficient for the current number assignment process. When the number of valid numbers used in the first number interval to be assigned is sufficient for the current number assignment (i.e., k≤m), the first k valid numbers in the first number interval to be assigned are marked as assigned numbers. When the number of valid numbers used in the first number interval to be assigned is insufficient for the current number assignment (i.e., k>m), the remaining numbers need to be redistributed.
[0074] It should also be noted that marking a number indicates that the number has been occupied or pre-occupied, meaning that the number has already been allocated. This way, these numbers will not be allocated again in the next number allocation process, thus avoiding the situation of duplicate allocation of numbers.
[0075] Because this embodiment manages and allocates numbers through a number storage skip list, it enables rapid number allocation in scenarios that support number pre-occupancy and also supports batch number allocation. Furthermore, since the attribute value of each data element in the number storage skip list in this embodiment includes a statistical value, it is possible to efficiently count the number of valid numbers used within any number range.
[0076] Based on the foregoing embodiments, this disclosure further provides a numbering allocation method. Figure 3 Schematic diagram of the implementation process of the numbering allocation method provided in the embodiments of this disclosure Figure 2 ,like Figure 3 As shown, the numbering allocation method includes the following steps:
[0077] Step S301: Locate the first target data element in the second-lowest index level from the number storage skip list; wherein, the number storage skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different number intervals in the lowest index level; the attribute information of the data element includes at least the statistical value of the valid number in the number interval corresponding to the data element; the statistical value of the first target data element is greater than zero.
[0078] Step S302: Determine the first numbering interval to be assigned in the lowest level index for the first target data element.
[0079] Step S303: If the number of numbers to be assigned, k, is greater than the statistical value m of the first target data element, determine the second target data element located in the next lower level index based on the first target data element.
[0080] When the number of pending numbers k is greater than the statistical value m of the first target data element—that is, when the number of valid numbers in the first pending number interval corresponding to the first target data element found in the number storage skip list is insufficient for the current number allocation process—a second target data element located in the next lower level index needs to be determined based on the first target data element found. Here, the statistical value of the second target data element is greater than zero, meaning that there are available pending numbers in the number interval corresponding to the second target data element.
[0081] It should be noted that the second target data element is the next target data element in the index level where the first target data element is located, that is, the numbering process is continuously increasing.
[0082] Step S304: Determine the second numbering interval to be assigned in the lowest level index for the second target data element.
[0083] In this embodiment of the disclosure, the process of determining the second number interval to be allocated in the lowest level index of the second target data element is the same as the process of determining the first number interval to be allocated in the lowest level index of the first target data element in step S202. Assuming that the data span between adjacent data elements is u, and assuming that the second target data element found is Slot[2i][1], then the second number interval to be allocated in the corresponding lowest level index is Slot[2i-u+1][0]~Slot[2i][0].
[0084] Step S305: Mark the first km of valid numbers in the second numbering interval to be assigned as assigned numbers.
[0085] In this embodiment, since the number of valid numbers used (m) in the first numbering interval to be allocated is insufficient to allocate (k) numbers, after all valid numbers in the first numbering interval to be allocated are allocated, (km) numbers remain unallocated. These remain to be allocated in the second numbering interval to be allocated. Before allocating (km) numbers, it is necessary to determine whether the number of valid numbers used (n) in the second numbering interval to be allocated can satisfy the allocation of (km) numbers (i.e., whether n is greater than or equal to (km)). If it can (i.e., n ≥ (km)), then the first (km) numbers in the second numbering interval to be allocated are directly marked as allocated numbers. If it cannot (i.e., n < (km)), it is necessary to find the third target data element located in the next lower-level index interval based on the second target data element, and allocate the remaining unallocated (kmn) numbers. This process continues until all numbers are allocated.
[0086] It should be noted that marking the first km of valid numbers in the second numbering interval indicates that the first km of valid numbers in the second numbering interval has been occupied or pre-occupied. In other words, the first km of valid numbers in the second numbering interval has been allocated. Thus, in the next numbering process, the first km of valid numbers in the second numbering interval will not be allocated again, that is, there will be no duplicate allocation of numbers.
[0087] Based on the foregoing embodiments, this disclosure further provides a numbering allocation method. Figure 4 Schematic diagram of the implementation process of the numbering allocation method provided in the embodiments of this disclosure Figure 3 ,like Figure 4 As shown, the numbering allocation method includes the following steps:
[0088] Step S401: Use a binary search algorithm to find the first valid data element with a statistical value greater than zero, starting from the highest level of the index.
[0089] Step S402: Based on the down pointer of the valid data element, find the first target data element located in the next lower level index.
[0090] Assuming the numbered skip list in this embodiment includes 16 index levels, the search starts from the 16th index level. First, it is determined whether the statistical value of the data element at the 16th index level is greater than zero. If it is greater than zero, it is determined whether the statistical value of the data element at the 8th index level is greater than zero. If it is, it is determined whether the statistical value of the data element at the 4th index level is greater than zero. If the statistical value of the data element at the 8th index level is equal to zero, it is determined whether the statistical value of the data element at the 12th index level is greater than zero. This process continues until the first valid data element with a non-zero (i.e., greater than zero) statistical value is found. Assuming the found valid data element is the data element Slot[i]
[12] at the 12th index level, the first target data element Slot[i][1] in the next lower index level (i.e., the 1st index level) is found through the down pointer of the data element Slot[i]
[12] .
[0091] Step S403: Determine the interval where the actual number of the first target data element is located in the lowest level index as the first number interval to be assigned.
[0092] In this embodiment of the disclosure, since each index level includes multiple data elements that correspond to different numbering intervals in the lowest index level, i.e., the data elements and numbering intervals are in a one-to-one correspondence, the first numbering interval to be allocated corresponding to the first target data element can be determined when the first target data element is determined.
[0093] Step S404: Determine whether the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element.
[0094] In some embodiments, when the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element, steps S405 and S406 are executed; when the number of numbers to be assigned, k, is greater than the statistical value m of the first target data element, steps S407 to S409 are executed.
[0095] Step S405: Mark the statistical value of the first k valid numbers in the first numbering interval to be allocated as 0, and mark the usage status of the first k valid numbers in the first numbering interval to be allocated as occupied.
[0096] In some embodiments, a valid number refers to a number with a statistical value of 1 and a usage status of available, while an assigned number refers to a number with a statistical value of 0 and a usage status of occupied or abandoned; here, occupied includes both occupied and pre-occupied situations.
[0097] In this embodiment of the disclosure, the statistical value of the first k valid numbers in the first numbering interval to be allocated is marked as 0, and the usage status of the first k valid numbers in the first numbering interval to be allocated is marked as occupied, indicating that the first k valid numbers in the first numbering interval to be allocated have been allocated.
[0098] Step S406: Mark the numerical value of the statistical value of the first target data element in each index level of the numbered skip list as mk.
[0099] In some embodiments, in addition to marking the statistical values and usage status of the first k valid numbers in the first numbering interval to be allocated, the number storage skip list also needs to be updated, mainly by updating the statistical values and usage status of data elements. This way, in the next numbering process, the first k valid numbers in the first numbering interval to be allocated do not need to be considered, as they have already been used. Specifically, the process of updating the number storage skip list involves marking the statistical value of the first target data element in each index level as mk.
[0100] Step S407: The data element pointed to by the right pointer of the first target data element is determined as the second target data element.
[0101] It should be noted that the first target data element and the second target data element have the same index level, and the numbering interval corresponding to the second target data element is the next numbering interval corresponding to the first target data element, which also shows that the numbering allocation is continuous.
[0102] In step S408, the statistical values of all valid numbers in the first numbering interval to be assigned and the first km valid numbers in the second numbering interval to be assigned are all marked as 0, and the usage status of all valid numbers in the first numbering interval to be assigned and the first km valid numbers in the second numbering interval to be assigned is marked as occupied.
[0103] As mentioned above, a valid number refers to a number with a statistical value of 1 and a usage status of available. Correspondingly, an assigned number refers to a number with a statistical value of 0 and a usage status of occupied or abandoned. Here, occupied includes both occupied and pre-occupied situations.
[0104] When the number of numbers to be assigned, k, is greater than the statistical value m of the first target data element, number allocation is required between the number intervals corresponding to the two target data elements. The specific allocation process is as follows: first, all valid numbers in the first number interval corresponding to the first target data element are allocated; then, the remaining numbers are allocated from the second number interval corresponding to the second target data element. Correspondingly, after number allocation, the number storage skip list needs to be updated. The update process includes updating the statistical value and usage status of the data elements. For example, the statistical values of all valid numbers in the first number interval and the first k valid numbers in the second number interval are marked as 0, and the usage status of all valid numbers in the first number interval and the first k valid numbers in the second number interval is marked as occupied.
[0105] Step S409: Mark the statistical value of the first target data element in each index level of the numbered skip list as 0, and mark the statistical value of the second target data element in each index level of the numbered skip list as n-k+m, where n is the statistical value of the second target data element and n is a positive integer.
[0106] When assigning numbers using the numbering intervals corresponding to two target data elements, the statistical values of these two target data elements in all index levels need to be updated. The implementation process of step S409 is the same as that of step S406, and will not be repeated here.
[0107] The number allocation method provided in this disclosure can achieve fast number allocation in scenarios that support number pre-reservation, and also supports batch number allocation. Furthermore, in scenarios that support number pre-reservation, the statistical value of the data element at each index level can represent the statistical value of the number of available numbers in the lowest-level index corresponding to that data element.
[0108] Another embodiment of this disclosure designs a skip list 500 storing a specific data element structure (corresponding to the numbered skip list in the above embodiments), such as... Figure 5 As shown, the skip list 500 consists of N index levels. Level 0 is a series of consecutive numeric units (i.e., numbers), representing a valid data range. The range of these consecutive numeric units is [1, 100*N], meaning this structure can be used for number allocation within the range [1, 10*N]. Level j covers (N-j+1) data elements. Each data element in skip list 500 has the same storage structure, as shown in the data structure below. Figure 6As shown, the following are the values: status, which represents the current status of the data element (corresponding to the usage status in the above embodiments), such as available, pre-occupied, occupied, or abandoned; count, which represents the number of available numbers within the numbering interval corresponding to the current data element (corresponding to the statistical value in the above embodiments); right, which represents the address of the next data element in the same index level (corresponding to the right pointer in the above embodiments); level, which represents the index level of the current data element (corresponding to the index level in the above embodiments); num, which represents the actual number of the current data element (corresponding to the number in the above embodiments); and down, which represents the address of the data element located below the current data element (corresponding to the down pointer in the above embodiments).
[0109] It should be noted that in the initial state, the status of each data element is "available", and the count of each data element in the j-level index is 100*j and the level is j.
[0110] Each data element in skip list 500 is represented by slot[x][y], where x represents the index position of the data element in the current index level, y represents the index level, the count of the slot[x][y] data element is represented as slot[x][y](count), and the num of the slot[x][y] data element is represented as slot[x][y](num).
[0111] In skip list 500, the data element `slot[j*100][j](count)` represents the statistical value of the usage status from 1 to j*100 in index level 0. Data elements `slot[j*100][j-1](count)`, `slot[j*100][j-2](count)`, and `slot[j*100][j-3](count)` represent the statistical values of the usage status from (j-1)*100 to j*100 in index level 0. The data structure of data elements in index levels 0 through N is the same. The `status` value of data elements in index levels 1 through N is invalid, and the `count` value of data elements in index level 0 is invalid.
[0112] Next, use Figure 5 The skip list shown illustrates the numbering method in this embodiment of the disclosure. Assuming the number of numbers to be allocated is K, the specific process of numbering allocation is as follows:
[0113] Step 1: Starting from the data element slot[N*100][N] in the highest index level N, use the binary search algorithm to find the first level 1 index slot[i][1] with a non-zero count value. Specifically:
[0114] 1.1 Determine if the data element slot[N*100][N](count) is greater than 0;
[0115] 1.2 If slot[N*100][N](count)>0, then determine whether the data element slot[N / 2*100][N / 2](count) is greater than 0;
[0116] 1.2.1 If it is greater than 0, then continue to check whether slot[N / 4*100][N / 4](count) is greater than 0;
[0117] 1.3 If slot[N*100][N](count)=0, then determine whether the data element slot[N3 / 4*100][N3 / 4](count) is greater than 0;
[0118] This process continues until the first data element slot[i][1] (corresponding to the first target data element in the above embodiment) corresponding to a level 1 index with a non-zero count value is found.
[0119] Step 2: Calculate the value of a = K - slot[i][1] (count), and set the span between each data element to 100; 2.1 If a < 0;
[0120] 2.1.1 Mark the count value of the first K numbers with a count value of 1 between slot[i-99][0] and slot[i][0] as 0, and mark the status of the first K numbers between slot[i-99][0] and slot[i][0] as pre-occupied;
[0121] 2.1.2 Mark the Slot[i][y](count) for all index levels as Slot[i][y](count) - K;
[0122] 2.2 If a > 0;
[0123] 2.2.1 Mark the count value of all slots from slot[i-99][0] to slot[i][0] with a count value of 1 as 0, and mark the status of all slots from slot[i-99][0] to slot[i][0] as pre-occupied;
[0124] 2.2.2 Mark the Slot[i][y](count) for all index levels as Slot[i][y](count) - K;
[0125] 2.2.3 Let K = a, and repeat step two;
[0126] 2.3 If a = 0;
[0127] 2.3.1 Mark the count value of all slots from slot[i-99][0] to slot[i][0] with a count value of 1 as 0, and mark the status of all slots from slot[i-99][0] to slot[i][0] as pre-occupied;
[0128] 2.3.2 Mark the Slot[i][y](count) of all index levels as Slot[i][y](count) - K.
[0129] For example, if 50 numbers need to be allocated and the span between each data element is set to 100, assuming the first target data element corresponding to the first level 1 index with a non-zero count value is Slot
[100] [1], and the count of the first target data element Slot
[100] [1] is 100, then the first range of numbers to be allocated is determined to be from slot[i-99][0] to slot[i][0]. The count values of the first 50 numbers with a count value of 1 in slot[i-99][0] to slot[i][0] are marked as 0, and the usage status of the first 50 numbers in slot[i-99][0] to slot[i][0] is marked as pre-occupied. Additionally, the count value of Slot
[100] [y] in each index level is marked as 100-k.
[0130] For example, if 150 numbers need to be allocated, and the span between each data element is set to 100, assuming the first target data element corresponding to the first level 1 index with a non-zero count value is Slot
[100] [1], and the count of the first target data element Slot
[100] [1] is 100, then based on the first target data element Slot
[100] [1], the first range of numbers to be allocated is determined to be from slot[i-99][0] to slot[i][0]. Then, the count values of all numbers with a count value of 1 in slot[1][0] to slot[i][0] are marked as 0, and the usage status of all numbers in slot[i-99][0] to slot[i][0] is marked as pre-occupied. Additionally, the count value of Slot
[100] [y] in each index level is marked as 0. At this point, only 100 numbers have been allocated, leaving 50 numbers to be allocated. Based on the first target data element Slot
[100] [1], the second target data element Slot
[200] [1] is determined, and the count of the second target data element Slot
[200] [1] is 100. Based on the second target data element Slot
[200] [1], the second range of numbers to be allocated is determined to be from Slot
[101] [0] to Slot
[200] [0]. All numbers in Slot
[101] [0] to Slot
[200] [0] with a count value of 1 are marked as 0, and the usage status of all numbers in Slot
[101] [0] to Slot
[200] [0] is marked as pre-occupied. Additionally, the Slot
[200] [y](count) value in each index level is marked as 100-50. This completes the allocation process for these 150 numbers.
[0131] The number allocation method provided in this disclosure can achieve fast number allocation in scenarios that support number pre-occupancy, and also supports batch number allocation.
[0132] Based on the foregoing embodiments, this disclosure provides a numbering allocation device, which includes the included units, the modules included in each unit, and the components included in each module. It can be implemented by a processor in an electronic device; of course, it can also be implemented by specific logic circuits. In the implementation process, the processor can be a central processing unit (CPU), a microprocessor unit (MPU), a digital signal processor (DSP that implements the numbering allocation process), or a field-programmable gate array (FPGA), etc.
[0133] Figure 7 This is a schematic diagram of the composition structure of the numbering allocation device according to an embodiment of the present disclosure, as shown below. Figure 7 As shown, the numbering allocation device 700 includes a query module 701, a first determination module 702, and a marking module 703; wherein,
[0134] The query module 701 is used to find the first target data element located in the second lowest level index from the number storage skip list; wherein, the number storage skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different number intervals in the lowest level index level; the attribute information of the data element includes at least the statistical value of the valid number in the number interval corresponding to the data element; the statistical value of the first target data element is greater than zero;
[0135] The first determining module 702 is used to determine the first numbering interval to be assigned corresponding to the first target data element in the lowest level index.
[0136] The marking module 703 is used to mark the first k valid numbers in the first interval of numbers to be assigned as assigned numbers when the number of numbers to be assigned k is less than or equal to the statistical value m of the first target data element; where m and k are both positive integers.
[0137] In some embodiments, the numbering allocation device 700 further includes a second determining module. Figure 7 (not shown in the image);
[0138] The second determining module is used to determine the second target data element located in the next lower level index based on the first target data element;
[0139] The first determining module 702 is also used to determine the second numbering interval to be assigned in the lowest level index level corresponding to the second target data element;
[0140] The marking module 703 is also used to mark the first km of valid numbers in the second numbering interval as assigned numbers when the number of numbers to be assigned k is greater than the number of valid numbers used in the first numbering interval.
[0141] In some embodiments, the attribute information of the data element further includes: usage status; the usage status includes at least occupancy and availability.
[0142] In some embodiments, a valid number is a number with a statistical value of 1 and a usage status of available; the marking module 703 is further configured to mark the statistical value of the first k valid numbers in the first numbering interval to be assigned as 0, and to mark the usage status of the first k valid numbers in the first numbering interval to be assigned as occupied.
[0143] In some embodiments, the marking module 703 is further configured to mark the numerical value of the statistical value of the first target data element in each index level of the numbered skip list as mk.
[0144] In some embodiments, a valid number is a number with a statistical value of 1 and a usage status of available; the marking module 703 is further configured to mark the statistical values of all valid numbers in the first number interval to be assigned and the first km valid numbers in the second number interval to be assigned as 0, and to mark the usage status of all valid numbers in the first number interval to be assigned and the first km valid numbers in the second number interval to be assigned as occupied.
[0145] In some embodiments, the marking module 703 is further configured to mark the statistical value of the first target data element in each index level of the numbered storage skip list as 0, and to mark the statistical value of the second target data element in each index level of the numbered storage skip list as n-k+m, where n is the statistical value of the second target data element and n is a positive integer.
[0146] In some embodiments, the attribute information of the data element further includes: number, index level, down pointer, and right pointer;
[0147] Among them, the data element numbers in the lowest level index are valid; the usage status of data elements in other index levels is invalid.
[0148] In other index levels, the span values of the numbering intervals corresponding to any adjacent data elements are the same.
[0149] In some embodiments, the query module 701 is further configured to use a binary search algorithm to find the first valid data element with a statistical value greater than zero starting from the highest level index level; and to find the first target data element located in the next lower level index level based on the down pointer of the valid data element.
[0150] In some embodiments, the first determining module 702 is further configured to determine the interval in which the number of the first target data element is located in the lowest level index as the first numbering interval to be assigned.
[0151] In some embodiments, the second determining module is further configured to determine the data element pointed to by the right pointer of the first target data element as the second target data element.
[0152] The description of the above apparatus embodiments is similar to that of the above method embodiments, and has similar beneficial effects. For technical details not disclosed in the apparatus embodiments of this disclosure, please refer to the description of the method embodiments of this disclosure for understanding.
[0153] It should be noted that, in the embodiments of this disclosure, if the above-described control method is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this disclosure, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device (which may be a personal computer, server, etc.) to execute all or part of the methods of the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM (Read Only Memory), magnetic disks, or optical disks. Thus, the embodiments of this disclosure are not limited to any specific hardware and software combination.
[0154] Correspondingly, this disclosure provides an electronic device including a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the program, it implements the steps in the numbering allocation method provided in the above embodiments.
[0155] Correspondingly, embodiments of this disclosure provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the numbering allocation method described above.
[0156] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium and electronic device embodiments of this disclosure, please refer to the descriptions of the method embodiments of this disclosure for understanding.
[0157] Figure 8 A schematic diagram of a hardware entity of an electronic device provided in an embodiment of this disclosure, such as... Figure 8As shown, the hardware entity of the electronic device 800 includes: a processor 801, a communication interface 802, and a memory 803, wherein,
[0158] The processor 801 typically controls the overall operation of the electronic device 800.
[0159] The communication interface 802 enables the electronic device 800 to communicate with other electronic devices, servers, or platforms via a network.
[0160] The memory 803 is configured to store instructions and applications executable by the processor 801, and can also cache data to be processed or already processed (e.g., image data, audio data, voice communication data and video communication data) in the processor 801 and various modules in the electronic device 800. It can be implemented by flash memory or random access memory (RAM).
[0161] In the several embodiments provided in this disclosure, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components may be combined, or integrated into another system, or some features may be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0162] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0163] Furthermore, in the various embodiments of this disclosure, all functional units can be integrated into one processing module, or each unit can be a separate unit, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in a combination of hardware and software functional units. Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.
[0164] The methods disclosed in the several method embodiments provided in this disclosure can be arbitrarily combined without conflict to obtain new method embodiments.
[0165] The features disclosed in the several method or device embodiments provided in this disclosure can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0166] The above descriptions are merely some embodiments of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure. Therefore, the scope of protection of this disclosure should be determined by the scope of the claims.
Claims
1. A numbering allocation method, characterized in that, The method includes: The first target data element located in the next lowest level index is retrieved from the numbered skip list; wherein the numbered skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different numbering intervals in the lowest level index level; the attribute information of the data element includes at least the statistical value of the valid number in the numbering interval corresponding to the data element; the statistical value of the first target data element is greater than zero; Determine the first numbering interval to be assigned corresponding to the first target data element in the lowest level index; If the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element, the first k valid numbers in the first number interval to be assigned are marked as assigned numbers; where m and k are both positive integers.
2. The method according to claim 1, characterized in that, The attribute information of the data element also includes: usage status; the usage status includes at least occupied and available.
3. The method according to claim 2, characterized in that, The valid number is the number whose statistical value is 1 and whose usage status is "available". The first k valid numbers in the first number interval to be assigned are marked, including: The statistical value of the first k valid numbers in the first numbering interval to be allocated is marked as 0, and the usage status of the first k valid numbers in the first numbering interval to be allocated is marked as occupied.
4. The method according to claim 3, characterized in that, Marking the first k valid numbers in the first numbering interval to be assigned also includes: The numerical value of the statistical value of the first target data element in each index level of the numbered skip list is marked as mk.
5. The method according to any one of claims 2 to 4, characterized in that, If the number of numbers to be assigned, k, is greater than the statistical value m of the first target data element, the method further includes: Determine the second target data element located in the next lower level index based on the first target data element; Determine the second numbering interval to be assigned corresponding to the second target data element in the lowest level index; The first km of valid numbers in the second numbering interval to be assigned are marked as assigned numbers.
6. The method according to claim 5, characterized in that, The valid number is the number whose statistical value is 1 and whose usage status is "available". The first km valid numbers in the second unassigned number interval are marked, including: The statistical values of all valid numbers in the first number interval to be assigned and the first km valid numbers in the second number interval to be assigned are all marked as 0. Furthermore, the usage status of all valid numbers in the first number interval to be assigned and the first km valid numbers in the second number interval to be assigned is marked as occupied.
7. The method according to claim 6, characterized in that, Marking the first km of valid numbers in the second numbering interval to be assigned also includes: The statistical value of the first target data element in each index level of the numbered skip list is marked as 0, and the statistical value of the second target data element in each index level of the numbered skip list is marked as n-k+m, where n is the statistical value of the second target data element and n is a positive integer.
8. The method according to claim 2, characterized in that, The attribute information of the data element also includes: number, index level, down pointer, and right pointer; Wherein, the data element number in the lowest level index is valid; the usage status of the data elements corresponding to other index levels besides the lowest level index is invalid; In the other index levels, the span values of the numbering intervals corresponding to any adjacent data elements are the same.
9. The method according to claim 8, characterized in that, The step of retrieving the first target data element located in the next lower level index from the numbered skip list includes: The binary search algorithm is used to find the first valid data element with a statistical value greater than zero, starting from the highest level of the index. Based on the lower pointer of the valid data element, the first target data element located in the next lower level index is found.
10. The method according to claim 8, characterized in that, Determining the first target data element's corresponding first unassigned number range in the lowest-level index hierarchy includes: The interval containing the number of the first target data element in the lowest level index is determined as the first number interval to be assigned.
11. The method according to claim 8, characterized in that, Determining the second target data element based on the first target data element includes: The data element pointed to by the right pointer of the first target data element is determined as the second target data element.
12. A numbering allocation device, characterized in that, include: The query module is used to find the first target data element located in the second lowest level index from the number storage skip list; wherein, the number storage skip list includes multiple index levels, and each index level includes multiple data elements corresponding to different number intervals in the lowest level index level; the attribute information of the data element includes at least the statistical value of the valid number in the number interval corresponding to the data element; the statistical value of the first target data element is greater than zero; The first determining module is used to determine the first numbering interval to be assigned corresponding to the first target data element in the lowest level index level; The marking module is used to mark the first k valid numbers in the first interval of numbers to be assigned as assigned numbers when the number of numbers to be assigned, k, is less than or equal to the statistical value m of the first target data element; where m and k are both positive integers.
13. The apparatus according to claim 12, characterized in that, It also includes a second determining module; The second determining module is used to determine a second target data element located in the next lower level index based on the first target data element; The first determining module is further configured to determine the second numbering interval to be assigned corresponding to the second target data element in the lowest level index level; The marking module is further configured to mark the first km valid numbers in the second number interval as assigned numbers when the number of numbers to be assigned k is greater than the number of valid numbers used in the first number interval to be assigned m.
14. An electronic device, characterized in that, The method includes a memory and a processor, the memory storing a computer program executable on the processor, wherein the processor, when executing the program, implements the steps of the method according to any one of claims 1 to 11.
15. A computer-readable storage medium, characterized in that, It stores a computer program thereon, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of claims 1 to 11.
Citation Information
Patent Citations
Picture data storage method, system and device based on index table, and storage medium
CN111026890A
Fast multi-tier indexing supporting dynamic update
US20160283538A1