CN111694559B - Method and device for implementing hash table in GC program language - Google Patents
Method and device for implementing hash table in GC program language Download PDFInfo
- Publication number
- CN111694559B CN111694559B CN202010436194.5A CN202010436194A CN111694559B CN 111694559 B CN111694559 B CN 111694559B CN 202010436194 A CN202010436194 A CN 202010436194A CN 111694559 B CN111694559 B CN 111694559B
- Authority
- CN
- China
- Prior art keywords
- array
- hash table
- new
- matrix
- last
- 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.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2255—Hash tables
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/0223—User address space allocation, e.g. contiguous or non contiguous base addressing
- G06F12/023—Free address space management
- G06F12/0253—Garbage collection, i.e. reclamation of unreferenced memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5022—Mechanisms to release resources
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the invention provides a method and a device for realizing a hash table in a GC programming language, wherein the method comprises the following steps: if the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, creating a new object block array, and inserting the new object block array below the last row of the matrix; acquiring a row number of the new object block array in the matrix, pointing the index array of the hash table at the same lower index position as the row number to the new object block array, and initializing an element of the starting position of the new object block array as an object to be inserted; if the last object in the matrix of the hash table is not located at the last position of the object block array, initializing an element at a position subsequent to the position of the last object as the object to be inserted. The embodiment of the invention reduces the frequency of memory application and release, reduces the number of objects in the heap memory, and obviously improves the performance of the hash table.
Description
Technical Field
The invention belongs to the technical field of computer data structures, and particularly relates to a method and a device for realizing a hash table in a GC program language.
Background
In GC (Garbage Collection ) programming language, high frequency construction and destruction of objects can incur significant program execution overhead due to periodic garbage collection. For example, in Golang language, objects constructed and destroyed at high frequency occupy a lot of scattered memory space in heap space and cause the whole program to lock for a long time without executing heap memory access instructions when garbage collection occurs every 2 minutes.
Hash tables are important data structures in programming languages, such as Golang's map and Java's HashMap, for fast lookup of objects. In the GC programming language, the high frequency insertion and deletion of objects in the hash table may cause a large number of objects on the heap space to be frequently created and destroyed, and when the GC operation periodically performed locks the whole heap space, the GC operation may also be locked for a long time due to the large number of objects, which further causes a significant decrease in the query performance of the hash table at this time.
Since hash tables are a very classical data structure, their implementation varies widely and little among languages. In brief, a linked list header corresponding to a hash value is stored through an array H, which is called a hash bucket. The operations of insertion, deletion and inquiry are firstly to position the index in the H array by carrying out hash calculation on the Key of the object, and to scan the linked list pointed by the index position to judge whether the object exists or not and whether the object needs to be added or deleted or not.
Taking Golang as an example, the method uses a traditional hash table implementation method, and when an object is inserted into the hash table, an object is generated on a heap space; deleting an object marks from heap space that the object is no longer being used by the hash table. Since the GC in the heap space will periodically check all objects in the heap space, it will eventually be released if not used by any code.
In the high-frequency insertion and deletion operation, the application and release of the objects enable the GC to face a heap space formed by a large number of fragmented objects, and frequent operation on the hash table can significantly influence the overall performance of the hash table.
Disclosure of Invention
In order to solve the problem that the conventional hash table implementation method affects the performance of the hash table due to frequent operation of the hash table or at least partially solve the problem, an embodiment of the present invention provides a method and an apparatus for implementing the hash table in a GC program language.
According to a first aspect of an embodiment of the present invention, there is provided a method for implementing a hash table in a GC programming language, including:
if the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, creating a new object block array, and inserting the new object block array below the last row of the matrix;
acquiring a row number of the new object block array in the matrix, pointing the index array of the hash table at the new object block array at the same lower index position as the row number, and initializing an element of the initial position of the new object block array as an object to be inserted;
and initializing an element at a position subsequent to the position of the last object as the object to be inserted if the last object in the matrix of the hash table is not positioned at the last position of the object block array.
Specifically, if the last object in the matrix of the hash table is located at the last position of the object block array in the matrix, the step of creating a new object block array further includes:
calculating a hash value of the Key value of the object to be inserted, and positioning the position of the object to be inserted in a hash bucket of a hash table according to the hash value;
and traversing the position of the linked list of the hash table, and judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array if the position does not have the object to be inserted.
Specifically, the step of pointing the index array of the hash table to the new object block array at the same subscript position as the row number further includes:
if the length of the index array is smaller than or equal to the row number of the new object block array in the matrix, creating a new index array; wherein the length of the new index array is greater than the length of the original index array;
copying the content of the original index array into the new index array, and pointing the index position, which is the same as the line number, in the new index array to the new object block array.
Specifically, the method further comprises the following steps:
calculating a hash value of a Key value of an object to be deleted, and positioning the position of the object to be deleted in a hash bucket of a hash table according to the hash value of the Key value of the object to be deleted;
traversing and accessing the position of the object to be deleted in a linked list of the hash table, and exchanging the object to be deleted with the last object in the matrix if the object to be deleted exists in the position;
if the exchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array where the object to be deleted is located after exchanging.
Specifically, after the step of destroying the object block array where the object to be deleted is located after the exchange, the method further includes:
if the line number of the matrix after the length of the index array minus the object to be deleted is larger than a preset threshold value, a new index array is created; wherein the length of the new index array is smaller than that of the original index array;
copying the content of the original index array into the new index array, and pointing the index position, which is the same as the row number of the matrix after the object to be deleted is interchanged, in the new index array to be empty.
Specifically, the step of exchanging the object to be deleted with the last object in the matrix further includes:
and if the exchanged position of the object to be deleted is not the initial position of the object block array, deleting the exchanged object to be deleted.
Specifically, the method further comprises the following steps:
calculating a hash value of a Key value of an object to be searched, and positioning the position of the object to be searched in a hash bucket of a hash table according to the hash value of the Key value of the object to be searched;
and traversing and accessing the position of the object to be searched in the linked list of the hash table, and returning the object to be searched if the object to be searched exists in the position.
According to a second aspect of the embodiment of the present invention, there is provided an implementation apparatus of a hash table in a GC program language, including:
the creating module is used for creating a new object block array when the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, and inserting the new object block array below the last row of the matrix;
the inserting module is used for acquiring a line number of the new object block array in the matrix, pointing the index array of the hash table to the new object block array at the same lower index position as the line number, and initializing an element at the initial position of the new object block array as an object to be inserted;
and initializing an element at a position subsequent to the position of the last object as the object to be inserted if the last object in the matrix of the hash table is not positioned at the last position of the object block array.
According to a third aspect of the embodiments of the present invention, there is further provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor invoking a method of implementing a hash table in a GC program language provided by any of various possible implementations of the first aspect.
According to a fourth aspect of embodiments of the present invention, there is further provided a non-transitory computer-readable storage medium storing computer instructions that cause the computer to perform a method of implementing a hash table in a GC program language provided by any one of the various possible implementations of the first aspect.
The embodiment of the invention provides a method and a device for realizing a hash table in a GC (gas chromatography) programming language, wherein when an object is inserted into the hash table, if the last object in a matrix of the hash table is positioned at the last position of an object block array in the matrix, a new object block array is created, the object to be inserted is inserted into the initial position of the new object block array, and the memory application unit in the hash table is an array in the matrix instead of a single object by storing the object in the hash table in the mode of the object block, so that the frequency of memory application is reduced to 1/Height (B), the number of objects in a heap memory is reduced to 1/Height (B), and the performance of the hash table is obviously improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic overall flow chart of a method for implementing hash tables in a GC programming language according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a hash table in a method for implementing a hash table in a GC programming language according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an overall structure of a hash table implementation device in a GC programming language according to an embodiment of the present invention;
fig. 4 is a schematic diagram of an overall structure of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to more clearly illustrate the embodiments of the present invention or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
In one embodiment of the present invention, a method for implementing a hash table in a GC program language is provided, and fig. 1 is a schematic overall flow diagram of a method for implementing a hash table in a GC program language provided in an embodiment of the present invention, where the method includes: s101, if the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, creating a new object block array, and inserting the new object block array below the last row of the matrix;
the hash table in this embodiment includes three parts, i.e., a hash bucket H, a matrix B made up of a plurality of object block arrays of the same length, and a variable-length index array I, as shown in fig. 2. Wherein the object block array is an array formed by object blocks composed of a plurality of objects. When the hash table is initialized, the length LH of H, the initial length Len (I) of the variable-length index array and the length of each array in B are transmitted by a caller, namely the Height (B) of B. Initially the number of arrays Len (B) =1, and the length of the B [0] array is equal to Height (B). The objects stored in B are stored next to each other in the form of object blocks, each object block having a length of Height (B), which can typically take on values of integers between [16,256 ]. The 0 th position I [0] of the initial time-varying index array points to B [0].
When an object to be inserted < key, object > is inserted into the hash table, the last element B [ i ] [ j ] in B is obtained. If j=height (B) -1 in B [ i ] [ j ], then a new object block array B [ i+1] of length Height (B) is created.
S102, acquiring a row number of the new object block array in the matrix, pointing the index array of the hash table to the new object block array at the same lower index position as the row number, and initializing an element of the initial position of the new object block array as an object to be inserted;
i [ i+1] is directed to B [ i+1], and B [ i+1] [0] is initialized to an object to be inserted in the object < key, object >.
And S103, initializing an element at a position behind the position of the last object as the object to be inserted if the last object in the matrix of the hash table is not positioned at the last position of the object block array.
If j < Height (B) -1 in B [ i ] [ j ], B [ i ] [ j+1] is initialized directly to the object.
In this embodiment, when inserting an object into the hash table, if the last object in the matrix of the hash table is located at the last position of the object block array in the matrix, a new object block array is created, the object to be inserted is inserted into the starting position of the new object block array, and the object is stored in the hash table in the manner of the object block, so that the memory application unit in the hash table is an array in the matrix, rather than a single object, thereby reducing the frequency of memory application to 1/Height (B), reducing the number of objects in the heap memory to 1/Height (B), and significantly improving the performance of the hash table.
Based on the above embodiment, in this embodiment, if the last object in the matrix of the hash table is located at the last position of the object block array in the matrix, the step of creating a new object block array further includes: calculating a hash value of the Key value of the object to be inserted, and positioning the position of the object to be inserted in a hash bucket of a hash table according to the hash value; and traversing the position of the linked list of the hash table, and judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array if the position does not have the object to be inserted.
Specifically, in order to avoid repeated insertion of the object to be inserted, before the object to be inserted is inserted into the hash table, it is determined whether the object to be inserted is already present in the hash table, and if not, the object to be inserted is inserted.
And calculating a Hash value Hash (Key) of the Key value of the object to be inserted, and positioning the subscript H of the Hash value in the H array. And traversing and accessing a linked list corresponding to H [ H ], returning if the object to be inserted is found, otherwise, inserting the object to be inserted into the hash table.
Based on the above embodiment, the step of pointing the index array of the hash table to the new object block array at the same index position as the row number in the embodiment further includes: if the length of the index array is smaller than or equal to the row number of the new object block array in the matrix, creating a new index array; wherein the length of the new index array is greater than the length of the original index array; copying the content of the original index array into the new index array, and pointing the index position, which is the same as the line number, in the new index array to the new object block array.
Specifically, if the length of I is less than or equal to i+1, a new index array longer than I is generated, for example, the new I is twice the length of the original I, and the content in the original I is copied into the new I. I [ i+1] in the new I is pointed to B [ i+1], and B [ i+1] [0] is initialized to the object to be inserted.
On the basis of the above embodiments, the present embodiment further includes: calculating a hash value of a Key value of an object to be deleted, and positioning the position of the object to be deleted in a hash bucket of a hash table according to the hash value of the Key value of the object to be deleted; traversing and accessing the position of the object to be deleted in a linked list of the hash table, and exchanging the object to be deleted with the last object in the matrix if the object to be deleted exists in the position; if the exchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array where the object to be deleted is located after exchanging.
Specifically, an object to be deleted is deleted from the hash table<key,object>At this time, a Hash value Hash (key) of the key is calculated and its subscript H in the H array is located. Traversal access H [ H ]]If the corresponding linked list does not find the object to be deleted, returning to the blank; if the object to be deleted is found, and the position of the object to be deleted in B is B [ i ]][j]It is then summed with the last element B [ i ] in the B matrix 2 ][j 2 ]And (5) exchanging. If j 2 =0, destroy B [ i ] 2 ]The entire array. If j 2 >And 0, deleting only the interchanged objects to be deleted.
In this embodiment, the objects are stored in the hash table in the manner of object blocks, so that the memory release unit in the hash table is an array in the matrix, instead of a single object, so that the frequency of memory release is reduced to 1/Height (B), the number of objects in the heap memory is reduced to 1/Height (B), and the performance of the hash table is significantly improved.
On the basis of the foregoing embodiment, the step of destroying the object block array where the object to be deleted is located after the exchange in this embodiment further includes: if the line number of the matrix after the length of the index array minus the object to be deleted is larger than a preset threshold value, a new index array is created; wherein the length of the new index array is smaller than that of the original index array; copying the content of the original index array into the new index array, and pointing the index position, which is the same as the row number of the matrix after the object to be deleted is interchanged, in the new index array to be empty.
Specifically, if i 2 Much smaller than the length of the I array, e.g. I 2 Less than 1/4 of the I array length, a new array shorter than I is generated, such as 1/2 of the original I array length, the content in the original I is copied into the new I array, and I [ I ] 2 ]Pointing to null.
On the basis of the above embodiments, the present embodiment further includes: calculating a hash value of a Key value of an object to be searched, and positioning the position of the object to be searched in a hash bucket of a hash table according to the hash value of the Key value of the object to be searched; and traversing and accessing the position of the object to be searched in the linked list of the hash table, and returning the object to be searched if the object to be searched exists in the position.
Specifically, when an object to be queried < Key, object > is queried from the Hash table, a Hash value Hash (Key) of the Key value of the object to be queried is calculated, and the subscript H of the Key value in the H array is positioned. And traversing and accessing a linked list corresponding to H [ H ], and returning if the object to be queried is found.
In another embodiment of the present invention, an implementation apparatus for a hash table in a GC programming language is provided, which is used to implement the method in the foregoing embodiments. Therefore, the descriptions and definitions in the embodiments of the implementation method of the hash table in the GC program language described above can be used for understanding each execution module in the embodiments of the present invention. Fig. 3 is a schematic diagram of an overall structure of a device for implementing a hash table in a GC programming language according to an embodiment of the present invention, where the device includes a creation module 301 and an insertion module 302; wherein:
the creating module is used for creating a new object block array when the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, and inserting the new object block array below the last row of the matrix;
the inserting module is used for acquiring a line number of the new object block array in the matrix, pointing the index array of the hash table to the new object block array at the same lower index position as the line number, and initializing an element at the initial position of the new object block array as an object to be inserted;
and initializing an element at a position subsequent to the position of the last object as the object to be inserted if the last object in the matrix of the hash table is not positioned at the last position of the object block array.
In this embodiment, when inserting an object into the hash table, if the last object in the matrix of the hash table is located at the last position of the object block array in the matrix, a new object block array is created, the object to be inserted is inserted into the starting position of the new object block array, and the object is stored in the hash table in the manner of the object block, so that the memory application unit in the hash table is an array in the matrix, rather than a single object, thereby reducing the frequency of memory application to 1/Height (B), reducing the number of objects in the heap memory to 1/Height (B), and significantly improving the performance of the hash table.
On the basis of the above embodiment, the embodiment further includes a judging module, configured to calculate a hash value of the Key value of the object to be inserted, and locate, according to the hash value, a position of the object to be inserted in a hash bucket of a hash table; and traversing the position of the linked list of the hash table, and judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array if the position does not have the object to be inserted.
On the basis of the above embodiment, the insertion module in this embodiment is further configured to: if the length of the index array is smaller than or equal to the row number of the new object block array in the matrix, creating a new index array; wherein the length of the new index array is greater than the length of the original index array; copying the content of the original index array into the new index array, and pointing the index position, which is the same as the line number, in the new index array to the new object block array.
Based on the above embodiment, the embodiment further includes a deletion module, configured to calculate a hash value of a Key value of an object to be deleted, and position the object to be deleted in a hash bucket of a hash table according to the hash value of the Key value of the object to be deleted; traversing and accessing the position of the object to be deleted in a linked list of the hash table, and exchanging the object to be deleted with the last object in the matrix if the object to be deleted exists in the position; if the exchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array where the object to be deleted is located after exchanging.
On the basis of the above embodiment, the deletion module in this embodiment is further configured to: if the line number of the matrix after the length of the index array minus the object to be deleted is larger than a preset threshold value, a new index array is created; wherein the length of the new index array is smaller than that of the original index array; copying the content of the original index array into the new index array, and pointing the index position, which is the same as the row number of the matrix after the object to be deleted is interchanged, in the new index array to be empty.
On the basis of the above embodiment, the deletion module in this embodiment is further configured to: and if the exchanged position of the object to be deleted is not the initial position of the object block array, deleting the exchanged object to be deleted.
On the basis of the above embodiment, the embodiment further includes a searching module, configured to calculate a hash value of a Key value of an object to be searched, and position the position of the object to be searched in a hash bucket of a hash table according to the hash value of the Key value of the object to be searched; and traversing and accessing the position of the object to be searched in the linked list of the hash table, and returning the object to be searched if the object to be searched exists in the position.
Fig. 4 illustrates a physical schematic diagram of an electronic device, as shown in fig. 4, which may include: a processor (processor) 401, a communication interface (Communications Interface) 402, a memory (memory) 403 and a communication bus 404, wherein the processor 401, the communication interface 402 and the memory 403 complete communication with each other through the communication bus 404. The processor 401 may call logic instructions in the memory 403 to perform the following method: if the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, creating a new object block array, and inserting the new object block array below the last row of the matrix; acquiring a row number of the new object block array in the matrix, pointing the index array of the hash table at the same lower index position as the row number to the new object block array, and initializing an element of the starting position of the new object block array as an object to be inserted; if the last object in the matrix of the hash table is not located at the last position of the object block array, initializing an element at a position subsequent to the position of the last object as the object to be inserted.
Further, the logic instructions in the memory 403 may be implemented in the form of software functional units and stored in a computer readable storage medium when sold or used as a stand alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The present embodiment provides a non-transitory computer readable storage medium storing computer instructions that cause a computer to perform the methods provided by the above-described method embodiments, for example, including: if the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, creating a new object block array, and inserting the new object block array below the last row of the matrix; acquiring a row number of the new object block array in the matrix, pointing the index array of the hash table at the same lower index position as the row number to the new object block array, and initializing an element of the starting position of the new object block array as an object to be inserted; if the last object in the matrix of the hash table is not located at the last position of the object block array, initializing an element at a position subsequent to the position of the last object as the object to be inserted.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the above method embodiments may be implemented by hardware associated with program instructions, where the foregoing program may be stored in a computer readable storage medium, and when executed, the program performs steps including the above method embodiments; and the aforementioned storage medium includes: various media that can store program code, such as ROM, RAM, magnetic or optical disks.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims (9)
1. A method for implementing a hash table in a GC programming language, comprising:
if the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, creating a new object block array, and inserting the new object block array below the last row of the matrix;
acquiring a row number of the new object block array in the matrix, pointing the index array of the hash table at the new object block array at the same lower index position as the row number, and initializing an element of the initial position of the new object block array as an object to be inserted;
if the last object in the matrix of the hash table is not located at the last position of the object block array, initializing an element at a position subsequent to the position of the last object as the object to be inserted;
the step of pointing the index array of the hash table to the new object block array at the same index position as the row number further comprises:
if the length of the index array is smaller than or equal to the row number of the new object block array in the matrix, creating a new index array; wherein the length of the new index array is greater than the length of the original index array;
copying the content of the original index array into the new index array, and pointing the index position, which is the same as the line number, in the new index array to the new object block array.
2. The method of claim 1, wherein if a last object in a matrix of the hash table is located at a last position of an object block array in the matrix, the step of creating a new object block array further comprises:
calculating a hash value of the Key value of the object to be inserted, and positioning the position of the object to be inserted in a hash bucket of a hash table according to the hash value;
and traversing the position of the linked list of the hash table, and judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array if the position does not have the object to be inserted.
3. The method for implementing a hash table in a GC programming language according to claim 1 or 2, further comprising:
calculating a hash value of a Key value of an object to be deleted, and positioning the position of the object to be deleted in a hash bucket of a hash table according to the hash value of the Key value of the object to be deleted;
traversing and accessing the position of the object to be deleted in a linked list of the hash table, and exchanging the object to be deleted with the last object in the matrix if the object to be deleted exists in the position;
if the exchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array where the object to be deleted is located after exchanging.
4. The method for implementing a hash table in a GC programming language according to claim 3, wherein the step of destroying the object chunk array in which the object to be deleted is interchanged further comprises:
if the line number of the matrix after the length of the index array minus the object to be deleted is larger than a preset threshold value, a new index array is created; wherein the length of the new index array is smaller than that of the original index array;
copying the content of the original index array into the new index array, and pointing the index position, which is the same as the row number of the matrix after the object to be deleted is interchanged, in the new index array to be empty.
5. A method of implementing a hash table in a GC programming language according to claim 3, further comprising, after the step of interchanging the object to be deleted with the last object in the matrix:
and if the exchanged position of the object to be deleted is not the initial position of the object block array, deleting the exchanged object to be deleted.
6. The method for implementing a hash table in a GC programming language according to claim 1 or 2, further comprising:
calculating a hash value of a Key value of an object to be searched, and positioning the position of the object to be searched in a hash bucket of a hash table according to the hash value of the Key value of the object to be searched;
and traversing and accessing the position of the object to be searched in the linked list of the hash table, and returning the object to be searched if the object to be searched exists in the position.
7. An apparatus for implementing a hash table in a GC programming language, comprising:
the creating module is used for creating a new object block array when the last object in the matrix of the hash table is positioned at the last position of the object block array in the matrix, and inserting the new object block array below the last row of the matrix;
the inserting module is used for acquiring a line number of the new object block array in the matrix, pointing the index array of the hash table to the new object block array at the same lower index position as the line number, and initializing an element at the initial position of the new object block array as an object to be inserted;
if the last object in the matrix of the hash table is not located at the last position of the object block array, initializing an element at a position subsequent to the position of the last object as the object to be inserted;
the insertion module is further configured to:
if the length of the index array is smaller than or equal to the row number of the new object block array in the matrix, creating a new index array; wherein the length of the new index array is greater than the length of the original index array;
copying the content of the original index array into the new index array, and pointing the index position, which is the same as the line number, in the new index array to the new object block array.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor performs the steps of the method for implementing a hash table in a GC programming language according to any one of claims 1 to 6 when the program is executed by the processor.
9. A non-transitory computer readable storage medium having stored thereon a computer program, which when executed by a processor, implements the steps of the method of implementing a hash table in a GC program language according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010436194.5A CN111694559B (en) | 2020-05-21 | 2020-05-21 | Method and device for implementing hash table in GC program language |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010436194.5A CN111694559B (en) | 2020-05-21 | 2020-05-21 | Method and device for implementing hash table in GC program language |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111694559A CN111694559A (en) | 2020-09-22 |
CN111694559B true CN111694559B (en) | 2023-07-21 |
Family
ID=72478111
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010436194.5A Active CN111694559B (en) | 2020-05-21 | 2020-05-21 | Method and device for implementing hash table in GC program language |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111694559B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2008037201A1 (en) * | 2006-09-29 | 2008-04-03 | Huawei Technologies Co., Ltd. | Method and apparatus for solving hash collision |
CN101169790A (en) * | 2007-11-30 | 2008-04-30 | 中兴通讯股份有限公司 | Matrix type data caching method and device based on WEB application |
CN104809135A (en) * | 2014-01-27 | 2015-07-29 | 腾讯科技(深圳)有限公司 | Method and device for accessing data |
CN106326475A (en) * | 2016-08-31 | 2017-01-11 | 中国科学院信息工程研究所 | High-efficiency static hash table implement method and system |
CN107154899A (en) * | 2017-03-23 | 2017-09-12 | 广东顺德中山大学卡内基梅隆大学国际联合研究院 | A kind of system that IP routes are searched with suffix index |
CN109766341A (en) * | 2018-12-27 | 2019-05-17 | 厦门市美亚柏科信息股份有限公司 | A kind of method, apparatus that establishing Hash mapping, storage medium |
CN110928483A (en) * | 2018-09-19 | 2020-03-27 | 华为技术有限公司 | Data storage method, data acquisition method and equipment |
-
2020
- 2020-05-21 CN CN202010436194.5A patent/CN111694559B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2008037201A1 (en) * | 2006-09-29 | 2008-04-03 | Huawei Technologies Co., Ltd. | Method and apparatus for solving hash collision |
CN101169790A (en) * | 2007-11-30 | 2008-04-30 | 中兴通讯股份有限公司 | Matrix type data caching method and device based on WEB application |
CN104809135A (en) * | 2014-01-27 | 2015-07-29 | 腾讯科技(深圳)有限公司 | Method and device for accessing data |
CN106326475A (en) * | 2016-08-31 | 2017-01-11 | 中国科学院信息工程研究所 | High-efficiency static hash table implement method and system |
CN107154899A (en) * | 2017-03-23 | 2017-09-12 | 广东顺德中山大学卡内基梅隆大学国际联合研究院 | A kind of system that IP routes are searched with suffix index |
CN110928483A (en) * | 2018-09-19 | 2020-03-27 | 华为技术有限公司 | Data storage method, data acquisition method and equipment |
CN109766341A (en) * | 2018-12-27 | 2019-05-17 | 厦门市美亚柏科信息股份有限公司 | A kind of method, apparatus that establishing Hash mapping, storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111694559A (en) | 2020-09-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11023448B2 (en) | Data scrubbing method and apparatus, and computer readable storage medium | |
CN106462592B (en) | System and method for optimizing multi-version support for indexes | |
US11442961B2 (en) | Active transaction list synchronization method and apparatus | |
KR101084816B1 (en) | Systems and methods for versioning based triggers | |
KR100862661B1 (en) | Method for deferred logging and apparatus thereof | |
CN104035923B (en) | Inquire about the method and device of data | |
CN110147204B (en) | Metadata disk-dropping method, device and system and computer-readable storage medium | |
EP2336901B1 (en) | Online access to database snapshots | |
CN109086382B (en) | Data synchronization method, device, equipment and storage medium | |
CA2722320A1 (en) | Paging hierarchical data | |
CN110532201A (en) | A kind of metadata processing method and device | |
CN106326040B (en) | Snapshot metadata management method and device | |
JP2004524632A (en) | System and method for reorganizing stored data | |
US10430341B2 (en) | Log-structured storage method and server | |
KR20230026946A (en) | Key value storage device with hashing | |
CN113254470B (en) | Data modification method, device, computer equipment and storage medium | |
CN111694559B (en) | Method and device for implementing hash table in GC program language | |
CN111241090B (en) | Method and device for managing data index in storage system | |
CN111639076B (en) | Cross-platform efficient key value storage method | |
US7051051B1 (en) | Recovering from failed operations in a database system | |
CN110781101A (en) | One-to-many mapping relation storage method and device, electronic equipment and medium | |
CN115904813A (en) | File backup method, device, equipment and storage medium | |
US20220083522A1 (en) | Data processing method, apparatus, electronic device, and computer storage medium | |
CN111026748B (en) | Data compression method, device and system for network access frequency management and control | |
CN112506651B (en) | Method and equipment for data operation in large-data-volume environment |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |