CN112860371A - Method and device for implementing Queue container - Google Patents

Method and device for implementing Queue container Download PDF

Info

Publication number
CN112860371A
CN112860371A CN201911187397.9A CN201911187397A CN112860371A CN 112860371 A CN112860371 A CN 112860371A CN 201911187397 A CN201911187397 A CN 201911187397A CN 112860371 A CN112860371 A CN 112860371A
Authority
CN
China
Prior art keywords
array
queue container
basic data
data
data type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911187397.9A
Other languages
Chinese (zh)
Inventor
张�林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Zhenshi Information Technology Co Ltd
Original Assignee
Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Zhenshi Information Technology Co Ltd filed Critical Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority to CN201911187397.9A priority Critical patent/CN112860371A/en
Publication of CN112860371A publication Critical patent/CN112860371A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method and a device for realizing a Queue container, wherein the method comprises the following steps: creating an array of a preset basic data type, and taking the array as a bottom storage data structure of the Queue container; for any basic data type which uses the Queue container for data storage, determining the conversion length N of the any basic data type corresponding to the preset basic data type; n is a positive integer; and storing and reading data of any basic data type in the array maintained by the Queue container based on the conversion length N. The invention can reduce the waste of memory resources.

Description

Method and device for implementing Queue container
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for realizing a Queue container.
Background
In the data processing process, Queue is often used for data storage, and the Queue commonly used in Java is LinkedBlockingQueue provided by JDK.
In LinkedBlockingQueue provided by JDK, it is implemented by using a single linked list with a head pointer head and a tail pointer last, where the head pointer head directly points to the first Node object at the head of the queue, and the tail pointer last points to the last Node at the tail of the queue, and its structure is shown in fig. 1, and each Node object includes two parts of contents: a reference address (pointer) pointing to a data position, and a reference address (pointer) pointing to a next node, wherein a data object is stored in the reference address pointing to the data position, and information such as object description information and value data is included in the data object.
As can be seen from fig. 1, when LinkedBlockingQueue is used for data storage, each value data needs to use a node object and a data object, and valid data information targeted by service data processing is actually only value data in the value data object, and other data information is irrelevant to service data processing but occupies a large amount of memory space additionally. Taking int type value data as an example, when LinkedBlockingQueue is used for storage, the value data only occupies 4 bytes (byte), however, in the node object related to the storage, two reference addresses occupy 8 bytes altogether, and in addition, object description information in the data object related to the reference addresses also occupies a certain memory space, and it can be seen that the additionally occupied memory space is much more than the space occupied by the value data itself. It can be seen that there is a great deal of memory resource waste in the existing LinkedBlockingQueue implementation.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for implementing a Queue container, which can reduce waste of memory resources.
In order to achieve the purpose, the invention provides the following technical scheme:
a method for implementing a Queue container comprises the following steps:
creating an array of a preset basic data type, and taking the array as a bottom storage data structure of the Queue container;
for any basic data type which uses the Queue container for data storage, determining the conversion length N of the any basic data type corresponding to the preset basic data type; n is a positive integer;
and storing and reading data of any basic data type in the array maintained by the Queue container based on the conversion length N.
An apparatus for implementing a Queue container, comprising:
the creating unit is used for creating an array of preset basic data types and using the array as a bottom storage data structure of the Queue container;
the determining unit is used for determining the conversion length N of any basic data type corresponding to the preset basic data type for any basic data type which uses the Queue container for data storage; n is a positive integer;
and the processing unit is used for storing and reading the data of any basic data type in the array maintained by the Queue container based on the conversion length N.
An electronic device, comprising: the system comprises at least one processor and a memory connected with the at least one processor through a bus; the memory stores one or more computer programs executable by the at least one processor; the at least one processor, when executing the one or more computer programs, implements the steps in the method for implementing a Queue container described above.
A computer readable storage medium storing one or more computer programs which, when executed by a processor, implement the steps in the method for implementing a Queue container described above.
According to the technical scheme, the array of the preset basic data types is used as the bottom layer storage data structure of the Queue container, for the storage and reading of the data of any basic data type, the data of any basic data type are stored and read in the array based on the conversion length of any basic data type corresponding to the preset basic data type, the data of any basic data type are not stored in an object form, extra object description information does not need to be wasted, in addition, the data are not stored in a chain mode by adopting the nodes comprising the reference address pointing to the data position and the reference address pointing to the next node, and the occupation of the memory space can be saved. Therefore, the Queue container realized by the method can greatly reduce the waste of memory resources.
Drawings
FIG. 1 is a data structure diagram of a prior art LinkedBlockingQueue;
FIG. 2 is a flow chart of a method for implementing a Queue container according to an embodiment of the present invention;
FIG. 3 is a flow chart of a method for implementing a Queue container according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of an underlying storage data structure in a Queue container according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of data storage in a Queue container according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of data reading in a Queue container according to an embodiment of the present invention;
FIG. 7 is a schematic structural diagram of an apparatus for implementing a Queue container according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention are described in detail below with reference to the accompanying drawings according to embodiments.
In existing computer languages, such as JAVA, C + +, etc., there is a notion of basic data types. In the embodiment of the invention, aiming at improving the Queue containers provided by various computer languages with memory resource waste similar to the realization mechanism of LinkedBlockingqueue, the invention provides a new Queue container realization method which is realized by basic data types supported by the computer languages and is suitable for the computer languages.
Referring to fig. 2, fig. 2 is a flowchart of a method for implementing a Queue container according to an embodiment of the present invention, and as shown in fig. 2, the method includes the following steps:
step 201, creating an array of preset basic data types, and using the array as a bottom storage data structure of the Queue container.
In the embodiment of the invention, the basic data types are different according to different computer languages adopted for realizing the Queue container. For example, when the Queue container is implemented by JAVA language, the basic data types refer to all the basic data types supported by JAVA (including 8 basic data types, including byte, short, int, long, float, double, bootean, char), and the preset basic data type in step 201 may be any one of the 8 basic data types supported by JAVA.
Step 202, for any basic data type which uses the Queue container to store data, determining a conversion length N of the any basic data type corresponding to the preset basic data type; n is a positive integer.
In practical applications, different basic data types may have the same or different lengths, for example, in JAVA, the lengths of byte, short, int, long, float, double, borolan, char are: byte (1 byte), short (2 bytes), int (4 bytes), long (8 bytes), float (4 bytes), double (8 bytes), boot (usually 4 bytes), char (2 bytes).
In the embodiment of the present invention, since the preset basic data type and the any basic data type may be different basic data types, when the Queue container is used to store data of the any basic data type, it is necessary to first determine a conversion length N of the any basic data type corresponding to the preset basic data type, and then store and read data of the any basic data type in the array maintained by the Queue container based on the length N, where the length N is determined according to a length of the any basic data type and a length of the preset basic data type, and detailed description will be subsequently performed.
And 203, storing and reading the data of any basic data type in the array maintained by the Queue container based on the conversion length N.
In the embodiment of the present invention, based on the conversion length N, the data of any basic data type is stored and read in the array maintained by the Queue container, that is, when storing, the data to be stored of any basic data type needs to be converted into N data of the preset basic data types, and then the N data obtained by conversion is stored in the array serving as the bottom storage data structure of the Queue container; during reading, firstly, reading N data from an array of a bottom storage data structure serving as a Queue container, and then converting the read N data into data of any basic data type.
It can be seen from the above embodiments of the present invention that, in the present invention, by constructing an array of preset basic data types as a result of storing data at the bottom layer of a Queue container, and according to a conversion length N of any basic data type corresponding to the preset basic data type, reading and storing data in the array maintained by the Queue container are performed, without using an additional reference address pointing to a data position and a reference address pointing to a next node, and the data itself is not stored in an object form, but stored in a preset basic data type form, and therefore, no additional object description information needs to be stored, and therefore, a large amount of memory space can be saved. In addition, the Queue container stores data by using the array of the preset basic data type, and the whole array can be loaded into a cache for storing and reading the data, so that the cache of a CPU can be fully utilized, and the access speed of the data is increased.
Referring to fig. 3, fig. 3 is a flowchart of a method for implementing a two Queue container according to an embodiment of the present invention, and as shown in fig. 3, the method mainly includes the following steps:
step 301, creating an array of preset basic data types, and using the array as a bottom storage data structure of the Queue container.
In the embodiment of the present invention, JAVA is taken as an example, and the basic data types of JAVA: byte is used as a preset basic data type.
Step 302, for any basic data type which uses the Queue container to store data, determining a conversion length N of the any basic data type corresponding to the preset basic data type; n is a positive integer.
In this embodiment of the present invention, the method for determining the conversion length N of any basic data type corresponding to the preset basic data type specifically includes:
calculating the quotient of the length of any basic data type and the length of the preset basic data type;
and determining the upward rounding result of the quotient as the conversion length N of any basic data type corresponding to the preset basic data type.
Taking any basic data type as int as an example, the length of int is 4 bytes, and the length of byte is 1 byte, so that it can be determined that the conversion length N of any basic data type corresponding to the preset basic data type is rounded up by a quotient of 4 and 1, and finally N is 4.
Taking the preset basic data type as byte and any basic data type as int as an example, the data structure of Queue provided by the embodiment of the present invention is as shown in fig. 4: the Queue container maintains an array of byte data elements, and each 4 continuous data elements in the array can correspondingly store one int data. The Queue container also maintains a head pointer and a tail pointer, wherein the head pointer points to the initial position of data stored in an array maintained by the Queue container firstly; the tail pointer points to the end position of the data stored in the array maintained by the Queue container.
Step 303, when the data to be stored of any data type needs to be stored into the Queue, converting the data to be stored into N data of the preset basic data types, sequentially storing the converted N data from the position in the array pointed by the tail pointer maintained by the Queue container, and updating the position in the array pointed by the tail pointer of the Queue container.
The main functions implemented in this step 303 are: and storing the data of any basic data type in the array maintained by the Queue container based on the conversion length N of any basic data type corresponding to the preset basic data type.
The following is illustrated in connection with fig. 4: suppose that two int-type data are already stored in the Queue container and data are not read from the Queue container, that is, as shown in fig. 4, a head pointer points to a start position of an array Queue [ ] maintained by the Queue container (i.e., a position where Queue [0] is located), Queue [0] to Queue [3] store first int data, Queue [4] to Queue [7] store second int data, and a tail pointer points to an end position of Queue [7] (i.e., a position where Queue [8] is located).
When the data to be stored of any data type needs to be stored into the Queue, the data to be stored may be converted into data of N preset basic data types, and the specific conversion process is as follows (int data is converted into byte data):
x [0] ═ byte (data to be stored &0 xff);
x [1] ═ (byte) (data to be stored > >8&0 xff);
x [2] ═ (byte) (data to be stored > >16&0 xff);
x [3] ═ (byte) (data to be stored > >24&0 xff);
wherein,
the above formula x [0] ═ (byte) (data to be stored &0xff) represents: converting the data of 0 th to 7 th bits of the data to be stored into x [0], namely the data [0-7] bit → x [0] to be stored;
the above formula x [1] ═ (byte) (data to be stored > >8&0xff) represents: converting the data of 8 th to 15 th bits of the data to be stored into x [1] (namely, the data to be stored [8-5] bit → x [1 ]);
the above formula x [2] ═ (byte) (to-be-stored data > >16&0xff) represents: converting the data of 16 th to 23 th bits of the data to be stored into x [2] (namely, the data to be stored [16-23] bit → x [2 ]);
the above formula x [3] ═ (byte) (to-be-stored data > >24&0xff) represents: converting the data of 24 th to 31 th bits of the data to be stored into x [3] (namely, the data to be stored [24-31] bit → x [3 ]);
through the above four formulas, the data to be stored can be converted into 4 byte type data, i.e. x [0], x [1], x [2], x [3 ].
Then, 4 data after conversion can be sequentially stored from the position in the array pointed by the tail pointer maintained by the Queue container, specifically, as shown in fig. 5, x [0], x [1], x [2], and x [3] are sequentially stored in four positions of Queue [8], Queue [9], Queue [10], and Queue [11], and the tail pointer maintained by the Queue container is immediately updated to point to the end position of Queue [11] (i.e., the position of Queue [12 ]).
And ending the process of storing the data to be stored of the int type into the Queue container.
Step 304, when the data of any data type needs to be read from the Queue, sequentially reading N array elements from the position in the array pointed by the head pointer maintained by the Queue container, converting the sequentially read N data into the data of any basic data type, and updating the position in the array pointed by the head pointer maintained by the Queue container.
The main functions implemented in this step 304 are: and reading the data of any basic data type in the array maintained by the Queue container based on the conversion length N of any basic data type corresponding to the preset basic data type.
The following is illustrated in connection with fig. 4: suppose that two int types of data are already stored in the Queue container and data are not read from the Queue container, that is, as shown in fig. 4, the head pointer points to the start position of the Queue container array Queue [ ] (i.e. the position where Queue [0] is located), Queue [0] to Queue [3] store the first int data, Queue [4] to Queue [7] store the second int data, and the tail pointer points to the end position of Queue [7] (i.e. the position where Queue [8] is located).
When data of any data type needs to be read from the Queue, N number of elements (N ═ 4) may be read sequentially from the position in the array Queue [ ] pointed by the head pointer maintained by the Queue container, that is, Queue [0], Queue [1], Queue [2], Queue [3] is read, and the head pointer maintained by the Queue container is updated to point to the position of Queue [4], as shown in fig. 6.
Then, the following formula is used: converting the read array elements of 4 byte types into int data, wherein the int data is the data to be read, (byte [0] &0xff) & lt 24) | (byte [1] &0xff) & lt 16) | (byte [2] &0xff) & lt 8) | (byte [3] &0xff) & lt 0).
And ending the process of reading data to be read of an int type from the Queue container.
The process of storing and reading data in the Queue container is described above by taking the preset basic data type as byte and any basic data type as int as an example. In practical applications, when the preset basic data type is byte, storage and reading of other basic data types can be realized, mutual conversion between N byte types and other basic data types is mainly involved in the storage and reading processes, and the conversion principle is the same as that in the storage and reading processes of int type data, and is not repeated.
In addition, the preset basic data type may also be other basic data types except byte, such as short, int, and the like, and it should be noted that when a basic data type other than byte is adopted as the preset basic data type, if a Queue container is used to store data of other data types having a length smaller than the preset basic data type, there may be a situation that a small amount of memory is wasted, for example, when the preset basic data type is short, if the Queue container is used to store data of the byte type, since byte originally only needs to occupy 1 byte, but actually occupies 2 bytes (i.e., occupies the length of an array element of one short type) when stored in the Queue container. However, even if there is a waste of memory space for this case, the memory space is still saved compared to the data structure of LinkedBlockingQueue in the prior art.
In the embodiment of the present invention shown in fig. 3, because an array is used as a bottom storage data structure of the Queue container, the length of the array may only be set to a smaller array initially to avoid waste of memory space, but as the data stored in the Queue container increases, the initial array length may not be sufficient to support subsequent data storage requirements, in this case, the Queue container may be expanded, specifically, an array with a larger length is created again, the data in the original array is copied to the newly created array with a larger length, and then the newly created array with a larger length is used to replace the original array.
Therefore, in the embodiment of the present invention shown in fig. 3, the Queue container may be further expanded through the following steps:
s1, when the number of array elements stored in the array maintained by the Queue container exceeds the preset proportion of the array length of the array, and the array length of the array is smaller than the preset maximum array length, expanding the array length of the array;
s2, creating a new array of the preset basic data type based on the extended array length;
s3, sequentially storing the data in the array maintained by the Queue container into a new array according to the sequence of storage, pointing a head pointer maintained by the Queue container to the initial position of the data stored in the new array at first, and pointing a tail pointer maintained by the Queue container to the end position of the data stored in the new array at last;
s4, replacing the array maintained by the Queue container with a new array to serve as the underlying storage data structure of the Queue container, and deleting the array maintained by the Queue container.
In the step S1, the length of the array may be extended in a variety of ways, for example, the length of the array is increased by a fixed length value; or the array length of the array is multiplied by a preset expansion factor to obtain the expanded array length.
In addition, in order to reuse the storage space in the array maintained by the Queue container, a sequential circular Queue mechanism may be adopted for the Queue container, that is: when the tail pointer maintained by the Queue container points to the end of the array, if the head pointer maintained by the Queue container points to a position other than the starting position of the array (as data is continuously read from the array maintained by the Queue container, the head pointer maintained by the Queue container is continuously updated and gradually points to a position far away from the starting position of the array, so that the starting position of the array is vacant), new data is stored, new data can be stored from the starting position of the array again until the tail pointer and the head pointer point to the same position, the storage space of the array is used up, and at this time, if the Queue container has reached the maximum capacity and is not allowed to be expanded, new data cannot be stored subsequently. It should be noted here that, the head pointer and the tail pointer of the Queue container point to the same position, and besides the case that the storage space of the above array is used up, there is another case that: no data has yet been stored in the array.
In addition, in the embodiment of the present invention shown in fig. 3, the number of data of any basic data type stored in the Queue container may also be determined according to the conversion length N of any basic data type in the Queue container corresponding to the preset basic data type, and the head pointer and the tail pointer maintained by the Queue container, and specifically, the following formula may be adopted: (tail pointer-head pointer)/N.
Practice proves that the memory usage of the Queue container realized by the method provided by the embodiment of the invention is about 40% of the LinkedBlockingqueue provided by JDK. Moreover, since the Queue container stores all data in the form of basic data types (not objects) in the array, the cpu cache can be fully utilized, and the data can be read faster than LinkedBlockingQueue provided by JDK. In addition, the Queue container realized by the method provided by the embodiment of the invention can also be suitable for various use scenes (namely, use scenes corresponding to different basic data types).
The method for implementing the Queue container provided by the invention is described in detail above, and the invention also provides an implementation device of the Queue container, which is described in detail below with reference to fig. 7:
referring to fig. 7, fig. 7 is a schematic structural diagram of an apparatus for implementing a Queue container according to an embodiment of the present invention, and as shown in fig. 7, the apparatus includes:
a creating unit 701, configured to create an array of preset basic data types, and use the array as a bottom storage data structure of the Queue container;
a determining unit 702, configured to determine, for any basic data type that uses the Queue container for data storage, a conversion length N of the any basic data type corresponding to the preset basic data type; n is a positive integer;
a processing unit 703, configured to store and read data of any basic data type in the array maintained by the Queue container based on the conversion length N.
In the arrangement shown in figure 7 of the drawings,
the determining unit 702, configured to, when determining that any of the basic data types corresponds to the conversion length N of the preset basic data type,:
calculating the quotient of the length of any basic data type and the length of the preset basic data type;
and determining the upward rounding result of the quotient as the conversion length N of any basic data type corresponding to the preset basic data type.
In the arrangement shown in figure 7 of the drawings,
the Queue container maintains a tailed pointer; the tail pointer points to the end position of the data stored in the array maintained by the Queue container finally;
the processing unit 703, based on the conversion length N, stores the data of any basic data type in the array maintained by the Queue container, including:
and converting data to be stored into N data of the preset basic data types, sequentially storing the N converted data from the position in the array pointed by the tail pointer maintained by the Queue container, and updating the position in the array pointed by the tail pointer of the Queue container.
In the arrangement shown in figure 7 of the drawings,
the Queue container maintains a headed pointer; the head pointer points to the initial position of data stored in an array maintained by the Queue container firstly;
the processing unit 703, based on the conversion length N, reads data of any basic data type in the array maintained by the Queue container, and includes:
and sequentially reading N array elements from the position in the array pointed by the head pointer maintained by the Queue container, converting the sequentially read N data into the data of any basic data type, and updating the position pointed by the head pointer maintained by the Queue container in the array.
The apparatus shown in fig. 7 further includes: a reset unit 704 for:
when the number of array elements stored in the array maintained by the Queue container exceeds a preset proportion of the array length of the array, and the array length of the array is smaller than a preset maximum array length, expanding the array length of the array;
creating a new array of the preset basic data type based on the extended array length;
sequentially storing the data in the array maintained by the Queue container into a new array according to the sequence of storage, pointing a head pointer maintained by the Queue container to the initial position of the data stored in the new array at first, and pointing a tail pointer maintained by the Queue container to the end position of the data stored in the new array at last;
replacing the array maintained by the Queue container with a new array as an underlying storage data structure of the Queue container, and deleting the array maintained by the Queue container.
In the arrangement shown in figure 7 of the drawings,
the preset basic data type is a byte type.
An embodiment of the present invention further provides an electronic device, and as shown in fig. 8, the electronic device 800 includes: at least one processor 801, and a memory 802 connected to the at least one processor 801 via a bus; the memory 802 stores one or more computer programs executable by the at least one processor 801; the at least one processor 801, when executing the one or more computer programs, implements the method steps as shown in fig. 2.
Embodiments of the present invention also provide a computer-readable storage medium storing one or more computer programs which, when executed by a processor, implement the method steps shown in fig. 2.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (14)

1. A method for implementing a Queue container is characterized by comprising the following steps:
creating an array of a preset basic data type, and taking the array as a bottom storage data structure of the Queue container;
for any basic data type which uses the Queue container for data storage, determining the conversion length N of the any basic data type corresponding to the preset basic data type; n is a positive integer;
and storing and reading data of any basic data type in the array maintained by the Queue container based on the conversion length N.
2. The method of claim 1,
the method for determining the conversion length N of any basic data type corresponding to the preset basic data type comprises the following steps:
calculating the quotient of the length of any basic data type and the length of the preset basic data type;
and determining the upward rounding result of the quotient as the conversion length N of any basic data type corresponding to the preset basic data type.
3. The method of claim 1,
the Queue container maintains a tailed pointer; the tail pointer points to the end position of the data stored in the array maintained by the Queue container finally;
based on the conversion length N, storing the data of any basic data type in the array maintained by the Queue container, including:
and converting data to be stored into N data of the preset basic data types, sequentially storing the N converted data from the position in the array pointed by the tail pointer maintained by the Queue container, and updating the position in the array pointed by the tail pointer of the Queue container.
4. The method of claim 1,
the Queue container maintains a headed pointer; the head pointer points to the initial position of data stored in an array maintained by the Queue container firstly;
based on the conversion length N, reading data of any basic data type in the array maintained by the Queue container, wherein the reading comprises the following steps:
and sequentially reading N array elements from the position in the array pointed by the head pointer maintained by the Queue container, converting the sequentially read N data into the data of any basic data type, and updating the position pointed by the head pointer maintained by the Queue container in the array.
5. The method of claim 1, further comprising:
when the number of array elements stored in the array maintained by the Queue container exceeds a preset proportion of the array length of the array, and the array length of the array is smaller than a preset maximum array length, expanding the array length of the array;
creating a new array of the preset basic data type based on the extended array length;
sequentially storing the data in the array maintained by the Queue container into a new array according to the sequence of storage, pointing a head pointer maintained by the Queue container to the initial position of the data stored in the new array at first, and pointing a tail pointer maintained by the Queue container to the end position of the data stored in the new array at last;
replacing the array maintained by the Queue container with a new array as an underlying storage data structure of the Queue container, and deleting the array maintained by the Queue container.
6. The method of claim 1,
the preset basic data type is a byte type.
7. An apparatus for implementing a Queue container, the apparatus comprising:
the creating unit is used for creating an array of preset basic data types and using the array as a bottom storage data structure of the Queue container;
the determining unit is used for determining the conversion length N of any basic data type corresponding to the preset basic data type for any basic data type which uses the Queue container for data storage; n is a positive integer;
and the processing unit is used for storing and reading the data of any basic data type in the array maintained by the Queue container based on the conversion length N.
8. The apparatus of claim 7,
the determining unit, when determining that the any basic data type corresponds to the conversion length N of the preset basic data type, is configured to:
calculating the quotient of the length of any basic data type and the length of the preset basic data type;
and determining the upward rounding result of the quotient as the conversion length N of any basic data type corresponding to the preset basic data type.
9. The apparatus of claim 7,
the Queue container maintains a tailed pointer; the tail pointer points to the end position of the data stored in the array maintained by the Queue container finally;
the processing unit, based on the conversion length N, stores the data of any basic data type in the array maintained by the Queue container, including:
and converting data to be stored into N data of the preset basic data types, sequentially storing the N converted data from the position in the array pointed by the tail pointer maintained by the Queue container, and updating the position in the array pointed by the tail pointer of the Queue container.
10. The apparatus of claim 7,
the Queue container maintains a headed pointer; the head pointer points to the initial position of data stored in an array maintained by the Queue container firstly;
the processing unit, based on the conversion length N, reads data of any basic data type in the array maintained by the Queue container, and includes:
and sequentially reading N array elements from the position in the array pointed by the head pointer maintained by the Queue container, converting the sequentially read N data into the data of any basic data type, and updating the position pointed by the head pointer maintained by the Queue container in the array.
11. The apparatus of claim 7, further comprising: a reset unit to:
when the number of array elements stored in the array maintained by the Queue container exceeds a preset proportion of the array length of the array, and the array length of the array is smaller than a preset maximum array length, expanding the array length of the array;
creating a new array of the preset basic data type based on the extended array length;
sequentially storing the data in the array maintained by the Queue container into a new array according to the sequence of storage, pointing a head pointer maintained by the Queue container to the initial position of the data stored in the new array at first, and pointing a tail pointer maintained by the Queue container to the end position of the data stored in the new array at last;
replacing the array maintained by the Queue container with a new array as an underlying storage data structure of the Queue container, and deleting the array maintained by the Queue container.
12. The apparatus of claim 7,
the preset basic data type is a byte type.
13. An electronic device, comprising: the system comprises at least one processor and a memory connected with the at least one processor through a bus; the memory stores one or more computer programs executable by the at least one processor; characterized in that the at least one processor, when executing the one or more computer programs, implements the method steps of any of claims 1-6.
14. A computer-readable storage medium, characterized in that the computer-readable storage medium stores one or more computer programs which, when executed by a processor, implement the method of any one of claims 1-6.
CN201911187397.9A 2019-11-28 2019-11-28 Method and device for implementing Queue container Pending CN112860371A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911187397.9A CN112860371A (en) 2019-11-28 2019-11-28 Method and device for implementing Queue container

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911187397.9A CN112860371A (en) 2019-11-28 2019-11-28 Method and device for implementing Queue container

Publications (1)

Publication Number Publication Date
CN112860371A true CN112860371A (en) 2021-05-28

Family

ID=75985305

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911187397.9A Pending CN112860371A (en) 2019-11-28 2019-11-28 Method and device for implementing Queue container

Country Status (1)

Country Link
CN (1) CN112860371A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541926A (en) * 2010-12-30 2012-07-04 北京新媒传信科技有限公司 Data exchange processing method, equipment and system
CN104978321A (en) * 2014-04-02 2015-10-14 阿里巴巴集团控股有限公司 Method and device for constructing data queue, method for inserting object into data queue and method for consuming object from data queue
CN108205577A (en) * 2016-12-20 2018-06-26 阿里巴巴集团控股有限公司 A kind of array structure, the method, apparatus and electronic equipment of array inquiry
CN109298888A (en) * 2018-10-31 2019-02-01 杭州迪普科技股份有限公司 The data access method and device of queue
CN109634955A (en) * 2018-11-15 2019-04-16 金蝶软件(中国)有限公司 Date storage method, data retrieval method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541926A (en) * 2010-12-30 2012-07-04 北京新媒传信科技有限公司 Data exchange processing method, equipment and system
CN104978321A (en) * 2014-04-02 2015-10-14 阿里巴巴集团控股有限公司 Method and device for constructing data queue, method for inserting object into data queue and method for consuming object from data queue
CN108205577A (en) * 2016-12-20 2018-06-26 阿里巴巴集团控股有限公司 A kind of array structure, the method, apparatus and electronic equipment of array inquiry
CN109298888A (en) * 2018-10-31 2019-02-01 杭州迪普科技股份有限公司 The data access method and device of queue
CN109634955A (en) * 2018-11-15 2019-04-16 金蝶软件(中国)有限公司 Date storage method, data retrieval method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
刘遵仁等: "《数据结构》", 31 August 2018, pages: 64 - 67 *

Similar Documents

Publication Publication Date Title
CN110147204B (en) Metadata disk-dropping method, device and system and computer-readable storage medium
EP3260993A1 (en) File operation method and device
US11314689B2 (en) Method, apparatus, and computer program product for indexing a file
CN110647514B (en) Metadata updating method and device and metadata server
CN112860592B (en) Data caching method and device based on linked list, electronic equipment and storage medium
CN111124464A (en) Method and system for differential upgrade of embedded system and computer readable storage medium
US9292549B2 (en) Method and system for index serialization
US20120011166A1 (en) Skip list generation
CN110888843A (en) Cross-host sparse file copying method, device, equipment and storage medium
US11074187B2 (en) Method, apparatus and computer program product for managing address in storage system
CN113504918A (en) Equipment tree configuration optimization method and device, computer equipment and storage medium
US8959309B2 (en) Skip list generation
CN110618883B (en) Method, device, equipment and storage medium for sharing memory linked list
CN115964002A (en) Electric energy meter terminal file management method, device, equipment and medium
CN107451070B (en) Data processing method and server
CN115952326B (en) Linked list type data structure, data processing method thereof, storage medium and electronic equipment
US10095630B2 (en) Sequential access to page metadata stored in a multi-level page table
CN106934066B (en) Metadata processing method and device and storage equipment
US7353323B2 (en) Method, system, and computer-readable medium for updating memory devices in a computer system
CN112860371A (en) Method and device for implementing Queue container
US20040172420A1 (en) System and method of object-oriented persistence
CN117331498A (en) Method, device, equipment and medium for constructing mapping table of solid state disk
CN111198718A (en) FPGA-based processor starting method and processor
CN113986134B (en) Method for storing data, method and device for reading data
CN112035380B (en) Data processing method, device and equipment and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination