CN111694559A - Method and device for realizing hash table in GC program language - Google Patents

Method and device for realizing hash table in GC program language Download PDF

Info

Publication number
CN111694559A
CN111694559A CN202010436194.5A CN202010436194A CN111694559A CN 111694559 A CN111694559 A CN 111694559A CN 202010436194 A CN202010436194 A CN 202010436194A CN 111694559 A CN111694559 A CN 111694559A
Authority
CN
China
Prior art keywords
hash table
array
matrix
last
new
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.)
Granted
Application number
CN202010436194.5A
Other languages
Chinese (zh)
Other versions
CN111694559B (en
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 YUNSHAN NETWORKS Inc
Original Assignee
BEIJING YUNSHAN NETWORKS Inc
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 YUNSHAN NETWORKS Inc filed Critical BEIJING YUNSHAN NETWORKS Inc
Priority to CN202010436194.5A priority Critical patent/CN111694559B/en
Publication of CN111694559A publication Critical patent/CN111694559A/en
Application granted granted Critical
Publication of CN111694559B publication Critical patent/CN111694559B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation 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/5022Mechanisms to release resources
    • YGENERAL 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
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE 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/00Energy 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 program language, wherein the method comprises the following steps: 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, 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 a new object block array in a matrix, pointing a subscript position in an index array of a hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array to be an object to be inserted; and if the last object in the matrix of the hash table is not positioned at the last position of the object block array, initializing an element at a position next 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

Method and device for realizing hash table in GC program language
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 the GC (Garbage Collection) program language, high frequency construction and destruction of objects incurs huge program execution overhead due to periodic Garbage Collection. For example, in the Golang language, objects constructed and destroyed by high frequency occupy a large amount of scattered memory space on heap space and cause the entire program to lock down for a long time to execute heap memory access instructions every 2 minutes when garbage collection occurs.
The hash table is an important data structure in programming languages, such as map of Golang and HashMap of Java, and is used for realizing quick search of objects. In the GC program language, 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 a periodically executed GC operation may also lock the whole heap space for a long time due to the large number of objects, thereby significantly reducing the query performance of the hash table at this time.
Since the hash table is a very classical data structure, its implementation is very different in various languages. Briefly, a linked list header corresponding to a hash value is stored by an array H, which is called a hash bucket. The operations of inserting, deleting and inquiring are carried out hash calculation on the Key of the object to locate the subscript in the H array, and the linked list pointed by the position of the subscript is scanned 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, it uses a traditional hash table implementation method, and when inserting an object into the hash table, an object is generated on the heap space; deleting an object marks the heap space that the object is no longer used by the hash table. Since the GC in heap space will periodically check all objects in heap space, it will eventually be freed if not used by any code.
During high-frequency insertion and deletion operations, application and release of objects enable a GC to face a heap space formed by a large number of fragmented objects, and frequent operations on a hash table can obviously affect the overall performance of the hash table.
Disclosure of Invention
In order to overcome the problem that the performance of the hash table is affected by frequent operations of the existing hash table implementation method or at least partially solve the problem, embodiments of the present invention provide an implementation method and an implementation device for a hash table in a GC program language.
According to a first aspect of the embodiments of the present invention, there is provided a method for implementing a hash table in a GC program language, including:
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, 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 a subscript position in an index array of the hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array to be an object to be inserted;
and 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.
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 the 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 and accessing the position of the linked list of the hash table, and if the position does not have the object to be inserted, judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array.
Specifically, the step of pointing the index position in the index array of the hash table, which is the same as the row number, to the new object block array further includes:
if the length of the index array is less than or equal to the row number of the new object block array in the matrix, creating a new index array; the length of the new index array is greater than that of the original index array;
and copying the content of the original index array into the new index array, and pointing the subscript position in the new index array, which is the same as the row number, to the new object block array.
Specifically, the method further comprises the following steps:
calculating the hash value of the Key value of the 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 the linked list of the hash table, and if the object to be deleted exists in the position, exchanging the object to be deleted with the last object in the matrix;
and if the interchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array in which the object to be deleted is interchanged.
Specifically, the step of destroying the object block array in which the objects to be deleted are interchanged further includes:
if the length of the index array minus the row number of the matrix after the interchange of the objects to be deleted is greater than a preset threshold value, creating a new index array; 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 subscript position in the new index array, which is the same as the row number of the matrix after being interchanged with the object to be deleted, to be null.
Specifically, the step of interchanging the object to be deleted and the last object in the matrix further includes:
and if the interchanged position of the object to be deleted is not the initial position of the object block array, deleting the interchanged object to be deleted.
Specifically, the method further comprises the following steps:
calculating the hash value of the Key value of the 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 if the object to be searched exists in the position, returning the object to be searched.
According to a second aspect of the embodiments of the present invention, there is provided an apparatus for implementing a hash table in a GC program language, including:
the hash table comprises a creating module, a generating module and a storing module, wherein the creating module is used for creating a new object block array when a last object in a matrix of the hash table is positioned at the last position of an 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 row number of the new object block array in the matrix, pointing a subscript position in an index array of the hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array as an object to be inserted;
and 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.
According to a third aspect of the embodiments of the present invention, there is also provided an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor calls the program instruction to perform the implementation method of the hash table in the GC program language provided in any one of the various possible implementations of the first aspect.
According to a fourth aspect of the embodiments of the present invention, there is further provided a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the method for implementing a hash table in a GC program language provided in 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 program 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 object is stored in the hash table in an object block mode, so that a memory application unit in the hash table is an array in the matrix instead of a single object, the frequency of memory application is reduced to 1/height (B), the number of objects in the memory is reduced to 1/height (B), and the performance of the hash table is remarkably improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic overall flow chart of an implementation method of a hash table in a GC program language according to an embodiment of the present invention;
fig. 2 is a schematic diagram illustrating an architecture of a hash table in a method for implementing the hash table in the GC program language according to the embodiment of the present invention;
fig. 3 is a schematic diagram of an overall structure of an apparatus for implementing a hash table in a GC program language according to an embodiment of the present invention;
fig. 4 is a schematic view 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 in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
In an 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 chart of the method for implementing the hash table in the GC program language provided in the embodiment of the present invention, where the method includes: s101, if the last object in a matrix of a hash table is located at the last position of an 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 formed by a plurality of object block arrays having the same length, and a variable length index array I, as shown in fig. 2. The object block array is an array formed by object blocks formed by 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, namely the height (B) of B, are transmitted by the caller. Initially, the number of arrays in B, len (B) is 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 object blocks, and the length of each object block is height (B), and the height (B) can be an integer between [16,256 ]. The 0 th position of the array of initially time-varying length indices, I [0], 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 is height (B) -1 in B [ i ] [ j ], 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 a subscript position in an index array of the hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array as an object to be inserted;
i [ I +1] points to B [ I +1], and B [ I +1] [0] is initialized to an object to be inserted into the object < key, object >.
S103, 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.
If j < height (B) -1 in B [ i ] [ j ], then B [ i ] [ j +1] is directly initialized to the object.
In this embodiment, when an object is inserted 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 start position of the new object block array, and the object is stored in the hash table in an object block manner, so that the memory application unit in the hash table is an array in the matrix instead of a single object, thereby reducing the frequency of memory application to 1/height (b), reducing the number of objects in the memory to 1/height (b), and significantly improving the performance of the hash table.
On the basis of the foregoing 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 the 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 and accessing the position of the linked list of the hash table, and if the position does not have the object to be inserted, judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array.
Specifically, 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 already exists in the hash table, and if not, the object to be inserted is inserted.
And calculating the hash value Hash (Key) of the Key value of the object to be inserted, and positioning the subscript H of the Hash value Hash (Key) in the H array. And traversing and accessing the linked list corresponding to the H [ H ], returning if the object to be inserted is found, and otherwise, inserting the object to be inserted into the hash table.
On the basis of the foregoing embodiment, in this embodiment, the step of pointing the index position in the index array of the hash table, which is the same as the row number, to the new object block array further includes: if the length of the index array is less than or equal to the row number of the new object block array in the matrix, creating a new index array; the length of the new index array is greater than that of the original index array; and copying the content of the original index array into the new index array, and pointing the subscript position in the new index array, which is the same as the row number, 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 length of new I is twice the length of original I, and the content in original I is copied to new I. I [ I +1] in the new I points to B [ I +1], and B [ I +1] [0] is initialized to the object to be inserted into the object.
On the basis of the above embodiments, the present embodiment further includes: calculating the hash value of the Key value of the 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 the linked list of the hash table, and if the object to be deleted exists in the position, exchanging the object to be deleted with the last object in the matrix; and if the interchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array in which the object to be deleted is interchanged.
Specifically, one object to be deleted is deleted from the hash table<key,object>Then, the 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 null; 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 matrix2][j2]And (4) interchanging. If j2If equal to 0, destroy B [ i2]The entire array. If j2>And 0, only deleting the interchanged objects to be deleted.
In the 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, thereby reducing the memory release frequency 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 foregoing embodiment, in this embodiment, after the step of destroying the object block array in which the objects to be deleted are interchanged, the method further includes: if the length of the index array minus the row number of the matrix after the interchange of the objects to be deleted is greater than a preset threshold value, creating a new index array; 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 subscript position in the new index array, which is the same as the row number of the matrix after being interchanged with the object to be deleted, to be null.
Specifically, if i2Much shorter than the length of the I array, e.g. I21/4 less than the length of the I array, a new array shorter than I is generated, such as 1/2 the length of the original I array, the contents of the original I are copied to the new I array, and I [ I [ [ I ] is2]Pointing to null.
On the basis of the above embodiments, the present embodiment further includes: calculating the hash value of the Key value of the 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 if the object to be searched exists in the position, returning the object to be searched.
Specifically, when an object to be queried < Key, object > is queried from the hash table, the hash value hash (Key) of the Key value of the object to be queried is calculated, and the subscript H of the hash value hash (Key) in the H array is located. And traversing and accessing the linked list corresponding to the H [ H ], and returning if the object to be queried is found.
In another embodiment of the present invention, an apparatus for implementing a hash table in a GC program language is provided, which is used to implement the methods in the foregoing embodiments. Therefore, the description and definition in each embodiment of the implementation method of the hash table in the GC program language can be used for understanding each execution module in the embodiment of the present invention. Fig. 3 is a schematic diagram of an overall structure of an apparatus for implementing a hash table in a GC program language according to an embodiment of the present invention, where the apparatus includes a creating module 301 and an inserting module 302; wherein:
the hash table comprises a creating module, a generating module and a storing module, wherein the creating module is used for creating a new object block array when a last object in a matrix of the hash table is positioned at the last position of an 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 row number of the new object block array in the matrix, pointing a subscript position in an index array of the hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array as an object to be inserted;
and 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.
In this embodiment, when an object is inserted 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 start position of the new object block array, and the object is stored in the hash table in an object block manner, so that the memory application unit in the hash table is an array in the matrix instead of a single object, thereby reducing the frequency of memory application to 1/height (b), reducing the number of objects in the memory to 1/height (b), and significantly improving the performance of the hash table.
On the basis of the foregoing embodiment, this embodiment further includes a determining module, configured to calculate a hash value of a Key value of the object to be inserted, and locate a position of the object to be inserted in a hash bucket of a hash table according to the hash value; and traversing and accessing the position of the linked list of the hash table, and if the position does not have the object to be inserted, judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array.
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 less than or equal to the row number of the new object block array in the matrix, creating a new index array; the length of the new index array is greater than that of the original index array; and copying the content of the original index array into the new index array, and pointing the subscript position in the new index array, which is the same as the row number, to the new object block array.
On the basis of the foregoing embodiment, this embodiment further includes a deletion module, configured to calculate a hash value of a Key value of an object to be deleted, and locate, according to the hash value of the Key value of the object to be deleted, a position of the object to be deleted in a hash bucket of a hash table; traversing and accessing the position of the object to be deleted in the linked list of the hash table, and if the object to be deleted exists in the position, exchanging the object to be deleted with the last object in the matrix; and if the interchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array in which the object to be deleted is interchanged.
On the basis of the foregoing embodiment, the deleting module in this embodiment is further configured to: if the length of the index array minus the row number of the matrix after the interchange of the objects to be deleted is greater than a preset threshold value, creating a new index array; 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 subscript position in the new index array, which is the same as the row number of the matrix after being interchanged with the object to be deleted, to be null.
On the basis of the foregoing embodiment, the deleting module in this embodiment is further configured to: and if the interchanged position of the object to be deleted is not the initial position of the object block array, deleting the interchanged object to be deleted.
On the basis of the above embodiment, the present embodiment further includes a lookup module, configured to calculate a hash value of a Key value of an object to be looked up, and locate a position of the object to be looked up in a hash bucket of a hash table according to the hash value of the Key value of the object to be looked up; and traversing and accessing the position of the object to be searched in the linked list of the hash table, and if the object to be searched exists in the position, returning the object to be searched.
Fig. 4 illustrates a physical structure diagram of an electronic device, which may include, as shown in fig. 4: a processor (processor)401, a communication Interface (communication 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. Processor 401 may call logic instructions in memory 403 to perform the following method: 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, 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 a new object block array in a matrix, pointing a subscript position in an index array of a hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array to be an object to be inserted; and if the last object in the matrix of the hash table is not positioned at the last position of the object block array, initializing an element at a position next to the position of the last object as the object to be inserted.
In addition, 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 the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute 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), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The present embodiments provide a non-transitory computer-readable storage medium storing computer instructions that cause a computer to perform the methods provided by the above method embodiments, for example, including: 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, 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 a new object block array in a matrix, pointing a subscript position in an index array of a hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array to be an object to be inserted; and if the last object in the matrix of the hash table is not positioned at the last position of the object block array, initializing an element at a position next to the position of the last object as the object to be inserted.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present 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 solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for implementing a hash table in a GC program language is characterized by comprising the following steps:
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, 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 a subscript position in an index array of the hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array to be an object to be inserted;
and 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.
2. The method as claimed in claim 1, wherein 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 comprises:
calculating the 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 and accessing the position of the linked list of the hash table, and if the position does not have the object to be inserted, judging whether the last object in the matrix of the hash table is positioned at the last position of the object block array.
3. The method of claim 1, wherein the step of pointing the index position of the hash table in the index array 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 less than or equal to the row number of the new object block array in the matrix, creating a new index array; the length of the new index array is greater than that of the original index array;
and copying the content of the original index array into the new index array, and pointing the subscript position in the new index array, which is the same as the row number, to the new object block array.
4. The method for implementing a hash table in a GC program language according to any one of claims 1 to 3, further comprising:
calculating the hash value of the Key value of the 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 the linked list of the hash table, and if the object to be deleted exists in the position, exchanging the object to be deleted with the last object in the matrix;
and if the interchanged position of the object to be deleted is the initial position of the object block array, destroying the object block array in which the object to be deleted is interchanged.
5. The method for implementing a hash table in a GC program language according to claim 4, wherein the step of destroying the object block array where the objects to be deleted are interchanged further comprises:
if the length of the index array minus the row number of the matrix after the interchange of the objects to be deleted is greater than a preset threshold value, creating a new index array; 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 subscript position in the new index array, which is the same as the row number of the matrix after being interchanged with the object to be deleted, to be null.
6. The method of claim 4, wherein the step of interchanging the object to be deleted with the last object in the matrix further comprises:
and if the interchanged position of the object to be deleted is not the initial position of the object block array, deleting the interchanged object to be deleted.
7. The method for implementing a hash table in a GC program language according to any one of claims 1 to 3, further comprising:
calculating the hash value of the Key value of the 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 if the object to be searched exists in the position, returning the object to be searched.
8. An apparatus for implementing a hash table in a GC program language, comprising:
the hash table comprises a creating module, a generating module and a storing module, wherein the creating module is used for creating a new object block array when a last object in a matrix of the hash table is positioned at the last position of an 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 row number of the new object block array in the matrix, pointing a subscript position in an index array of the hash table, which is the same as the row number, to the new object block array, and initializing an element of an initial position of the new object block array as an object to be inserted;
and 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.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method for implementing a hash table in the GC program language according to any one of claims 1 to 7 when executing the program.
10. A non-transitory computer readable storage medium, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the steps of the method for implementing a hash table in a GC program language according to any one of claims 1 to 7.
CN202010436194.5A 2020-05-21 2020-05-21 Method and device for implementing hash table in GC program language Active CN111694559B (en)

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 true CN111694559A (en) 2020-09-22
CN111694559B 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)

* Cited by examiner, † Cited by third party
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

Patent Citations (7)

* Cited by examiner, † Cited by third party
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
CN111694559B (en) 2023-07-21

Similar Documents

Publication Publication Date Title
KR102564170B1 (en) Method and device for storing data object, and computer readable storage medium having a computer program using the same
CN110109915B (en) Method, apparatus and computer program product for managing hash tables
CN110147204B (en) Metadata disk-dropping method, device and system and computer-readable storage medium
US11288210B2 (en) Method, device and computer program product for managing storage system
EP2237185B1 (en) Method for optimization of anti-virus scan
CN110888837B (en) Object storage small file merging method and device
US20200151268A1 (en) Bounding cost of flushes in buffer trees
CA2722320A1 (en) Paging hierarchical data
CN110532201A (en) A kind of metadata processing method and device
CN109213450B (en) Associated metadata deleting method, device and equipment based on flash memory array
CN111274245B (en) Method and device for optimizing data storage
KR20230026946A (en) Key value storage device with hashing
CN115269631A (en) Data query method, data query system, device and storage medium
US20160299834A1 (en) State storage and restoration device, state storage and restoration method, and storage medium
CN111158601A (en) IO data flushing method, system and related device in cache
KR101640733B1 (en) System for Managing data based In-Memory DataBase and method thereof
CN111694559B (en) Method and device for implementing hash table in GC program language
CN109324929B (en) Snapshot creating method, device and equipment and readable storage medium
US20220083522A1 (en) Data processing method, apparatus, electronic device, and computer storage medium
CN115904813A (en) File backup method, device, equipment and storage medium
CN112506651B (en) Method and equipment for data operation in large-data-volume environment
CN113132241B (en) ACL template dynamic configuration method and device
CN111026748B (en) Data compression method, device and system for network access frequency management and control
CN113626382A (en) Index method, system and related device for aggregation object in distributed file system
CN107506156B (en) Io optimization method of block device

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